Afifchage de l'historique des mouvements de point

This commit is contained in:
2024-12-14 00:27:30 +01:00
parent 02304527d3
commit 3d50cee9a9
10 changed files with 102 additions and 19 deletions

View File

@ -4,11 +4,12 @@ import { PaginationMeta } from '../common'
export interface MoneyUpdate {
id: number
playerId: number
amount: number
reason: 'START' | 'NEW_RUN' | 'BUY_TRAIN' | 'WIN_CHALLENGE'
timestamp: number
runId: number | null
actionId: number | null
tripId: number | null
tripId: string | null
}
export interface MoneyUpdatesState {
@ -19,8 +20,19 @@ const initialState: MoneyUpdatesState = {
moneyUpdates: []
}
export interface MoneyUpdatePayload {
id: number
playerId: number
amount: number
reason: 'START' | 'NEW_RUN' | 'BUY_TRAIN' | 'WIN_CHALLENGE'
timestamp: string
runId: number | null
actionId: number | null
tripId: string | null
}
export interface MoneyUpdatesPayload {
data: MoneyUpdate[]
data: MoneyUpdatePayload[]
meta: PaginationMeta
}
@ -31,7 +43,16 @@ export const moneyUpdatesSlice = createSlice({
downloadMoneyUpdates(state, action: PayloadAction<MoneyUpdatesPayload>) {
state.moneyUpdates = state.moneyUpdates.filter(moneyUpdate => action.payload.data.filter(dlMU => dlMU.id === moneyUpdate.id) === null)
for (const dlMU of action.payload.data) {
state.moneyUpdates.push(dlMU)
state.moneyUpdates.push({
id: dlMU.id,
playerId: dlMU.playerId,
amount: dlMU.amount,
reason: dlMU.reason,
timestamp: new Date(dlMU.timestamp).getTime(),
runId: dlMU.runId,
actionId: dlMU.actionId,
tripId: dlMU.tripId,
})
}
state.moneyUpdates.sort((mu1, mu2) => mu2.id - mu1.id)
},