-
-
Save amandeepmittal/ba0bd6dd80d4950f8a7e3c272687bd68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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