From 5ab2df351c0ca61e251e1aae0faa8f7536a5a92c Mon Sep 17 00:00:00 2001 From: Spacelord Date: Sun, 2 Mar 2025 18:52:35 +0100 Subject: [PATCH] Fix codecheck -> Handle all nullish things possible --- src/routes/api/v1/user.ts | 6 ++++-- src/routes/api/v1/user_codecheck.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/routes/api/v1/user.ts b/src/routes/api/v1/user.ts index 7f32161..107e41b 100644 --- a/src/routes/api/v1/user.ts +++ b/src/routes/api/v1/user.ts @@ -39,7 +39,7 @@ async function get(req: Request, res: Response) { if (result.length !== 0) { result.forEach((element: { id: number; name: string; code: string | null | boolean }) => { // code-> true if code is set - element.code = element.code !== ''; + element.code = !(element.code === '' || element.code === null || element.code === undefined); // Check if nullish }); res.status(200).json({ count, result }); } else { @@ -69,7 +69,9 @@ async function get(req: Request, res: Response) { if (result.length !== 0) { result.forEach((element: { id: number; name: string; code: string | null | boolean }) => { // code-> true if code is set - element.code = element.code !== ''; + //log.api?.debug('"' + element.code + '"'); + //log.api?.debug(!(element.code === ''), !(element.code === null), !(element.code === undefined)); + element.code = !(element.code === '' || element.code === null || element.code === undefined); // Check if nullish }); res.status(200).json({ count, result }); } else { diff --git a/src/routes/api/v1/user_codecheck.ts b/src/routes/api/v1/user_codecheck.ts index 60c7833..3adeddc 100644 --- a/src/routes/api/v1/user_codecheck.ts +++ b/src/routes/api/v1/user_codecheck.ts @@ -27,7 +27,7 @@ async function get(req: Request, res: Response) { // result?.code === null -> user exists and has no code // result?.code === undefined -> user does not exists // value.code === result?.code -> If user exists and has no code this matches - res.status(200).json(result?.code === '' || result?.code === null || result?.code === undefined || value.code === result?.code); + res.status(200).json(result?.code === '' || result?.code === null || result?.code === undefined || result?.code === value.code); //log.api?.debug(result, result?.code); }); }