From acbd496ce898a8e78e99ce42f3072dc04629cb29 Mon Sep 17 00:00:00 2001 From: 1emu Date: Thu, 14 Sep 2023 13:19:27 -0300 Subject: [PATCH] refactor: return validated required string --- src/back/routes/badges.ts | 4 +--- src/back/utils/validations.ts | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/back/routes/badges.ts b/src/back/routes/badges.ts index c0d0b4504..50ee2398c 100644 --- a/src/back/routes/badges.ts +++ b/src/back/routes/badges.ts @@ -103,9 +103,7 @@ async function createBadgeSpec(req: WithAuth): Promise { const user = req.auth validateDebugAddress(user) - const { badgeCid } = req.body - validateRequiredString('badgeCid', badgeCid) - + const badgeCid = validateRequiredString('badgeCid', req.body.badgeCid) try { const result = await createSpec(badgeCid) return { status: ActionStatus.Success, badgeCid: JSON.stringify(result) } diff --git a/src/back/utils/validations.ts b/src/back/utils/validations.ts index e415c6c64..4a86807e6 100644 --- a/src/back/utils/validations.ts +++ b/src/back/utils/validations.ts @@ -83,6 +83,7 @@ export function validateRequiredString(fieldName: string, value?: string) { if (!value || value.length === 0) { throw new RequestError(`Invalid ${fieldName}`, RequestError.BadRequest) } + return value } // eslint-disable-next-line @typescript-eslint/no-explicit-any