Просмотр исходного кода

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

tags/0.0.3^2
juancarbajal98 3 лет назад
Родитель
Сommit
9d2e254c9b
2 измененных файлов: 11 добавлений и 5 удалений
  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 Просмотреть файл

@@ -23,7 +23,7 @@ const responseSchemas = {
23 23
 
24 24
 const validators = {
25 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 29
 module.exports = {
@@ -37,13 +37,12 @@ module.exports = {
37 37
         cors: true,
38 38
         handler: async function (request, h) {
39 39
             const { profile_id } = request.params
40
-            const { include_profile } = request.query
40
+            const { include_profile, limit, offset} = request.query
41 41
             const { profileService, matchQueueService } =
42 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 45
             const queueIds = queue.map(entry => entry.target_id)
46
-            // console.log('queueIds', queueIds)
47 46
             const res = {
48 47
                 ok: true,
49 48
                 handler: pluginConfig.handlerType,

+ 8
- 1
backend/lib/services/matchqueue.js Просмотреть файл

@@ -9,12 +9,19 @@ module.exports = class MatchQueueService extends Schmervice.Service {
9 9
      * @param {number} profileId
10 10
      * @returns {array} MatchQueue
11 11
      */
12
-    async getQueue(profileId) {
12
+    async getQueue(profileId, limit, offset=0) {
13 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 20
         return await MatchQueue.query()
16 21
             .where('profile_id', profileId)
17 22
             .where('is_deleted', 0)
23
+            .limit(limit)
24
+            .offset(offset)
18 25
     }
19 26
     /**
20 27
      * Returns queues by profile id by user type

Загрузка…
Отмена
Сохранить