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