@@ -16,6 +16,29 @@ import ObjectID from 'bson-objectid'
16
16
import { globalModels as models } from './service-module/global-models'
17
17
import stringify from 'fast-json-stable-stringify'
18
18
19
+ interface Query {
20
+ [ key : string ] : any
21
+ }
22
+ interface PaginationOptions {
23
+ default : number
24
+ max : number
25
+ }
26
+ interface Params {
27
+ query ?: Query
28
+ paginate ?: false | Pick < PaginationOptions , 'max' >
29
+ provider ?: string
30
+ route ?: { [ key : string ] : string }
31
+ headers ?: { [ key : string ] : any }
32
+
33
+ [ key : string ] : any // (JL) not sure if we want this
34
+ }
35
+ interface Paginated < T > {
36
+ total : number
37
+ limit : number
38
+ skip : number
39
+ data : T [ ]
40
+ }
41
+
19
42
export function stripSlashes ( location : string ) {
20
43
return _trim ( location , '/' )
21
44
}
@@ -283,28 +306,22 @@ export function updateOriginal(original, newData) {
283
306
} )
284
307
}
285
308
286
- export function getQueryInfo ( params = { } , response = { } ) {
287
- // @ts -ignore
309
+ // @ts -ignore
310
+ export function getQueryInfo ( params : Params = { } , response : Paginated = { } ) {
288
311
const query = params . query || { }
289
- // @ts -ignore
290
312
const qid = params . qid || 'default'
291
- // @ts -ignore
292
- const $limit = ( response . limit !== null && response . limit !== undefined )
293
- // @ts -ignore
294
- ? response . limit
295
- : query . $limit
296
- // @ts -ignore
297
- const $skip = ( response . skip !== null && response . skip !== undefined )
298
- // @ts -ignore
299
- ? response . skip
300
- : query . $skip
313
+ const $limit =
314
+ response . limit !== null && response . limit !== undefined
315
+ ? response . limit
316
+ : query . $limit
317
+ const $skip =
318
+ response . skip !== null && response . skip !== undefined
319
+ ? response . skip
320
+ : query . $skip
301
321
302
- // @ts -ignore
303
322
const queryParams = _omit ( query , [ '$limit' , '$skip' ] )
304
- // @ts -ignore
305
323
const queryId = stringify ( queryParams )
306
324
const pageParams = $limit !== undefined ? { $limit, $skip } : undefined
307
- // @ts -ignore
308
325
const pageId = pageParams ? stringify ( pageParams ) : undefined
309
326
310
327
return {
0 commit comments