Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created October 4, 2018 12:35
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 amandeepmittal/ba0bd6dd80d4950f8a7e3c272687bd68 to your computer and use it in GitHub Desktop.
Save amandeepmittal/ba0bd6dd80d4950f8a7e3c272687bd68 to your computer and use it in GitHub Desktop.
// books.js
router.post('/new', (ctx, next) => {
// Check if any of the data field not empty
if (
!ctx.request.body.id ||
!ctx.request.body.name ||
!ctx.request.body.author
) {
ctx.response.status = 400;
ctx.body = 'Please enter the data';
} else {
let newBook = books.push({
id: ctx.request.body.id,
name: ctx.request.body.name,
author: ctx.request.body.author
});
ctx.response.status = 201;
ctx.body = `New book added with id: ${ctx.request.body.id} & name: ${
ctx.request.body.name
}`;
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment