您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

matchqueue.js 1.9KB

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