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.

leave.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. const Joi = require('joi')
  3. const apiSchema = require('../../schemas/api')
  4. const pluginConfig = {
  5. handlerType: 'grouping',
  6. docs: {
  7. description: 'leave',
  8. notes: 'Leave a grouping by editing a membership record',
  9. },
  10. opts: {
  11. tags: ['api'],
  12. auth:
  13. process.env.USE_AUTH != 'true'
  14. ? false
  15. : { strategy: 'default_jwt' },
  16. cors: true,
  17. },
  18. }
  19. const validators = {
  20. leave: {
  21. payload: Joi.object(),
  22. },
  23. }
  24. module.exports = {
  25. method: 'POST',
  26. path: '/leave',
  27. options: {
  28. ...pluginConfig.docs,
  29. ...pluginConfig.opts,
  30. handler: async function (request, h) {
  31. try {
  32. return {
  33. ok: true,
  34. handler: pluginConfig.handlerType,
  35. data: { foo: 'bar' },
  36. }
  37. } catch (err) {
  38. return {
  39. ok: false,
  40. handler: pluginConfig.handlerType,
  41. data: { error: `${err}` },
  42. }
  43. }
  44. },
  45. validate: validators.leave,
  46. response: {
  47. schema: apiSchema.single.append({
  48. data: validators.leave,
  49. }),
  50. failAction: 'log',
  51. },
  52. },
  53. }