@roit/roit-data-firestore 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roit/roit-data-firestore",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "main": "dist/index.js",
5
5
  "types": "src/index.ts",
6
6
  "scripts": {
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@google-cloud/firestore": "4.10.1",
27
27
  "@roit/roit-date": "1.7.0",
28
- "class-validator": "0.12.0",
28
+ "class-validator": "0.13.0",
29
29
  "class-validator-jsonschema": "^3.1.0",
30
30
  "firebase": "^9.2.0",
31
31
  "node-cache": "5.1.2",
@@ -1,11 +1,11 @@
1
1
 
2
2
  export class Paging {
3
3
 
4
- orderBy?: string = 'id'
4
+ orderBy?: string | string[] = 'id'
5
5
 
6
6
  orderByDirection?: Direction = 'asc'
7
7
 
8
- cursor?: string | null = null
8
+ cursor?: string | string[] | null = null
9
9
 
10
10
  limit: number = 1000
11
11
  }
@@ -4,20 +4,21 @@ import { Paging } from "../model/Paging";
4
4
  export class QueryCreatorConfig {
5
5
 
6
6
  buildPaging(collectionRef: CollectionReference<DocumentData>, paging?: Paging): Query<DocumentData> {
7
-
8
- const orderBy = paging?.orderBy || ''
9
7
  const orderByDirection = paging?.orderByDirection || 'asc'
10
- const startAfter = paging?.cursor
11
8
  const limit = paging?.limit ?? 1000
12
9
 
13
10
  let documentRef: Query<DocumentData> = collectionRef.limit(limit)
14
11
 
15
- if (orderBy) {
16
- documentRef = documentRef.orderBy(orderBy, orderByDirection)
12
+ if (paging?.orderBy) {
13
+ const ordersBy = Array.isArray(paging.orderBy) ? paging.orderBy : [paging.orderBy]
14
+ ordersBy.forEach(order =>
15
+ documentRef = documentRef.orderBy(order, orderByDirection)
16
+ )
17
17
  }
18
18
 
19
- if (startAfter) {
20
- documentRef= documentRef.startAfter(startAfter)
19
+ if (paging?.cursor) {
20
+ const startAfter = Array.isArray(paging.cursor) ? paging.cursor : [paging.cursor]
21
+ documentRef = documentRef.startAfter(...startAfter)
21
22
  }
22
23
 
23
24
  return documentRef