Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

patch-queue.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'profile',
  5. docs: {
  6. description: 'Updates match queue in place',
  7. notes: 'Updates in place and does not delete from table',
  8. },
  9. }
  10. const responseSchemas = {
  11. responses: Joi.array().items(
  12. Joi.alternatives().try(
  13. Joi.number(),
  14. Joi.object({
  15. // ORIGINAL
  16. profile_id: Joi.number(),
  17. user_id: Joi.number(),
  18. // Added user_name, user_media to account for updated CompleteProfile
  19. user_name: Joi.string(),
  20. user_media: Joi.string(),
  21. responses: Joi.array().items(),
  22. user_type: Joi.any(),
  23. }),
  24. ),
  25. ),
  26. error: Joi.object({
  27. error: Joi.string(),
  28. }),
  29. }
  30. const validators = {
  31. params: Joi.object({ profile_id: Joi.number(), target_id: Joi.number() }),
  32. query: Joi.object({ include_profile: Joi.bool(), reinsert: Joi.boolean() }),
  33. }
  34. module.exports = {
  35. method: 'PATCH',
  36. path: '/{profile_id}/queue/{target_id}/delete',
  37. options: {
  38. ...pluginConfig.docs,
  39. tags: ['api'],
  40. /** Protect this route with authentication? */
  41. auth: false,
  42. cors: true,
  43. handler: async function (request, h) {
  44. const { profile_id, target_id } = request.params
  45. const { include_profile, reinsert } = request.query
  46. const { profileService, matchQueueService } =
  47. request.server.services()
  48. // console.log('reinsert', reinsert)
  49. const updatedQueue = await matchQueueService.markAsDeleted(
  50. profile_id,
  51. target_id,
  52. reinsert,
  53. )
  54. const queueIds = updatedQueue.map(entry => entry.target_id)
  55. const res = {
  56. ok: true,
  57. handler: pluginConfig.handlerType,
  58. data: queueIds,
  59. }
  60. if (include_profile) {
  61. res.data = await profileService.getProfilesFor(queueIds)
  62. }
  63. try {
  64. return h.response(res).code(200)
  65. } catch (err) {
  66. return h
  67. .response({
  68. ok: false,
  69. handler: pluginConfig.handlerType,
  70. data: { error: `${err}` },
  71. })
  72. .code(409)
  73. }
  74. },
  75. /** Validate based on validators object */
  76. validate: {
  77. ...validators,
  78. failAction: 'log',
  79. },
  80. /** Validate the server response */
  81. response: {
  82. status: {
  83. 200: Joi.object({
  84. ok: Joi.bool(),
  85. handler: Joi.string(),
  86. data: responseSchemas.responses,
  87. }),
  88. 409: Joi.object({
  89. ok: Joi.bool(),
  90. handler: Joi.string(),
  91. data: responseSchemas.error,
  92. }),
  93. },
  94. },
  95. },
  96. }