| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { db } from '../utils/db'
- import { Profile } from '../entities'
-
- /**
- * Get a match queue of profiles
- * @param {number} profileId
- * @returns {array} profiles
- */
- const fetchQueueByProfileId = async profileId => {
- let queue
-
- try {
- queue = await db.get(
- `/profile/${profileId}/queue?include_profile=true`,
- )
- if(!queue?.length) {
- throw 'Could not retrieve match queue. Please take the survey and rescore.'
- }
- } catch (err) {
- console.error(err)
- }
-
- return queue ? queue.map(profileData => {
- return new Profile({ email: 'fixme@gmail.com', ...profileData })
- }) : []
- }
-
- /**
- * Remove or reinsert a profile in match queue
- * @param {number} profileId profile viewing the queue
- * @param {number} targetId
- * @param {boolean} reinsert FALSE if profileId accepted targetId; TRUE to reinsert into match queue
- * @returns {array} profiles
- */
- const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
- const updateQueue = await db.patch(
- `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
- [ targetId ],
- )
- return updateQueue ? updateQueue.map(profileData => {
- return new Profile({ email: 'fixme@gmail.com', ...profileData })
- }) : []
- }
-
- export { fetchQueueByProfileId, updateQueueByProfileId }
|