fix(api): handle string numbers in normalizeDate (#64188)

This commit is contained in:
Shaun Hamilton
2025-11-27 15:16:25 +02:00
committed by GitHub
parent 7c12767a68
commit 4b6c2d7805
2 changed files with 13 additions and 2 deletions

View File

@@ -193,6 +193,10 @@ describe('normalize', () => {
'Unexpected date value: {"date":"123"}'
);
});
test('should handle string numbers', () => {
expect(normalizeDate('1696118400000')).toEqual(1696118400000);
});
});
describe('normalizeChallengeType', () => {

View File

@@ -76,9 +76,16 @@ export const normalizeDate = (date?: Prisma.JsonValue): number => {
typeof date.$date === 'string'
) {
return new Date(date.$date).getTime();
} else {
throw Error('Unexpected date value: ' + JSON.stringify(date));
} else if (typeof date === 'string') {
const parsed = Number(date);
if (!isNaN(parsed)) {
// Number() handles invalid strings e.g. '2023-10-01T00:00:00Z'
// parseInt() handles floats
return parseInt(String(parsed));
}
}
throw Error('Unexpected date value: ' + JSON.stringify(date));
};
/**