Skip to content

Commit

Permalink
refactor: return validated required string
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu committed Sep 14, 2023
1 parent b880a79 commit acbd496
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/back/routes/badges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async function createBadgeSpec(req: WithAuth): Promise<BadgeCreationResult> {
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) }
Expand Down
1 change: 1 addition & 0 deletions src/back/utils/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acbd496

Please sign in to comment.