@takentrade/takentrade-libs 1.2.57 → 1.2.59
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/dist/nats/constants/nats.constants.d.ts +77 -10
- package/dist/nats/constants/nats.constants.js +95 -11
- package/dist/notification/notification.interface.d.ts +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/dto/index.d.ts +1 -4
- package/dist/utils/dto/index.js +14 -28
- package/dist/utils/dto/pagination.d.ts +8 -0
- package/dist/utils/dto/pagination.js +49 -0
- package/dist/utils/interceptors/index.d.ts +0 -1
- package/dist/utils/interceptors/index.js +0 -1
- package/dist/utils/interfaces/pagination.interface.d.ts +12 -13
- package/dist/utils/utils/index.d.ts +1 -0
- package/dist/utils/utils/index.js +1 -0
- package/dist/utils/utils/pagination.d.ts +10 -0
- package/dist/utils/utils/pagination.js +31 -0
- package/package.json +1 -1
- package/dist/utils/interceptors/pagination.interceptor.d.ts +0 -19
- package/dist/utils/interceptors/pagination.interceptor.js +0 -49
package/dist/utils/dto/index.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
7
15
|
};
|
|
8
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports
|
|
10
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
11
|
-
const class_validator_1 = require("class-validator");
|
|
12
|
-
const class_transformer_1 = require("class-transformer");
|
|
13
|
-
class PaginationDto {
|
|
14
|
-
page = 1;
|
|
15
|
-
limit = 10;
|
|
16
|
-
}
|
|
17
|
-
exports.PaginationDto = PaginationDto;
|
|
18
|
-
__decorate([
|
|
19
|
-
(0, swagger_1.ApiProperty)({ minimum: 1, default: 1 }),
|
|
20
|
-
(0, class_validator_1.IsInt)(),
|
|
21
|
-
(0, class_validator_1.IsOptional)(),
|
|
22
|
-
(0, class_transformer_1.Transform)(({ value }) => (value ? parseInt(value) : 10))
|
|
23
|
-
], PaginationDto.prototype, "page", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
(0, swagger_1.ApiProperty)({ minimum: 1, maximum: 100, default: 10 }),
|
|
26
|
-
(0, class_validator_1.IsInt)(),
|
|
27
|
-
(0, class_validator_1.Min)(1),
|
|
28
|
-
(0, class_validator_1.Max)(100),
|
|
29
|
-
(0, class_validator_1.IsOptional)(),
|
|
30
|
-
(0, class_transformer_1.Transform)(({ value }) => (value ? parseInt(value) : 10))
|
|
31
|
-
], PaginationDto.prototype, "limit", void 0);
|
|
17
|
+
__exportStar(require("./pagination"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PaginationQueryDto = void 0;
|
|
10
|
+
const class_validator_1 = require("class-validator");
|
|
11
|
+
const class_transformer_1 = require("class-transformer");
|
|
12
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
13
|
+
class PaginationQueryDto {
|
|
14
|
+
page;
|
|
15
|
+
limit;
|
|
16
|
+
search;
|
|
17
|
+
sortBy;
|
|
18
|
+
sortOrder;
|
|
19
|
+
}
|
|
20
|
+
exports.PaginationQueryDto = PaginationQueryDto;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, swagger_1.ApiPropertyOptional)({ minimum: 1, default: 1 }),
|
|
23
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
24
|
+
(0, class_validator_1.IsInt)(),
|
|
25
|
+
(0, class_validator_1.Min)(1),
|
|
26
|
+
(0, class_validator_1.IsOptional)()
|
|
27
|
+
], PaginationQueryDto.prototype, "page", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, swagger_1.ApiPropertyOptional)({ minimum: 1, maximum: 100, default: 10 }),
|
|
30
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
31
|
+
(0, class_validator_1.IsInt)(),
|
|
32
|
+
(0, class_validator_1.Min)(1),
|
|
33
|
+
(0, class_validator_1.IsOptional)()
|
|
34
|
+
], PaginationQueryDto.prototype, "limit", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, swagger_1.ApiPropertyOptional)(),
|
|
37
|
+
(0, class_validator_1.IsString)(),
|
|
38
|
+
(0, class_validator_1.IsOptional)()
|
|
39
|
+
], PaginationQueryDto.prototype, "search", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, swagger_1.ApiPropertyOptional)(),
|
|
42
|
+
(0, class_validator_1.IsString)(),
|
|
43
|
+
(0, class_validator_1.IsOptional)()
|
|
44
|
+
], PaginationQueryDto.prototype, "sortBy", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, swagger_1.ApiPropertyOptional)({ enum: ['asc', 'desc'], default: 'desc' }),
|
|
47
|
+
(0, class_validator_1.IsEnum)(['asc', 'desc']),
|
|
48
|
+
(0, class_validator_1.IsOptional)()
|
|
49
|
+
], PaginationQueryDto.prototype, "sortOrder", void 0);
|
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./pagination.interceptor"), exports);
|
|
18
17
|
__exportStar(require("./response.interceptor"), exports);
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
/** The page value from the client. It is used to evaluate the value of `offset` and `skip`. Defaults to 1. */
|
|
1
|
+
export interface PaginationParams {
|
|
3
2
|
page?: number;
|
|
4
|
-
/** The number of rows to take */
|
|
5
3
|
limit?: number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
skip?: number;
|
|
4
|
+
search?: string;
|
|
5
|
+
sortBy?: string;
|
|
6
|
+
sortOrder?: 'asc' | 'desc';
|
|
10
7
|
}
|
|
11
|
-
export interface PaginatedResult<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
export interface PaginatedResult<T> {
|
|
9
|
+
data: T[];
|
|
10
|
+
meta: {
|
|
11
|
+
total: number;
|
|
12
|
+
page: number;
|
|
13
|
+
lastPage: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
};
|
|
17
16
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PaginatedResult, PaginationParams } from '../interfaces';
|
|
2
|
+
export declare const getPaginationParams: (params: PaginationParams) => {
|
|
3
|
+
take: number;
|
|
4
|
+
skip: number;
|
|
5
|
+
orderBy: {
|
|
6
|
+
[x: string]: "asc" | "desc";
|
|
7
|
+
};
|
|
8
|
+
page: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const createPaginatedResponse: <T>(data: T[], total: number, page: number, limit: number) => PaginatedResult<T>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaginatedResponse = exports.getPaginationParams = void 0;
|
|
4
|
+
const getPaginationParams = (params) => {
|
|
5
|
+
const page = Math.max(1, Number(params.page) || 1);
|
|
6
|
+
const limit = Math.max(1, Math.min(100, Number(params.limit) || 10));
|
|
7
|
+
const offset = (page - 1) * limit;
|
|
8
|
+
const sortBy = params.sortBy || 'createdAt';
|
|
9
|
+
const sortOrder = params.sortOrder || 'desc';
|
|
10
|
+
return {
|
|
11
|
+
take: limit,
|
|
12
|
+
skip: offset,
|
|
13
|
+
orderBy: {
|
|
14
|
+
[sortBy]: sortOrder,
|
|
15
|
+
},
|
|
16
|
+
page,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.getPaginationParams = getPaginationParams;
|
|
20
|
+
const createPaginatedResponse = (data, total, page, limit) => {
|
|
21
|
+
return {
|
|
22
|
+
data,
|
|
23
|
+
meta: {
|
|
24
|
+
total,
|
|
25
|
+
page,
|
|
26
|
+
lastPage: Math.ceil(total / limit),
|
|
27
|
+
limit,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.createPaginatedResponse = createPaginatedResponse;
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
/**
|
|
4
|
-
* This is intended to intercept incoming requests for routes that intend to use pagination.
|
|
5
|
-
* It attaches a `Pagination` object named `pagination` to the request object.
|
|
6
|
-
*
|
|
7
|
-
* This new `pagination` property on the request body uses the `page` and `limit` properties on
|
|
8
|
-
* the request's query object if they exist. If no `page` or `limit` property is provided by
|
|
9
|
-
* the request client, this interceptor sets defaults.
|
|
10
|
-
*
|
|
11
|
-
* Defaults:
|
|
12
|
-
*
|
|
13
|
-
* `page` = 1 and;
|
|
14
|
-
*
|
|
15
|
-
* `limit` = 10
|
|
16
|
-
*/
|
|
17
|
-
export declare class PaginationInterceptor implements NestInterceptor {
|
|
18
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
19
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.PaginationInterceptor = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
/**
|
|
12
|
-
* This is intended to intercept incoming requests for routes that intend to use pagination.
|
|
13
|
-
* It attaches a `Pagination` object named `pagination` to the request object.
|
|
14
|
-
*
|
|
15
|
-
* This new `pagination` property on the request body uses the `page` and `limit` properties on
|
|
16
|
-
* the request's query object if they exist. If no `page` or `limit` property is provided by
|
|
17
|
-
* the request client, this interceptor sets defaults.
|
|
18
|
-
*
|
|
19
|
-
* Defaults:
|
|
20
|
-
*
|
|
21
|
-
* `page` = 1 and;
|
|
22
|
-
*
|
|
23
|
-
* `limit` = 10
|
|
24
|
-
*/
|
|
25
|
-
let PaginationInterceptor = class PaginationInterceptor {
|
|
26
|
-
intercept(context, next) {
|
|
27
|
-
const request = context.switchToHttp().getRequest();
|
|
28
|
-
let page = Number.parseInt(request.query.page);
|
|
29
|
-
let limit = Number.parseInt(request.query.limit);
|
|
30
|
-
// check validity and set defaults where necessary
|
|
31
|
-
page = page.toString() === Number.NaN.toString() ? 1 : page;
|
|
32
|
-
limit = limit.toString() === Number.NaN.toString() ? 10 : limit;
|
|
33
|
-
// set boundaries
|
|
34
|
-
page = page <= 0 ? 1 : page;
|
|
35
|
-
limit = limit > 100 ? 100 : limit;
|
|
36
|
-
const pagination = {
|
|
37
|
-
offset: page * limit - limit,
|
|
38
|
-
skip: (page - 1) * limit,
|
|
39
|
-
limit,
|
|
40
|
-
page,
|
|
41
|
-
};
|
|
42
|
-
request.pagination = pagination;
|
|
43
|
-
return next.handle();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.PaginationInterceptor = PaginationInterceptor;
|
|
47
|
-
exports.PaginationInterceptor = PaginationInterceptor = __decorate([
|
|
48
|
-
(0, common_1.Injectable)()
|
|
49
|
-
], PaginationInterceptor);
|