Browse Source

:sparkles: backend support for limiting + offsetting match queue return

tags/0.0.3^2
juancarbajal98 3 years ago
parent
commit
9d2e254c9b
2 changed files with 11 additions and 5 deletions
  1. 3
    4
      backend/lib/routes/profile/queue.js
  2. 8
    1
      backend/lib/services/matchqueue.js

+ 3
- 4
backend/lib/routes/profile/queue.js View File

23
 
23
 
24
 const validators = {
24
 const validators = {
25
     params: params.profileId,
25
     params: params.profileId,
26
-    query: params.profileInclude,
26
+    query: Joi.object({include_profile: Joi.bool(), limit: Joi.number(), offset: Joi.number()}),
27
 }
27
 }
28
 
28
 
29
 module.exports = {
29
 module.exports = {
37
         cors: true,
37
         cors: true,
38
         handler: async function (request, h) {
38
         handler: async function (request, h) {
39
             const { profile_id } = request.params
39
             const { profile_id } = request.params
40
-            const { include_profile } = request.query
40
+            const { include_profile, limit, offset} = request.query
41
             const { profileService, matchQueueService } =
41
             const { profileService, matchQueueService } =
42
                 request.server.services()
42
                 request.server.services()
43
 
43
 
44
-            const queue = await matchQueueService.getQueue(profile_id)
44
+            const queue = await matchQueueService.getQueue(profile_id, limit, offset)
45
             const queueIds = queue.map(entry => entry.target_id)
45
             const queueIds = queue.map(entry => entry.target_id)
46
-            // console.log('queueIds', queueIds)
47
             const res = {
46
             const res = {
48
                 ok: true,
47
                 ok: true,
49
                 handler: pluginConfig.handlerType,
48
                 handler: pluginConfig.handlerType,

+ 8
- 1
backend/lib/services/matchqueue.js View File

9
      * @param {number} profileId
9
      * @param {number} profileId
10
      * @returns {array} MatchQueue
10
      * @returns {array} MatchQueue
11
      */
11
      */
12
-    async getQueue(profileId) {
12
+    async getQueue(profileId, limit, offset=0) {
13
         const { MatchQueue } = this.server.models()
13
         const { MatchQueue } = this.server.models()
14
+        if(typeof limit==='undefined') {
15
+            return await MatchQueue.query()
16
+                .where('profile_id', profileId)
17
+                .where('is_deleted', 0)
18
+        }
14
 
19
 
15
         return await MatchQueue.query()
20
         return await MatchQueue.query()
16
             .where('profile_id', profileId)
21
             .where('profile_id', profileId)
17
             .where('is_deleted', 0)
22
             .where('is_deleted', 0)
23
+            .limit(limit)
24
+            .offset(offset)
18
     }
25
     }
19
     /**
26
     /**
20
      * Returns queues by profile id by user type
27
      * Returns queues by profile id by user type

Loading…
Cancel
Save