Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.put('/user', function(req, res) {
- // db object is already added to req object when express is initialised
- const db = req.db;
- const { userId, userName, userEmail } = req.body
- try {
- await updateUserService({
- db,
- updateParams: {
- userId,
- userName,
- userEmai
- }
- })
- } catch (ex) {
- switch (ex.name) {
- case 'InvalidParamsException':
- res.status(400).send('Missing required params')
- return
- case 'UserNotFoundException':
- res.status(404).send('User not found')
- return
- case 'DatabaseErrorException':
- res.status(500).send('Db error')
- return
- default:
- res.status(500).send('Unknown error')
- return
- }
- }
- res.status(200).send('User updated')
- })
Add Comment
Please, Sign In to add comment