@maioradv/nestjs-core 1.8.1 → 1.8.3

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.
@@ -51,20 +51,21 @@ function PaginatedGQL(classRef) {
51
51
  }
52
52
  class PaginatedGQLDto {
53
53
  constructor(data, meta, query) {
54
- this.edges = this.getEdges(data, query.cursorField);
54
+ this.edges = this.getEdges(data);
55
55
  this.nodes = data;
56
- const [firstIndex, lastIndex] = query.cursorOrder == 'asc' ? [0, this.edges.length - 1] : [this.edges.length - 1, 0];
56
+ const [first, last] = query.sorting == 'asc' ? [meta.first, meta.last] : [meta.last, meta.first];
57
57
  this.meta = new cursor_meta_dto_1.default({
58
- ...meta,
59
- start: +this.edges[firstIndex]?.cursor,
60
- end: +this.edges[lastIndex]?.cursor
58
+ first,
59
+ last,
60
+ start: +this.edges[0]?.cursor,
61
+ end: +this.edges[this.edges.length - 1]?.cursor
61
62
  });
62
63
  }
63
- getEdges(data, cursor) {
64
+ getEdges(data) {
64
65
  return data.map((value) => {
65
66
  return {
66
67
  node: value,
67
- cursor: value[cursor],
68
+ cursor: value.id,
68
69
  };
69
70
  });
70
71
  }
@@ -3,12 +3,11 @@ export default class CursorQueryDto {
3
3
  readonly after?: number;
4
4
  readonly before?: number;
5
5
  readonly limit?: number;
6
- readonly cursorField?: string;
7
- readonly cursorOrder?: Sorting;
6
+ readonly sorting?: Sorting;
8
7
  get skip(): number;
9
8
  get take(): number;
10
9
  get order(): Record<string, any>;
11
- get cursor(): {
12
- [x: string]: number;
10
+ get getCursor(): {
11
+ id: number;
13
12
  };
14
13
  }
@@ -17,8 +17,7 @@ const sorting_1 = require("../sorting");
17
17
  let CursorQueryDto = class CursorQueryDto {
18
18
  constructor() {
19
19
  this.limit = 50;
20
- this.cursorField = 'id';
21
- this.cursorOrder = sorting_1.Sorting.asc;
20
+ this.sorting = sorting_1.Sorting.asc;
22
21
  }
23
22
  get skip() {
24
23
  if (this.after || this.before)
@@ -32,12 +31,12 @@ let CursorQueryDto = class CursorQueryDto {
32
31
  }
33
32
  get order() {
34
33
  return {
35
- [this.cursorField]: this.cursorOrder
34
+ id: this.sorting
36
35
  };
37
36
  }
38
- get cursor() {
37
+ get getCursor() {
39
38
  return this.after || this.before ? {
40
- [this.cursorField]: this.after ?? this.before
39
+ id: this.after ?? this.before
41
40
  } : undefined;
42
41
  }
43
42
  };
@@ -79,16 +78,6 @@ __decorate([
79
78
  (0, class_transformer_1.Type)(() => Number),
80
79
  __metadata("design:type", Number)
81
80
  ], CursorQueryDto.prototype, "limit", void 0);
82
- __decorate([
83
- (0, swagger_1.ApiProperty)({
84
- required: false,
85
- default: 'id',
86
- }),
87
- (0, graphql_1.Field)({ nullable: true }),
88
- (0, class_validator_1.IsString)(),
89
- (0, class_validator_1.IsOptional)(),
90
- __metadata("design:type", String)
91
- ], CursorQueryDto.prototype, "cursorField", void 0);
92
81
  __decorate([
93
82
  (0, swagger_1.ApiProperty)({
94
83
  required: false,
@@ -100,7 +89,7 @@ __decorate([
100
89
  (0, class_validator_1.IsEnum)(sorting_1.Sorting),
101
90
  (0, class_validator_1.IsOptional)(),
102
91
  __metadata("design:type", String)
103
- ], CursorQueryDto.prototype, "cursorOrder", void 0);
92
+ ], CursorQueryDto.prototype, "sorting", void 0);
104
93
  CursorQueryDto = __decorate([
105
94
  (0, graphql_1.ArgsType)()
106
95
  ], CursorQueryDto);
@@ -5,3 +5,8 @@ export type WithRelations<T, R extends object> = T & R;
5
5
  export type WithRequired<T, K extends keyof T> = T & {
6
6
  [P in K]-?: T[P];
7
7
  };
8
+ export type ExtractProperties<T, H> = {
9
+ [K in keyof T]: T[K] extends H ? K : never;
10
+ }[keyof T];
11
+ export type FilteredProperties<T, H> = Pick<T, ExtractProperties<T, H>>;
12
+ export type ExtractCursors<T> = ExtractProperties<T, string | number | Date>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",