| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- const Schmervice = require('@hapipal/schmervice')
-
- module.exports = class MatchQueueService extends Schmervice.Service {
- constructor(...args) {
- super(...args)
- }
-
- async getQueue(profileId) {
- const { MatchQueue } = this.server.models()
- return await MatchQueue.query()
- .where('profile_id', profileId)
- .andWhere('is_deleted', false)
- }
- /**
- * Saves Scored Profile Ids to MatchQue IN ORDER
- * @param {number} profileId
- * @param {array} targetIds
- */
- async saveMatchQueue(profileId, targetIds) {
- const { MatchQueue } = this.server.models()
-
- // returns an array of all matches for the profileId where the target_id already exists in the targetIds array
- await MatchQueue.query()
- .patch({
- is_deleted: true,
- })
- .where('profile_id', profileId)
-
- for (let id of targetIds) {
- await MatchQueue.query().insert({
- profile_id: profileId,
- target_id: id,
- is_deleted: false,
- })
- }
-
- return await this.getQueue(profileId)
- }
- /**
- * Set the rows deleted as true, does NOT DELETE from database
- * @param {number} profileId
- * @param {number} targetId
- * @param {boolean} reinsert
- * @returns
- */
- async markAsDeleted(profileId, targetId, reinsert) {
- const { MatchQueue } = this.server.models()
- await MatchQueue.query()
- .patch({
- is_deleted: true,
- })
- .where('profile_id', profileId)
- .andWhere('target_id', targetId)
- .first()
-
- if (reinsert) {
- await MatchQueue.query().insert({
- profile_id: profileId,
- target_id: targetId,
- is_deleted: false,
- })
- }
-
- return await this.getQueue(profileId)
- }
- }
|