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, offset = 0, limit = 5) => { let queue try { 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 }