diff --git a/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.spec.ts b/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.spec.ts index d3b3f3b..858f6a2 100644 --- a/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.spec.ts +++ b/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.spec.ts @@ -72,4 +72,32 @@ describe('buildRows', () => { const rows = buildRows(team() as any, '2026-08-01', '2026-08-31'); expect(rows).toEqual([]); }); + + it('skips transactions with null type and includes valid ones', () => { + const rows = buildRows( + team({ + transactions: [ + { date: '2026-08-05T00:00:00.000Z', amount: 100, note: 'Valid credit', type: { name: 'credit' } }, + { date: '2026-08-06T00:00:00.000Z', amount: 50, note: 'Null type team wallet', type: null }, + ], + players: [ + { + firstName: 'Bob', + lastName: 'Smith', + transactions: [ + { date: '2026-08-07T00:00:00.000Z', amount: 20, note: 'Valid payment', type: { name: 'payment' } }, + { date: '2026-08-08T00:00:00.000Z', amount: 30, note: 'Null type player', type: null }, + ], + }, + ], + }) as any, + '2026-08-01', + '2026-08-31', + ); + + expect(rows).toEqual([ + { date: '2026-08-05T00:00:00.000Z', type: 'credit', who: 'Teamkasse', note: 'Valid credit', amount: 100, runningTotal: 100 }, + { date: '2026-08-07T00:00:00.000Z', type: 'payment', who: 'Bob Smith', note: 'Valid payment', amount: 20, runningTotal: 120 }, + ]); + }); }); diff --git a/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.ts b/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.ts index 0ca5776..2ada4bb 100644 --- a/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.ts +++ b/myteamwallet_backend/src/cashbox-export/cashbox-export.utils.ts @@ -24,6 +24,7 @@ export function buildRows(team: Team, from: string, to: string): CashboxExportRo const raw: RawRow[] = []; for (const transaction of team.transactions ?? []) { + if (!transaction.type) continue; raw.push({ date: transaction.date, type: transaction.type.name, @@ -35,7 +36,7 @@ export function buildRows(team: Team, from: string, to: string): CashboxExportRo for (const player of team.players ?? []) { for (const transaction of player.transactions ?? []) { - if (transaction.type.name !== 'payment') continue; + if (!transaction.type || transaction.type.name !== 'payment') continue; raw.push({ date: transaction.date, type: transaction.type.name,