From 7693d793c08d7b3a8f0a4236c8e14a8593ea2fd1 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Thu, 20 Feb 2025 23:11:43 +0100 Subject: [PATCH] Allow api to remove code from user with "0000" / Fix regex (only 0-9) --- src/routes/api/v1/user.ts | 2 +- src/routes/api/v1/user_schema.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/api/v1/user.ts b/src/routes/api/v1/user.ts index f8b8e14..14c2a0f 100644 --- a/src/routes/api/v1/user.ts +++ b/src/routes/api/v1/user.ts @@ -125,7 +125,7 @@ async function patch(req: Request, res: Response) { }, data: { name: value.name, - code: value.code + code: (value.code === '0000') ? null : value.code }, select: { id: true diff --git a/src/routes/api/v1/user_schema.ts b/src/routes/api/v1/user_schema.ts index 37e4427..868a6b2 100644 --- a/src/routes/api/v1/user_schema.ts +++ b/src/routes/api/v1/user_schema.ts @@ -22,7 +22,7 @@ const schema_get = validator // MARK: CREATE user const schema_post = validator.object({ name: validator.string().min(1).max(32).required(), - code: validator.string().min(4).max(4).trim().regex(new RegExp('/^[0-9]+$/')) + code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/)) }); // MARK: UPDATE user @@ -30,7 +30,7 @@ const schema_patch = validator .object({ id: validator.number().positive().precision(0).required(), name: validator.string().min(1).max(32), - code: validator.string().min(4).max(4).trim().regex(new RegExp('/^[0-9]+$/')) + code: validator.string().min(4).max(4).trim().regex(new RegExp(/^[0-9]+$/)) }) .or('name', 'code');