Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

queue.service.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { db } from '../utils/db'
  2. import { Profile } from '../entities'
  3. /**
  4. * Get a match queue of profiles
  5. * @param {number} profileId
  6. * @returns {array} profiles
  7. */
  8. const fetchQueueByProfileId = async profileId => {
  9. let queue
  10. try {
  11. queue = await db.get(`/profile/${profileId}/queue?include_profile=true`)
  12. if (!queue?.length) {
  13. throw 'Could not retrieve match queue. Please take the survey and rescore.'
  14. }
  15. } catch (err) {
  16. console.error(err)
  17. }
  18. return queue
  19. ? queue.map(profileData => {
  20. return new Profile({ email: 'fixme@gmail.com', ...profileData })
  21. })
  22. : []
  23. }
  24. /**
  25. * Remove or reinsert a profile in match queue
  26. * @param {number} profileId profile viewing the queue
  27. * @param {number} targetId
  28. * @param {boolean} reinsert FALSE if profileId accepted targetId; TRUE to reinsert into match queue
  29. * @returns {array} profiles
  30. */
  31. const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
  32. const updateQueue = await db.patch(
  33. `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
  34. )
  35. return updateQueue
  36. ? updateQueue.map(profileData => {
  37. return new Profile({ email: 'fixme@gmail.com', ...profileData })
  38. })
  39. : []
  40. }
  41. export { fetchQueueByProfileId, updateQueueByProfileId }