@maioradv/nestjs-core 1.8.2 → 1.8.4
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
|
|
54
|
+
this.edges = this.getEdges(data);
|
|
55
55
|
this.nodes = data;
|
|
56
|
-
const [
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
64
|
+
getEdges(data) {
|
|
64
65
|
return data.map((value) => {
|
|
65
66
|
return {
|
|
66
67
|
node: value,
|
|
67
|
-
cursor: value
|
|
68
|
+
cursor: value.id,
|
|
68
69
|
};
|
|
69
70
|
});
|
|
70
71
|
}
|
|
@@ -3,10 +3,11 @@ export default class CursorQueryDto {
|
|
|
3
3
|
readonly after?: number;
|
|
4
4
|
readonly before?: number;
|
|
5
5
|
readonly limit?: number;
|
|
6
|
-
readonly
|
|
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():
|
|
10
|
+
get cursor(): {
|
|
11
|
+
id: number;
|
|
12
|
+
};
|
|
12
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.
|
|
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
|
-
|
|
34
|
+
id: this.sorting
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
get cursor() {
|
|
39
38
|
return this.after || this.before ? {
|
|
40
|
-
|
|
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, "
|
|
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>;
|