backend: Fix type errors in genId

I checked on NodeJS locally and `Math.min` was coercing the Dates to numbers,
I'm just making it more obvious (to the typechecker as well)
This commit is contained in:
Michcio 2022-09-25 15:46:11 +02:00
parent a91bbed34e
commit 30faeb73d2
1 changed files with 2 additions and 2 deletions

View File

@ -7,8 +7,8 @@ import * as crypto from 'node:crypto';
const TIME2000 = 946684800000;
let counter = crypto.randomBytes(2).readUInt16LE(0);
export function genId(date?: Date = new Date()): string {
let t = Math.min(date, new Date());
export function genId(date: Date = new Date()): string {
let t = Math.min(date.valueOf(), new Date().valueOf());
t -= TIME2000;
if (t < 0) t = 0;
if (isNaN(t)) throw new Error('Failed to create AID: Invalid Date');