Skip to content

Commit

Permalink
Use value nested inside request body
Browse files Browse the repository at this point in the history
Value validation may need the config too, so this nesting was added.
  • Loading branch information
RedwanPlague committed Oct 15, 2023
1 parent f71a922 commit 25707d1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pages/api/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ const handler = async (
return;
}

const color = req.body.color;
const color = req.body?.value?.color;

if (typeof color !== "string") {
return res.status(422).json({ message: "No 'color' hex string found" });
}

if (!color.match(/^#[0-9a-f]{6}([0-9a-f]{2})?$/i)) {
return res.status(422).json({ message: `'${color}' is not a valid hex color string` });
return res
.status(422)
.json({ message: `'${color}' is not a valid hex color string` });
}

res.status(200).json({ message: "OK" });
Expand Down

0 comments on commit 25707d1

Please sign in to comment.