@nest-omni/core 3.1.1-21 → 3.1.1-22
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/common/dto/dto-extensions.js +6 -11
- package/decorators/api-paginated-response.decorator.d.ts +2 -0
- package/decorators/api-paginated-response.decorator.js +9 -0
- package/decorators/field.decorators.js +3 -1
- package/decorators/index.d.ts +2 -0
- package/decorators/index.js +2 -0
- package/decorators/paginated-response.decorator.d.ts +11 -0
- package/decorators/paginated-response.decorator.js +60 -0
- package/package.json +1 -1
|
@@ -34,10 +34,7 @@ typeorm_1.SelectQueryBuilder.prototype.toDtoPage = function (pageOptionsDto, dto
|
|
|
34
34
|
const pageSize = pageOptionsDto.pageSize || 10;
|
|
35
35
|
const skip = (page - 1) * pageSize;
|
|
36
36
|
const totalItems = yield this.getCount();
|
|
37
|
-
const entities = yield this
|
|
38
|
-
.skip(skip)
|
|
39
|
-
.take(pageSize)
|
|
40
|
-
.getMany();
|
|
37
|
+
const entities = yield this.skip(skip).take(pageSize).getMany();
|
|
41
38
|
if (entities.length > 0) {
|
|
42
39
|
console.log('Raw entity sample:', JSON.stringify(entities[0], null, 2));
|
|
43
40
|
}
|
|
@@ -51,13 +48,11 @@ typeorm_1.SelectQueryBuilder.prototype.toDtoPage = function (pageOptionsDto, dto
|
|
|
51
48
|
const hasNextPage = page < pageCount;
|
|
52
49
|
return {
|
|
53
50
|
data,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
hasNextPage,
|
|
60
|
-
},
|
|
51
|
+
itemCount,
|
|
52
|
+
page,
|
|
53
|
+
pageCount,
|
|
54
|
+
hasPreviousPage,
|
|
55
|
+
hasNextPage,
|
|
61
56
|
};
|
|
62
57
|
});
|
|
63
58
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiPaginatedResponse = ApiPaginatedResponse;
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
const paginated_response_decorator_1 = require("./paginated-response.decorator");
|
|
6
|
+
function ApiPaginatedResponse(entityClass, options) {
|
|
7
|
+
const ResponseDto = (0, paginated_response_decorator_1.createPaginatedResponseDto)(entityClass);
|
|
8
|
+
return (0, swagger_1.ApiResponse)(Object.assign(Object.assign({}, options), { type: ResponseDto }));
|
|
9
|
+
}
|
|
@@ -383,6 +383,7 @@ function FQDNFieldOptional(options = {}) {
|
|
|
383
383
|
return (0, common_1.applyDecorators)((0, validator_decorators_1.IsEmptyable)(), FQDNField(Object.assign({ required: false }, options)));
|
|
384
384
|
}
|
|
385
385
|
function DateField(options = {}) {
|
|
386
|
+
var _a;
|
|
386
387
|
const decorators = [
|
|
387
388
|
(0, class_transformer_1.Type)(() => Date),
|
|
388
389
|
(0, class_validator_1.IsDate)({ message: (0, nestjs_i18n_1.i18nValidationMessage)('validation.IS_DATE') }),
|
|
@@ -406,7 +407,8 @@ function DateField(options = {}) {
|
|
|
406
407
|
}));
|
|
407
408
|
}
|
|
408
409
|
if (options.swagger !== false) {
|
|
409
|
-
|
|
410
|
+
const swaggerOptions = Object.assign({ type: Date, example: (_a = options.example) !== null && _a !== void 0 ? _a : new Date() }, options);
|
|
411
|
+
decorators.push((0, swagger_1.ApiProperty)(swaggerOptions));
|
|
410
412
|
}
|
|
411
413
|
return (0, common_1.applyDecorators)(...decorators);
|
|
412
414
|
}
|
package/decorators/index.d.ts
CHANGED
|
@@ -10,3 +10,5 @@ export * from './translate.decorator';
|
|
|
10
10
|
export * from './use-dto.decorator';
|
|
11
11
|
export * from './validator.decorators';
|
|
12
12
|
export * from './controller.decorator';
|
|
13
|
+
export * from './api-paginated-response.decorator';
|
|
14
|
+
export * from './paginated-response.decorator';
|
package/decorators/index.js
CHANGED
|
@@ -26,3 +26,5 @@ __exportStar(require("./translate.decorator"), exports);
|
|
|
26
26
|
__exportStar(require("./use-dto.decorator"), exports);
|
|
27
27
|
__exportStar(require("./validator.decorators"), exports);
|
|
28
28
|
__exportStar(require("./controller.decorator"), exports);
|
|
29
|
+
__exportStar(require("./api-paginated-response.decorator"), exports);
|
|
30
|
+
__exportStar(require("./paginated-response.decorator"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function createPaginatedResponseDto<T extends new (...args: any[]) => any>(entityClass: T): {
|
|
2
|
+
new (): {
|
|
3
|
+
data: InstanceType<T>[];
|
|
4
|
+
count?: number;
|
|
5
|
+
total?: number;
|
|
6
|
+
page?: number;
|
|
7
|
+
pageCount?: number;
|
|
8
|
+
hasPreviousPage?: boolean;
|
|
9
|
+
hasNextPage?: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createPaginatedResponseDto = createPaginatedResponseDto;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const class_transformer_1 = require("class-transformer");
|
|
15
|
+
function createPaginatedResponseDto(entityClass) {
|
|
16
|
+
const entityName = entityClass.name.replace('Dto', '');
|
|
17
|
+
class PaginatedResponse {
|
|
18
|
+
}
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, swagger_1.ApiProperty)({
|
|
21
|
+
type: entityClass,
|
|
22
|
+
isArray: true,
|
|
23
|
+
description: `${entityName} data`,
|
|
24
|
+
}),
|
|
25
|
+
(0, class_transformer_1.Type)(() => entityClass),
|
|
26
|
+
__metadata("design:type", Array)
|
|
27
|
+
], PaginatedResponse.prototype, "data", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, swagger_1.ApiPropertyOptional)({
|
|
30
|
+
example: 10,
|
|
31
|
+
description: 'Number of items in current page',
|
|
32
|
+
}),
|
|
33
|
+
__metadata("design:type", Number)
|
|
34
|
+
], PaginatedResponse.prototype, "count", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, swagger_1.ApiPropertyOptional)({ example: 100, description: 'Total number of items' }),
|
|
37
|
+
__metadata("design:type", Number)
|
|
38
|
+
], PaginatedResponse.prototype, "total", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, swagger_1.ApiPropertyOptional)({ example: 1, description: 'Current page number' }),
|
|
41
|
+
__metadata("design:type", Number)
|
|
42
|
+
], PaginatedResponse.prototype, "page", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, swagger_1.ApiPropertyOptional)({ example: 10, description: 'Total number of pages' }),
|
|
45
|
+
__metadata("design:type", Number)
|
|
46
|
+
], PaginatedResponse.prototype, "pageCount", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, swagger_1.ApiPropertyOptional)({ example: false, description: 'Has previous page' }),
|
|
49
|
+
__metadata("design:type", Boolean)
|
|
50
|
+
], PaginatedResponse.prototype, "hasPreviousPage", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, swagger_1.ApiPropertyOptional)({ example: true, description: 'Has next page' }),
|
|
53
|
+
__metadata("design:type", Boolean)
|
|
54
|
+
], PaginatedResponse.prototype, "hasNextPage", void 0);
|
|
55
|
+
Object.defineProperty(PaginatedResponse, 'name', {
|
|
56
|
+
value: `${entityName}PaginatedResponseDto`,
|
|
57
|
+
writable: false,
|
|
58
|
+
});
|
|
59
|
+
return PaginatedResponse;
|
|
60
|
+
}
|
package/package.json
CHANGED