You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const Joi = require('joi')
  2. const pluginConfig = {
  3. handlerType: 'user',
  4. docs: {
  5. get: {
  6. description: 'get user',
  7. notes: 'Returns a user by the email passed in the path',
  8. },
  9. },
  10. }
  11. const validators = {
  12. params: Joi.object({ user_email: Joi.string() }),
  13. }
  14. module.exports = {
  15. method: 'GET',
  16. path: '/{user_email}',
  17. options: {
  18. ...pluginConfig.docs.get,
  19. tags: ['api'],
  20. // auth: 'default_jwt',
  21. auth: false,
  22. cors: true,
  23. handler: async (request, h) => {
  24. try {
  25. const { userService } = request.services()
  26. const email = request.params.user_email
  27. const user = await userService.findByEmail(email)
  28. return {
  29. ok: true,
  30. handler: pluginConfig.handlerType,
  31. data: { user },
  32. }
  33. } catch (err) {
  34. return {
  35. ok: false,
  36. handler: pluginConfig.handlerType,
  37. data: { error: err },
  38. }
  39. }
  40. },
  41. validate: {
  42. ...validators,
  43. failAction: 'log',
  44. },
  45. response: {
  46. schema: Joi.object({
  47. ok: Joi.bool(),
  48. handler: Joi.string(),
  49. data: Joi.object(),
  50. }).label('password_res'),
  51. failAction: 'log',
  52. },
  53. },
  54. }