Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

score.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'score',
  5. docs: {
  6. description: 'scores',
  7. notes: 'A list of profile scores',
  8. },
  9. }
  10. const validators = {
  11. /** Validate the header (cookie check) */
  12. // headers: true,
  13. /** Validate the route params (/active/{thing}) */
  14. params: Joi.object({
  15. profile_id: Joi.number(),
  16. }),
  17. /** Validate the route query (/active/{thing}?limit=10&offset=10) */
  18. // query: true,
  19. /** Validate the incoming payload (POST method) */
  20. // payload: true,
  21. }
  22. const responseSchemas = {}
  23. module.exports = {
  24. method: 'GET',
  25. path: '/{profile_id}/score',
  26. options: {
  27. ...pluginConfig.docs,
  28. tags: ['api'],
  29. /** Protect this route with authentication? */
  30. auth: false,
  31. handler: async function (request, h) {
  32. const { profileService } = request.services()
  33. const profileId = request.params.profile_id
  34. const profiles = await profileService.scoreProfilesFor(profileId)
  35. try {
  36. return {
  37. ok: true,
  38. handler: pluginConfig.handlerType,
  39. data: profiles,
  40. }
  41. } catch (err) {
  42. return {
  43. ok: false,
  44. handler: pluginConfig.handlerType,
  45. data: { error: `${err}` },
  46. }
  47. }
  48. },
  49. /** Validate based on validators object */
  50. validate: {
  51. ...validators,
  52. failAction: 'log',
  53. },
  54. /** Validate the server response */
  55. response: {
  56. schema: Joi.object({
  57. ok: Joi.bool(),
  58. handler: Joi.string(),
  59. data: Joi.array().items(),
  60. }),
  61. },
  62. },
  63. }