Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

matchqueue.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const Schmervice = require('@hapipal/schmervice')
  2. module.exports = class MatchQueService extends Schmervice.Service {
  3. constructor(...args) {
  4. super(...args)
  5. }
  6. async getPotentials(profileId) {
  7. const { MatchQue } = this.server.models()
  8. const allPotentials = await MatchQue.query()
  9. .where('profile_id', profileId)
  10. .andWhere('deleted', false)
  11. return allPotentials
  12. }
  13. /**
  14. * Saves Scored Profile Ids to MatchQue IN ORDER
  15. * @param {number} profileId
  16. * @param {array} potentialProfileIds
  17. */
  18. async insertScoredProfilesIntoMatchQue(profileId, potentialProfileIds) {
  19. const { MatchQue } = this.server.models()
  20. // returns an array of all matches for the profileId where the profile_id_2 already exists in the potentialProfileIds array
  21. await MatchQue.query()
  22. .patch({
  23. deleted: true,
  24. })
  25. .where('profile_id', profileId)
  26. for (let potentialProfileId of potentialProfileIds) {
  27. await MatchQue.query().insert({
  28. profile_id: profileId,
  29. profile_id_2: potentialProfileId,
  30. deleted: false,
  31. })
  32. }
  33. return await this.getPotentials(profileId)
  34. }
  35. /**
  36. * Set the rows deleted as true, does NOT DELETE from database
  37. * @param {number} profileId
  38. * @param {number} profileId2
  39. * @param {boolean} reinsert
  40. * @returns
  41. */
  42. async markAsDeleted(profileId, profileId2, reinsert) {
  43. const { MatchQue } = this.server.models()
  44. await MatchQue.query()
  45. .patch({
  46. deleted: true,
  47. })
  48. .where('profile_id', profileId)
  49. .andWhere('profile_id_2', profileId2)
  50. .first()
  51. if (reinsert) {
  52. await MatchQue.query().insert({
  53. profile_id: profileId,
  54. profile_id_2: profileId2,
  55. deleted: false,
  56. })
  57. }
  58. return await this.getPotentials(profileId)
  59. }
  60. }