Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

queue.service.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { db } from '../utils/db.js'
  2. import { Profile } from '../entities/index.js'
  3. /**
  4. * Get a match queue of profiles
  5. * @param {number} profileId
  6. * @param {number} limit
  7. * @param {number} offset
  8. * @returns {array} profiles
  9. */
  10. const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
  11. let queue
  12. try {
  13. if(typeof limit==='undefined') queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=5`)
  14. else queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=${limit}&offset=${offset}`)
  15. if (!queue?.length) {
  16. throw '[Queue Service]: Could not retrieve match queue.\nHave you taken the survey and scored this profile?'
  17. }
  18. } catch (err) {
  19. console.error(err)
  20. }
  21. return queue
  22. ? queue.map(profileData => {
  23. return new Profile({ email: 'fixme@gmail.com', ...profileData })
  24. })
  25. : []
  26. }
  27. /**
  28. * Remove or reinsert a profile in match queue
  29. * @param {number} profileId profile viewing the queue
  30. * @param {number} targetId
  31. * @param {boolean} reinsert FALSE if profileId accepted targetId; TRUE to reinsert into match queue
  32. * @returns {array} profiles
  33. */
  34. const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
  35. let updateQueue
  36. try {
  37. updateQueue = await db.patch(
  38. `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
  39. )
  40. if (!updateQueue?.length) {
  41. throw '[Queue Service]: Could not update match queue.'
  42. }
  43. } catch (err) {
  44. console.error(err)
  45. }
  46. return updateQueue
  47. ? updateQueue.map(profileData => {
  48. return new Profile({ email: 'fixme@gmail.com', ...profileData })
  49. })
  50. : []
  51. }
  52. export { fetchQueueByProfileId, updateQueueByProfileId }