Skip to content

Instantly share code, notes, and snippets.

@kasramp

kasramp/index.js Secret

Last active October 5, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasramp/f83b9c927f544de7c57d1867325a1f17 to your computer and use it in GitHub Desktop.
Save kasramp/f83b9c927f544de7c57d1867325a1f17 to your computer and use it in GitHub Desktop.
router.post("/v1/users", async (context) => {
if (!context.request.hasBody) {
context.response.status = 400;
context.response.body = { error: "Request body cannot be empty" };
} else {
const { firstName, lastName, age } = (await context.request.body(true)).value
const ageInt = parseInt(age);
if (firstName && lastName && ageInt) {
let addedUser = (await storage.addUser(firstName, lastName, ageInt))[0];
context.response.status = 201;
context.response.body = addedUser;
} else {
context.response.status = 400;
context.response.body = { error: "Invalid payload's provided" };
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment