Guest User

Untitled

a guest
Dec 14th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. router.put('/user', function(req, res) {
  2. // db object is already added to req object when express is initialised
  3. const db = req.db;
  4. const { userId, userName, userEmail } = req.body
  5. try {
  6. await updateUserService({
  7. db,
  8. updateParams: {
  9. userId,
  10. userName,
  11. userEmai
  12. }
  13. })
  14. } catch (ex) {
  15. switch (ex.name) {
  16. case 'InvalidParamsException':
  17. res.status(400).send('Missing required params')
  18. return
  19. case 'UserNotFoundException':
  20. res.status(404).send('User not found')
  21. return
  22. case 'DatabaseErrorException':
  23. res.status(500).send('Db error')
  24. return
  25. default:
  26. res.status(500).send('Unknown error')
  27. return
  28. }
  29. }
  30. res.status(200).send('User updated')
  31. })
Add Comment
Please, Sign In to add comment