| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { db } from '../utils/db.js'
- import { Profile } from '../entities/index.js'
-
- /**
- * Get a match queue of profiles
- * @param {number} profileId
- * @param {number} limit
- * @param {number} offset
- * @returns {array} profiles
- */
- const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
- let queue
- try {
- if(typeof limit==='undefined') queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=5`)
- else queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=${limit}&offset=${offset}`)
-
- if (!queue?.length) {
- throw '[Queue Service]: Could not retrieve match queue.\nHave you taken the survey and scored this profile?'
- }
- } 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) => {
- let updateQueue
- try {
- updateQueue = await db.patch(
- `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
- )
- if (!updateQueue?.length) {
- throw '[Queue Service]: Could not update match queue.'
- }
- } catch (err) {
- console.error(err)
- }
- return updateQueue
- ? updateQueue.map(profileData => {
- return new Profile({ email: 'fixme@gmail.com', ...profileData })
- })
- : []
- }
-
- export { fetchQueueByProfileId, updateQueueByProfileId }
|