@hedhog/pagination 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pagination.service.d.ts","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,qBACa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEvD,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"pagination.service.d.ts","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,qBACa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAEvD,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EACnC,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAuH9B,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE;IAgBvD,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO;IAI5D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO;CAK7D"}
|
@@ -17,6 +17,9 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
17
17
|
}
|
18
18
|
async paginate(model, paginationParams, customQuery) {
|
19
19
|
try {
|
20
|
+
if (!model) {
|
21
|
+
throw new common_1.BadRequestException('Model is required');
|
22
|
+
}
|
20
23
|
const page = Number(paginationParams.page || pagination_constants_1.DEFAULT_PAGE);
|
21
24
|
const pageSize = Number(paginationParams.pageSize || pagination_constants_1.DEFAULT_PAGE_SIZE);
|
22
25
|
const search = paginationParams.search || null;
|
@@ -32,6 +35,7 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
32
35
|
let sortOrderCondition = {
|
33
36
|
id: paginationParams.sortOrder || patination_enums_1.PageOrderDirection.Asc,
|
34
37
|
};
|
38
|
+
console.log('sortField:', sortField);
|
35
39
|
if (sortField) {
|
36
40
|
const invalid = this.isInvalidField(sortField, model);
|
37
41
|
if (invalid) {
|
@@ -46,6 +50,7 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
46
50
|
throw new common_1.BadRequestException('Search must be a string');
|
47
51
|
}
|
48
52
|
}
|
53
|
+
console.log('fields:', fields);
|
49
54
|
if (fields) {
|
50
55
|
const invalidFields = this.isInvalidFields(fields, model);
|
51
56
|
if (invalidFields) {
|
@@ -69,6 +74,8 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
69
74
|
query.include = customQuery === null || customQuery === void 0 ? void 0 : customQuery.include;
|
70
75
|
delete query.select;
|
71
76
|
}
|
77
|
+
console.log('Query:', query);
|
78
|
+
console.log('model:', model);
|
72
79
|
const [total, data] = await Promise.all([
|
73
80
|
model.count({ where: (customQuery === null || customQuery === void 0 ? void 0 : customQuery.where) || {} }),
|
74
81
|
model.findMany(query),
|
@@ -94,6 +101,7 @@ let PaginationService = PaginationService_1 = class PaginationService {
|
|
94
101
|
}
|
95
102
|
extractFieldNames(model) {
|
96
103
|
const fieldNames = [];
|
104
|
+
console.log('extractFieldNames', { model });
|
97
105
|
const fields = model.fields;
|
98
106
|
for (const key in fields) {
|
99
107
|
if (fields && fields.hasOwnProperty(key)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pagination.service.js","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2EAG0C;AAC1C,+DAA8D;AASvD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAAvB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"pagination.service.js","sourceRoot":"","sources":["../src/pagination.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAyE;AACzE,2EAG0C;AAC1C,+DAA8D;AASvD,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAAvB;QACY,WAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IAsJ/D,CAAC;IApJC,KAAK,CAAC,QAAQ,CACZ,KAAQ,EACR,gBAAkC,EAClC,WAA6B;QAE7B,IAAI,CAAC;YACH,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,4BAAmB,CAAC,mBAAmB,CAAC,CAAC;YACrD,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,IAAI,mCAAY,CAAC,CAAC;YAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,QAAQ,IAAI,wCAAiB,CAAC,CAAC;YACxE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,IAAI,IAAI,CAAC;YAC/C,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,IAAI,IAAI,CAAC;YACrD,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,IAAI,qCAAkB,CAAC,GAAG,CAAC;YACvE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;gBACpC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;gBACpC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,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,cAAc,CAAC,SAAiB,EAAE,KAAgB;QAChD,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,CAAC;IAED,eAAe,CAAC,MAAgB,EAAE,KAAgB;QAChD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7B,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CACpD,CAAC;IACJ,CAAC;CACF,CAAA;AAvJY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAuJ7B"}
|
package/package.json
CHANGED
@@ -21,6 +21,10 @@ export class PaginationService {
|
|
21
21
|
customQuery?: FindManyArgs<M>,
|
22
22
|
): Promise<PaginatedResult<T>> {
|
23
23
|
try {
|
24
|
+
if (!model) {
|
25
|
+
throw new BadRequestException('Model is required');
|
26
|
+
}
|
27
|
+
|
24
28
|
const page = Number(paginationParams.page || DEFAULT_PAGE);
|
25
29
|
const pageSize = Number(paginationParams.pageSize || DEFAULT_PAGE_SIZE);
|
26
30
|
const search = paginationParams.search || null;
|
@@ -41,6 +45,8 @@ export class PaginationService {
|
|
41
45
|
id: paginationParams.sortOrder || PageOrderDirection.Asc,
|
42
46
|
};
|
43
47
|
|
48
|
+
console.log('sortField:', sortField);
|
49
|
+
|
44
50
|
if (sortField) {
|
45
51
|
const invalid = this.isInvalidField(sortField, model);
|
46
52
|
if (invalid) {
|
@@ -62,6 +68,8 @@ export class PaginationService {
|
|
62
68
|
}
|
63
69
|
}
|
64
70
|
|
71
|
+
console.log('fields:', fields);
|
72
|
+
|
65
73
|
if (fields) {
|
66
74
|
const invalidFields = this.isInvalidFields(fields, model);
|
67
75
|
|
@@ -100,6 +108,9 @@ export class PaginationService {
|
|
100
108
|
delete query.select;
|
101
109
|
}
|
102
110
|
|
111
|
+
console.log('Query:', query);
|
112
|
+
console.log('model:', model);
|
113
|
+
|
103
114
|
const [total, data] = await Promise.all([
|
104
115
|
model.count({ where: customQuery?.where || {} }),
|
105
116
|
model.findMany(query),
|
@@ -129,6 +140,9 @@ export class PaginationService {
|
|
129
140
|
|
130
141
|
extractFieldNames(model: Record<string, any>): string[] {
|
131
142
|
const fieldNames: string[] = [];
|
143
|
+
|
144
|
+
console.log('extractFieldNames', { model });
|
145
|
+
|
132
146
|
const fields = model.fields;
|
133
147
|
|
134
148
|
for (const key in fields) {
|