eh-commons 0.0.1-testing.21 → 0.0.1-testing.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/dist/models/wrappers/rest-wrapper.class.d.ts +11 -1
- package/dist/models/wrappers/rest-wrapper.class.js +57 -5
- package/dist/models/wrappers/rest-wrapper.class.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/models/wrappers/rest-wrapper.class.ts +70 -5
|
@@ -7,6 +7,10 @@ export declare class RESTSort {
|
|
|
7
7
|
property: string;
|
|
8
8
|
direction: SortDirection;
|
|
9
9
|
}
|
|
10
|
+
export interface IMongoPage {
|
|
11
|
+
skip: number;
|
|
12
|
+
limit: number;
|
|
13
|
+
}
|
|
10
14
|
export declare class RESTPaging {
|
|
11
15
|
page: number;
|
|
12
16
|
size: number;
|
|
@@ -14,6 +18,7 @@ export declare class RESTPaging {
|
|
|
14
18
|
skip: number;
|
|
15
19
|
limit: number;
|
|
16
20
|
};
|
|
21
|
+
static generate(page: number, size: number): IMongoPage;
|
|
17
22
|
}
|
|
18
23
|
export declare abstract class RESTRequestBody {
|
|
19
24
|
abstract data: any;
|
|
@@ -44,7 +49,7 @@ export declare class RESTError {
|
|
|
44
49
|
debug?: any;
|
|
45
50
|
validation?: any;
|
|
46
51
|
statusCode?: HttpStatus;
|
|
47
|
-
constructor(keyword: string, debug?: any);
|
|
52
|
+
constructor(keyword: string, debug?: any, statusCode?: HttpStatus);
|
|
48
53
|
static throw(keyword: string, statusCode?: HttpStatus, debug?: any): void;
|
|
49
54
|
static dataValidation(validation: any): RESTError;
|
|
50
55
|
}
|
|
@@ -56,3 +61,8 @@ export declare class RESTResponseBody<T> {
|
|
|
56
61
|
static success<T>(data: T, page?: RESTPage, sort?: RESTSort[]): RESTResponseBody<T>;
|
|
57
62
|
static fail(errors: RESTError[], statusCode?: number): RESTResponseBody<any>;
|
|
58
63
|
}
|
|
64
|
+
export declare class RESTQueryParams extends RESTPaging {
|
|
65
|
+
sort: string[];
|
|
66
|
+
getRESTSort(): RESTSort[];
|
|
67
|
+
extractSort(): {};
|
|
68
|
+
}
|
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RESTResponseBody = exports.RESTError = exports.RESTResult = exports.RESTPage = exports.RESTRequestBody = exports.RESTPaging = exports.RESTSort = exports.SortDirection = void 0;
|
|
12
|
+
exports.RESTQueryParams = exports.RESTResponseBody = exports.RESTError = exports.RESTResult = exports.RESTPage = exports.RESTRequestBody = exports.RESTPaging = exports.RESTSort = exports.SortDirection = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const class_transformer_1 = require("class-transformer");
|
|
15
15
|
const class_validator_1 = require("class-validator");
|
|
@@ -37,16 +37,25 @@ class RESTPaging {
|
|
|
37
37
|
const skip = (this.page - 1) * this.size;
|
|
38
38
|
return { skip, limit: this.size };
|
|
39
39
|
}
|
|
40
|
+
static generate(page, size) {
|
|
41
|
+
const skip = (page - 1) * size;
|
|
42
|
+
return { skip, limit: size };
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
exports.RESTPaging = RESTPaging;
|
|
42
46
|
__decorate([
|
|
43
47
|
(0, class_validator_1.IsNotEmpty)(),
|
|
44
|
-
(0, class_validator_1.
|
|
48
|
+
(0, class_validator_1.IsInt)(),
|
|
49
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
50
|
+
(0, class_validator_1.Min)(1),
|
|
45
51
|
__metadata("design:type", Number)
|
|
46
52
|
], RESTPaging.prototype, "page", void 0);
|
|
47
53
|
__decorate([
|
|
48
54
|
(0, class_validator_1.IsNotEmpty)(),
|
|
49
|
-
(0, class_validator_1.
|
|
55
|
+
(0, class_validator_1.IsInt)(),
|
|
56
|
+
(0, class_transformer_1.Type)(() => Number),
|
|
57
|
+
(0, class_validator_1.Min)(1),
|
|
58
|
+
(0, class_validator_1.Max)(100),
|
|
50
59
|
__metadata("design:type", Number)
|
|
51
60
|
], RESTPaging.prototype, "size", void 0);
|
|
52
61
|
class RESTRequestBody {
|
|
@@ -119,9 +128,10 @@ class RESTResult {
|
|
|
119
128
|
}
|
|
120
129
|
exports.RESTResult = RESTResult;
|
|
121
130
|
class RESTError {
|
|
122
|
-
constructor(keyword, debug) {
|
|
131
|
+
constructor(keyword, debug, statusCode) {
|
|
123
132
|
this.keyword = keyword;
|
|
124
133
|
this.debug = debug;
|
|
134
|
+
this.statusCode = statusCode;
|
|
125
135
|
}
|
|
126
136
|
static throw(keyword, statusCode, debug) {
|
|
127
137
|
const error = new RESTError(keyword, debug);
|
|
@@ -129,7 +139,7 @@ class RESTError {
|
|
|
129
139
|
throw error;
|
|
130
140
|
}
|
|
131
141
|
static dataValidation(validation) {
|
|
132
|
-
const error = new RESTError('body_validation_error', null);
|
|
142
|
+
const error = new RESTError('body_validation_error', null, 422);
|
|
133
143
|
error.validation = validation;
|
|
134
144
|
return error;
|
|
135
145
|
}
|
|
@@ -159,4 +169,46 @@ class RESTResponseBody {
|
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
exports.RESTResponseBody = RESTResponseBody;
|
|
172
|
+
class RESTQueryParams extends RESTPaging {
|
|
173
|
+
getRESTSort() {
|
|
174
|
+
const result = [];
|
|
175
|
+
const items = [];
|
|
176
|
+
if (this.sort) {
|
|
177
|
+
if (this.sort instanceof Array) {
|
|
178
|
+
items.push(...this.sort);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
items.push(this.sort);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (let item of items) {
|
|
185
|
+
const pair = item.split(':');
|
|
186
|
+
if (pair.length != 2) {
|
|
187
|
+
throw new RESTError('invalid_sorting_pair', pair, 422);
|
|
188
|
+
}
|
|
189
|
+
if (['asc', 'desc'].indexOf(pair[1]) === -1) {
|
|
190
|
+
throw new RESTError('invalid_sorting_direction', pair[1], 422);
|
|
191
|
+
}
|
|
192
|
+
result.push({
|
|
193
|
+
property: pair[0],
|
|
194
|
+
direction: pair[1] === 'asc' ? 1 : -1,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
extractSort() {
|
|
200
|
+
const sorts = this.getRESTSort();
|
|
201
|
+
const result = {};
|
|
202
|
+
for (let item of sorts) {
|
|
203
|
+
result[item.property] = item.direction;
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.RESTQueryParams = RESTQueryParams;
|
|
209
|
+
__decorate([
|
|
210
|
+
(0, class_validator_1.IsOptional)(),
|
|
211
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
212
|
+
__metadata("design:type", Array)
|
|
213
|
+
], RESTQueryParams.prototype, "sort", void 0);
|
|
162
214
|
//# sourceMappingURL=rest-wrapper.class.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-wrapper.class.js","sourceRoot":"","sources":["../../../src/models/wrappers/rest-wrapper.class.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"rest-wrapper.class.js","sourceRoot":"","sources":["../../../src/models/wrappers/rest-wrapper.class.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAyC;AACzC,qDAA+H;AAE/H,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+CAAO,CAAA;IACP,kDAAS,CAAA;AACX,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,MAAa,QAAQ;CASpB;AATD,4BASC;AANC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;0CACM;AAKj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