my-q-format-response-aws-lambda 1.0.46 → 1.0.48
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/index.js +53 -43
- package/index.ts +191 -201
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,11 +4,11 @@ exports.controlResponseNull = exports.normaliseMongoPaginate = exports.normalise
|
|
|
4
4
|
class StatusResult {
|
|
5
5
|
}
|
|
6
6
|
exports.StatusResult = StatusResult;
|
|
7
|
-
StatusResult.ok =
|
|
8
|
-
StatusResult.error =
|
|
9
|
-
StatusResult.notFound =
|
|
10
|
-
StatusResult.unauthorized =
|
|
11
|
-
StatusResult.needRedirect =
|
|
7
|
+
StatusResult.ok = 'Ok';
|
|
8
|
+
StatusResult.error = 'Error';
|
|
9
|
+
StatusResult.notFound = 'NotFound';
|
|
10
|
+
StatusResult.unauthorized = 'Unauthorized';
|
|
11
|
+
StatusResult.needRedirect = 'NeedRedirect';
|
|
12
12
|
class StatusCode {
|
|
13
13
|
}
|
|
14
14
|
exports.StatusCode = StatusCode;
|
|
@@ -64,10 +64,11 @@ StatusCode.BadGateway = 502;
|
|
|
64
64
|
class ResponseBodyVO {
|
|
65
65
|
constructor() {
|
|
66
66
|
this.statusResult = StatusResult.ok;
|
|
67
|
-
this.message =
|
|
67
|
+
this.message = '';
|
|
68
68
|
this.data = null;
|
|
69
69
|
this.count = null;
|
|
70
70
|
this.error = null;
|
|
71
|
+
this.info = null;
|
|
71
72
|
this.redirectTo = undefined;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -75,18 +76,19 @@ exports.ResponseBodyVO = ResponseBodyVO;
|
|
|
75
76
|
class ResponseVO {
|
|
76
77
|
constructor() {
|
|
77
78
|
this.statusCode = StatusCode.OK;
|
|
78
|
-
this.body =
|
|
79
|
+
this.body = '';
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
exports.ResponseVO = ResponseVO;
|
|
82
83
|
class Result {
|
|
83
|
-
constructor({ statusCode = StatusCode.OK, statusResult = StatusResult.ok, message, data = null, count = null, error = null, redirectTo = undefined, bodyWrap = true, }) {
|
|
84
|
+
constructor({ statusCode = StatusCode.OK, statusResult = StatusResult.ok, message, data = null, count = null, error = null, info = null, redirectTo = undefined, bodyWrap = true, }) {
|
|
84
85
|
this.statusCode = statusCode;
|
|
85
86
|
this.statusResult = statusResult;
|
|
86
|
-
this.message = !message ?
|
|
87
|
+
this.message = !message ? '' : message;
|
|
87
88
|
this.count = count;
|
|
88
89
|
this.data = data;
|
|
89
90
|
this.error = error;
|
|
91
|
+
this.info = info;
|
|
90
92
|
this.redirectTo = redirectTo;
|
|
91
93
|
this.bodyWrap = bodyWrap;
|
|
92
94
|
}
|
|
@@ -95,17 +97,14 @@ class Result {
|
|
|
95
97
|
* If use to AWS Appsync need response value without body wrap
|
|
96
98
|
*/
|
|
97
99
|
bodyToString() {
|
|
98
|
-
let _err = this.error && this.error.message
|
|
99
|
-
? this.error.message
|
|
100
|
-
: !this.error
|
|
101
|
-
? null
|
|
102
|
-
: JSON.stringify(this.error);
|
|
100
|
+
let _err = this.error && this.error.message ? this.error.message : !this.error ? null : JSON.stringify(this.error);
|
|
103
101
|
const valueBody = {
|
|
104
102
|
statusResult: this.statusResult,
|
|
105
103
|
message: this.message,
|
|
106
104
|
data: this.data,
|
|
107
105
|
count: this.count,
|
|
108
106
|
error: _err,
|
|
107
|
+
info: this.info,
|
|
109
108
|
};
|
|
110
109
|
if (this.redirectTo)
|
|
111
110
|
valueBody.redirectTo = this.redirectTo;
|
|
@@ -124,7 +123,7 @@ class CreateResponse {
|
|
|
124
123
|
* @param message
|
|
125
124
|
* @param bodyWrap
|
|
126
125
|
*/
|
|
127
|
-
static success({ data = null, count = null, message =
|
|
126
|
+
static success({ data = null, count = null, message = 'success', bodyWrap = true, info = null, }) {
|
|
128
127
|
const result = new Result({
|
|
129
128
|
statusCode: StatusCode.OK,
|
|
130
129
|
statusResult: StatusResult.ok,
|
|
@@ -132,6 +131,7 @@ class CreateResponse {
|
|
|
132
131
|
data,
|
|
133
132
|
count,
|
|
134
133
|
bodyWrap,
|
|
134
|
+
info,
|
|
135
135
|
});
|
|
136
136
|
return result.bodyToString();
|
|
137
137
|
}
|
|
@@ -141,7 +141,7 @@ class CreateResponse {
|
|
|
141
141
|
* @param message
|
|
142
142
|
* @param bodyWrap
|
|
143
143
|
*/
|
|
144
|
-
static created({ data, message =
|
|
144
|
+
static created({ data, message = 'created', bodyWrap = true }) {
|
|
145
145
|
const result = new Result({
|
|
146
146
|
statusCode: StatusCode.Created,
|
|
147
147
|
statusResult: StatusResult.ok,
|
|
@@ -157,13 +157,14 @@ class CreateResponse {
|
|
|
157
157
|
* @param message
|
|
158
158
|
* @param bodyWrap
|
|
159
159
|
*/
|
|
160
|
-
static updated({ data, message =
|
|
160
|
+
static updated({ data, message = 'updated', bodyWrap = true, info = null }) {
|
|
161
161
|
const result = new Result({
|
|
162
162
|
statusCode: StatusCode.OK,
|
|
163
163
|
statusResult: StatusResult.ok,
|
|
164
164
|
message,
|
|
165
165
|
data,
|
|
166
166
|
bodyWrap,
|
|
167
|
+
info,
|
|
167
168
|
});
|
|
168
169
|
return result.bodyToString();
|
|
169
170
|
}
|
|
@@ -173,13 +174,14 @@ class CreateResponse {
|
|
|
173
174
|
* @param message
|
|
174
175
|
* @param bodyWrap
|
|
175
176
|
*/
|
|
176
|
-
static updateOrCreate({ data, message =
|
|
177
|
+
static updateOrCreate({ data, message = 'update_or_create', bodyWrap = true, info = null, }) {
|
|
177
178
|
const result = new Result({
|
|
178
179
|
statusCode: StatusCode.OK,
|
|
179
180
|
statusResult: StatusResult.ok,
|
|
180
181
|
message,
|
|
181
182
|
data,
|
|
182
183
|
bodyWrap,
|
|
184
|
+
info,
|
|
183
185
|
});
|
|
184
186
|
return result.bodyToString();
|
|
185
187
|
}
|
|
@@ -189,7 +191,7 @@ class CreateResponse {
|
|
|
189
191
|
* @param message
|
|
190
192
|
* @param bodyWrap
|
|
191
193
|
*/
|
|
192
|
-
static notFound({ error = null, message =
|
|
194
|
+
static notFound({ error = null, message = '', bodyWrap = true }) {
|
|
193
195
|
const result = new Result({
|
|
194
196
|
statusCode: StatusCode.NotFound,
|
|
195
197
|
statusResult: StatusResult.notFound,
|
|
@@ -207,7 +209,7 @@ class CreateResponse {
|
|
|
207
209
|
* @param message
|
|
208
210
|
* @param bodyWrap
|
|
209
211
|
*/
|
|
210
|
-
static error({ error = null, statusCode = StatusCode.BadRequest, message =
|
|
212
|
+
static error({ error = null, statusCode = StatusCode.BadRequest, message = 'Error', bodyWrap = true, }) {
|
|
211
213
|
const result = new Result({
|
|
212
214
|
statusCode,
|
|
213
215
|
statusResult: StatusResult.error,
|
|
@@ -225,7 +227,7 @@ class CreateResponse {
|
|
|
225
227
|
* @param message
|
|
226
228
|
* @param bodyWrap
|
|
227
229
|
*/
|
|
228
|
-
static unauthorized({ error = null, statusCode = StatusCode.Unauthorized, message =
|
|
230
|
+
static unauthorized({ error = null, statusCode = StatusCode.Unauthorized, message = 'Unauthorized', bodyWrap = true, }) {
|
|
229
231
|
const result = new Result({
|
|
230
232
|
statusCode,
|
|
231
233
|
statusResult: StatusResult.unauthorized,
|
|
@@ -243,7 +245,7 @@ class CreateResponse {
|
|
|
243
245
|
* @param message
|
|
244
246
|
* @param bodyWrap
|
|
245
247
|
*/
|
|
246
|
-
static redirect({ statusCode = StatusCode.MovedTemporarily, message =
|
|
248
|
+
static redirect({ statusCode = StatusCode.MovedTemporarily, message = '', bodyWrap = true, redirectTo = '', }) {
|
|
247
249
|
const result = new Result({
|
|
248
250
|
statusCode,
|
|
249
251
|
statusResult: StatusResult.needRedirect,
|
|
@@ -265,7 +267,7 @@ class CreateResponse {
|
|
|
265
267
|
* @param count
|
|
266
268
|
* @param bodyWrap
|
|
267
269
|
*/
|
|
268
|
-
static custom({ statusCode = StatusCode.OK, statusResult = StatusResult.ok, message =
|
|
270
|
+
static custom({ statusCode = StatusCode.OK, statusResult = StatusResult.ok, message = '', error = null, data = null, count = null, bodyWrap = true, info = null, }) {
|
|
269
271
|
const result = new Result({
|
|
270
272
|
statusCode,
|
|
271
273
|
statusResult,
|
|
@@ -274,12 +276,13 @@ class CreateResponse {
|
|
|
274
276
|
data,
|
|
275
277
|
count,
|
|
276
278
|
bodyWrap,
|
|
279
|
+
info
|
|
277
280
|
});
|
|
278
281
|
return result.bodyToString();
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
284
|
exports.CreateResponse = CreateResponse;
|
|
282
|
-
const messagesREST = (prefix, suffix =
|
|
285
|
+
const messagesREST = (prefix, suffix = '') => {
|
|
283
286
|
return {
|
|
284
287
|
TOTAL: `${prefix}_TOTAL${suffix}`,
|
|
285
288
|
NOT_FOUND: `${prefix}_NOT_FOUND${suffix}`,
|
|
@@ -362,10 +365,19 @@ const messagesREST = (prefix, suffix = "") => {
|
|
|
362
365
|
USER_AUTHENTICATION_REFRESH: `${prefix}_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
363
366
|
NOT_USER_AUTHENTICATION_REFRESH: `${prefix}_NOT_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
364
367
|
ERROR_USER_AUTHENTICATION_REFRESH: `${prefix}_ERROR_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
368
|
+
MARK_ACTION: `${prefix}_MARK_ACTION${suffix}`,
|
|
369
|
+
NOT_MARK_ACTION: `${prefix}_NOT_MARK_ACTION${suffix}`,
|
|
370
|
+
ERROR_MARK_ACTION: `${prefix}_ERROR_MARK_ACTION${suffix}`,
|
|
371
|
+
MARK_FOR_DELETE: `${prefix}_MARK_FOR_DELETE${suffix}`,
|
|
372
|
+
NOT_MARK_FOR_DELETE: `${prefix}_NOT_MARK_FOR_DELETE${suffix}`,
|
|
373
|
+
ERROR_MARK_FOR_DELETE: `${prefix}_ERROR_MARK_FOR_DELETE${suffix}`,
|
|
374
|
+
MARK_SYSTEM: `${prefix}_MARK_SYSTEM${suffix}`,
|
|
375
|
+
NOT_MARK_SYSTEM: `${prefix}_NOT_MARK_SYSTEM${suffix}`,
|
|
376
|
+
ERROR_MARK_SYSTEM: `${prefix}_ERROR_MARK_SYSTEM${suffix}`,
|
|
365
377
|
};
|
|
366
378
|
};
|
|
367
379
|
exports.messagesREST = messagesREST;
|
|
368
|
-
exports.optionsPaginationParams = [
|
|
380
|
+
exports.optionsPaginationParams = ['limit', 'skip', 'count'];
|
|
369
381
|
/**
|
|
370
382
|
* Normalise filter for mongoose
|
|
371
383
|
* @param regexFields
|
|
@@ -374,19 +386,17 @@ exports.optionsPaginationParams = ["limit", "skip", "count"];
|
|
|
374
386
|
*/
|
|
375
387
|
const normaliseMongoFilter = (filter, regexFields, excludeFields) => {
|
|
376
388
|
const _filter = {};
|
|
377
|
-
const excludeParams = excludeFields && Array.isArray(excludeFields) && excludeFields.length > 0
|
|
378
|
-
? excludeFields
|
|
379
|
-
: exports.optionsPaginationParams;
|
|
389
|
+
const excludeParams = excludeFields && Array.isArray(excludeFields) && excludeFields.length > 0 ? excludeFields : exports.optionsPaginationParams;
|
|
380
390
|
Object.keys(filter).forEach((f) => {
|
|
381
391
|
const v = filter[f];
|
|
382
392
|
if (!(v === null ||
|
|
383
|
-
(typeof v ===
|
|
393
|
+
(typeof v === 'number' && isNaN(v)) ||
|
|
384
394
|
v === Infinity ||
|
|
385
395
|
v === undefined ||
|
|
386
396
|
excludeParams.includes(f))) {
|
|
387
397
|
_filter[f] = filter[f];
|
|
388
398
|
if (regexFields.includes(f))
|
|
389
|
-
_filter[f] = { $regex: new RegExp(_filter[f],
|
|
399
|
+
_filter[f] = { $regex: new RegExp(_filter[f], 'gi') };
|
|
390
400
|
}
|
|
391
401
|
});
|
|
392
402
|
return _filter;
|
|
@@ -409,42 +419,42 @@ exports.normaliseMongoPaginate = normaliseMongoPaginate;
|
|
|
409
419
|
const controlResponseNull = (data, okResultOf, prefix, bodyWrap = true) => {
|
|
410
420
|
let result;
|
|
411
421
|
if (data) {
|
|
412
|
-
if (okResultOf ===
|
|
422
|
+
if (okResultOf === 'create') {
|
|
413
423
|
result = CreateResponse.created({
|
|
414
424
|
data,
|
|
415
425
|
message: (0, exports.messagesREST)(prefix).CREATE,
|
|
416
426
|
bodyWrap,
|
|
417
427
|
});
|
|
418
428
|
}
|
|
419
|
-
if (okResultOf ===
|
|
429
|
+
if (okResultOf === 'update') {
|
|
420
430
|
result = CreateResponse.updated({
|
|
421
431
|
data,
|
|
422
432
|
message: (0, exports.messagesREST)(prefix).UPDATE,
|
|
423
433
|
bodyWrap,
|
|
424
434
|
});
|
|
425
435
|
}
|
|
426
|
-
if (okResultOf ===
|
|
436
|
+
if (okResultOf === 'update_or_create') {
|
|
427
437
|
result = CreateResponse.updateOrCreate({
|
|
428
438
|
data,
|
|
429
439
|
message: (0, exports.messagesREST)(prefix).UPDATE_OR_CREATE,
|
|
430
440
|
bodyWrap,
|
|
431
441
|
});
|
|
432
442
|
}
|
|
433
|
-
if (okResultOf ===
|
|
443
|
+
if (okResultOf === 'update_many') {
|
|
434
444
|
result = CreateResponse.updated({
|
|
435
445
|
data,
|
|
436
446
|
message: (0, exports.messagesREST)(prefix).UPDATE_MANY,
|
|
437
447
|
bodyWrap,
|
|
438
448
|
});
|
|
439
449
|
}
|
|
440
|
-
if (okResultOf ===
|
|
450
|
+
if (okResultOf === 'increment') {
|
|
441
451
|
result = CreateResponse.updated({
|
|
442
452
|
data,
|
|
443
453
|
message: (0, exports.messagesREST)(prefix).INCREMENT,
|
|
444
454
|
bodyWrap,
|
|
445
455
|
});
|
|
446
456
|
}
|
|
447
|
-
if (okResultOf ===
|
|
457
|
+
if (okResultOf === 'decrement') {
|
|
448
458
|
result = CreateResponse.updated({
|
|
449
459
|
data,
|
|
450
460
|
message: (0, exports.messagesREST)(prefix).DECREMENT,
|
|
@@ -453,18 +463,18 @@ const controlResponseNull = (data, okResultOf, prefix, bodyWrap = true) => {
|
|
|
453
463
|
}
|
|
454
464
|
}
|
|
455
465
|
else {
|
|
456
|
-
let messageErr =
|
|
457
|
-
if (okResultOf ===
|
|
466
|
+
let messageErr = '';
|
|
467
|
+
if (okResultOf === 'create')
|
|
458
468
|
messageErr = (0, exports.messagesREST)(prefix).NOT_CREATE;
|
|
459
|
-
if (okResultOf ===
|
|
469
|
+
if (okResultOf === 'update')
|
|
460
470
|
messageErr = (0, exports.messagesREST)(prefix).NOT_UPDATE;
|
|
461
|
-
if (okResultOf ===
|
|
471
|
+
if (okResultOf === 'update_or_create')
|
|
462
472
|
messageErr = (0, exports.messagesREST)(prefix).NOT_UPDATE_OR_CREATE;
|
|
463
|
-
if (okResultOf ===
|
|
473
|
+
if (okResultOf === 'update_many')
|
|
464
474
|
messageErr = (0, exports.messagesREST)(prefix).NOT_UPDATE_MANY;
|
|
465
|
-
if (okResultOf ===
|
|
475
|
+
if (okResultOf === 'increment')
|
|
466
476
|
messageErr = (0, exports.messagesREST)(prefix).NOT_INCREMENT;
|
|
467
|
-
if (okResultOf ===
|
|
477
|
+
if (okResultOf === 'decrement')
|
|
468
478
|
messageErr = (0, exports.messagesREST)(prefix).NOT_DECREMENT;
|
|
469
479
|
result = CreateResponse.error({
|
|
470
480
|
data: data,
|
package/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export class StatusResult {
|
|
2
|
-
static ok =
|
|
3
|
-
static error =
|
|
4
|
-
static notFound =
|
|
5
|
-
static unauthorized =
|
|
6
|
-
static needRedirect =
|
|
2
|
+
static ok = 'Ok'
|
|
3
|
+
static error = 'Error'
|
|
4
|
+
static notFound = 'NotFound'
|
|
5
|
+
static unauthorized = 'Unauthorized'
|
|
6
|
+
static needRedirect = 'NeedRedirect'
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export class StatusCode {
|
|
@@ -11,29 +11,29 @@ export class StatusCode {
|
|
|
11
11
|
// static Continue = 100;
|
|
12
12
|
// static Processing = 102;
|
|
13
13
|
|
|
14
|
-
static OK = 200
|
|
15
|
-
static Created = 201
|
|
16
|
-
static Accepted = 202
|
|
17
|
-
static NonAuthoritativeInformation = 203
|
|
18
|
-
static NoContent = 204
|
|
14
|
+
static OK = 200
|
|
15
|
+
static Created = 201
|
|
16
|
+
static Accepted = 202
|
|
17
|
+
static NonAuthoritativeInformation = 203
|
|
18
|
+
static NoContent = 204
|
|
19
19
|
// static ResetContent = 205;
|
|
20
20
|
// static PartialContent = 206;
|
|
21
21
|
// static MultiStatus = 207;
|
|
22
22
|
|
|
23
|
-
static MultipleChoices = 300
|
|
24
|
-
static MovedPermanently = 301
|
|
25
|
-
static MovedTemporarily = 302
|
|
26
|
-
static SeeOther = 303
|
|
23
|
+
static MultipleChoices = 300
|
|
24
|
+
static MovedPermanently = 301
|
|
25
|
+
static MovedTemporarily = 302
|
|
26
|
+
static SeeOther = 303
|
|
27
27
|
// static UseProxy = 305;
|
|
28
28
|
// static NotModified = 304;
|
|
29
|
-
static TemporaryRedirect = 307
|
|
29
|
+
static TemporaryRedirect = 307
|
|
30
30
|
// static PermanentRedirect = 308;
|
|
31
31
|
|
|
32
|
-
static BadRequest = 400
|
|
33
|
-
static Unauthorized = 401
|
|
34
|
-
static PaymentRequired = 402
|
|
35
|
-
static NotFound = 404
|
|
36
|
-
static Forbidden = 403
|
|
32
|
+
static BadRequest = 400
|
|
33
|
+
static Unauthorized = 401
|
|
34
|
+
static PaymentRequired = 402
|
|
35
|
+
static NotFound = 404
|
|
36
|
+
static Forbidden = 403
|
|
37
37
|
// static MethodNotAllowed = 405;
|
|
38
38
|
// static ProxyAuthenticationRequired = 407;
|
|
39
39
|
// static NotAcceptable = 406;
|
|
@@ -57,9 +57,9 @@ export class StatusCode {
|
|
|
57
57
|
// static TooManyRequests = 429;
|
|
58
58
|
// static RequestHeaderFieldsTooLarge = 431;
|
|
59
59
|
|
|
60
|
-
static InternalServerError = 500
|
|
61
|
-
static NotImplemented = 501
|
|
62
|
-
static BadGateway = 502
|
|
60
|
+
static InternalServerError = 500
|
|
61
|
+
static NotImplemented = 501
|
|
62
|
+
static BadGateway = 502
|
|
63
63
|
// static ServiceUnavailable = 503;
|
|
64
64
|
// static GatewayTimeOut = 504;
|
|
65
65
|
// static HTTPVersionNotSupported = 505;
|
|
@@ -70,58 +70,63 @@ export class StatusCode {
|
|
|
70
70
|
// static NetworkAuthenticationRequire = 511;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
type TData = object | boolean | string | null
|
|
74
|
-
type TCount = number | null
|
|
75
|
-
type TError = any | null
|
|
76
|
-
type
|
|
73
|
+
type TData = object | boolean | string | null
|
|
74
|
+
type TCount = number | null
|
|
75
|
+
type TError = any | null
|
|
76
|
+
type TInfo = any | null
|
|
77
|
+
type TRedirectTo = string | undefined
|
|
77
78
|
|
|
78
79
|
interface TResultIn {
|
|
79
|
-
statusCode?: StatusCode
|
|
80
|
-
statusResult?: StatusResult
|
|
81
|
-
message?: string
|
|
82
|
-
data?: TData
|
|
83
|
-
count?: TCount
|
|
84
|
-
error?: TError
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
statusCode?: StatusCode
|
|
81
|
+
statusResult?: StatusResult
|
|
82
|
+
message?: string
|
|
83
|
+
data?: TData
|
|
84
|
+
count?: TCount
|
|
85
|
+
error?: TError
|
|
86
|
+
info?: TInfo
|
|
87
|
+
redirectTo?: TRedirectTo
|
|
88
|
+
bodyWrap: boolean
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
interface TFuncParams {
|
|
90
|
-
statusCode?: StatusCode
|
|
91
|
-
statusResult?: StatusResult
|
|
92
|
-
message?: string
|
|
93
|
-
error?: TError
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
statusCode?: StatusCode
|
|
93
|
+
statusResult?: StatusResult
|
|
94
|
+
message?: string
|
|
95
|
+
error?: TError
|
|
96
|
+
info?: TInfo
|
|
97
|
+
data?: TData
|
|
98
|
+
count?: TCount
|
|
99
|
+
redirectTo?: TRedirectTo
|
|
100
|
+
bodyWrap?: boolean
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
export class ResponseBodyVO {
|
|
101
|
-
statusResult: StatusResult = StatusResult.ok
|
|
102
|
-
message: string =
|
|
103
|
-
data: TData = null
|
|
104
|
-
count: TCount = null
|
|
105
|
-
error: TError = null
|
|
106
|
-
|
|
104
|
+
statusResult: StatusResult = StatusResult.ok
|
|
105
|
+
message: string = ''
|
|
106
|
+
data: TData = null
|
|
107
|
+
count: TCount = null
|
|
108
|
+
error: TError = null
|
|
109
|
+
info: TInfo = null
|
|
110
|
+
redirectTo?: TRedirectTo = undefined
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
export class ResponseVO {
|
|
110
|
-
statusCode: StatusCode = StatusCode.OK
|
|
111
|
-
body: string =
|
|
114
|
+
statusCode: StatusCode = StatusCode.OK
|
|
115
|
+
body: string = ''
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
export type ResponseVoAWS = ResponseVO | ResponseBodyVO
|
|
118
|
+
export type ResponseVoAWS = ResponseVO | ResponseBodyVO
|
|
115
119
|
|
|
116
120
|
class Result {
|
|
117
|
-
private statusCode: StatusCode
|
|
118
|
-
private statusResult: StatusResult
|
|
119
|
-
private message: string
|
|
120
|
-
private data: TData
|
|
121
|
-
private count: TCount
|
|
122
|
-
private error: any
|
|
123
|
-
private
|
|
124
|
-
private
|
|
121
|
+
private statusCode: StatusCode
|
|
122
|
+
private statusResult: StatusResult
|
|
123
|
+
private message: string
|
|
124
|
+
private data: TData
|
|
125
|
+
private count: TCount
|
|
126
|
+
private error: any
|
|
127
|
+
private info: any
|
|
128
|
+
private redirectTo: TRedirectTo
|
|
129
|
+
private bodyWrap: boolean
|
|
125
130
|
|
|
126
131
|
constructor({
|
|
127
132
|
statusCode = StatusCode.OK,
|
|
@@ -130,17 +135,19 @@ class Result {
|
|
|
130
135
|
data = null,
|
|
131
136
|
count = null,
|
|
132
137
|
error = null,
|
|
138
|
+
info = null,
|
|
133
139
|
redirectTo = undefined,
|
|
134
140
|
bodyWrap = true,
|
|
135
141
|
}: TResultIn) {
|
|
136
|
-
this.statusCode = statusCode
|
|
137
|
-
this.statusResult = statusResult
|
|
138
|
-
this.message = !message ?
|
|
139
|
-
this.count = count
|
|
140
|
-
this.data = data
|
|
141
|
-
this.error = error
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
142
|
+
this.statusCode = statusCode
|
|
143
|
+
this.statusResult = statusResult
|
|
144
|
+
this.message = !message ? '' : message
|
|
145
|
+
this.count = count
|
|
146
|
+
this.data = data
|
|
147
|
+
this.error = error
|
|
148
|
+
this.info = info
|
|
149
|
+
this.redirectTo = redirectTo
|
|
150
|
+
this.bodyWrap = bodyWrap
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
/**
|
|
@@ -148,12 +155,7 @@ class Result {
|
|
|
148
155
|
* If use to AWS Appsync need response value without body wrap
|
|
149
156
|
*/
|
|
150
157
|
bodyToString(): ResponseVoAWS {
|
|
151
|
-
let _err =
|
|
152
|
-
this.error && this.error.message
|
|
153
|
-
? this.error.message
|
|
154
|
-
: !this.error
|
|
155
|
-
? null
|
|
156
|
-
: JSON.stringify(this.error);
|
|
158
|
+
let _err = this.error && this.error.message ? this.error.message : !this.error ? null : JSON.stringify(this.error)
|
|
157
159
|
|
|
158
160
|
const valueBody: ResponseBodyVO = {
|
|
159
161
|
statusResult: this.statusResult,
|
|
@@ -161,14 +163,15 @@ class Result {
|
|
|
161
163
|
data: this.data,
|
|
162
164
|
count: this.count,
|
|
163
165
|
error: _err,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
info: this.info,
|
|
167
|
+
}
|
|
168
|
+
if (this.redirectTo) valueBody.redirectTo = this.redirectTo
|
|
166
169
|
const valueBodyWrap: ResponseVO = {
|
|
167
170
|
statusCode: this.statusCode,
|
|
168
171
|
body: JSON.stringify(valueBody),
|
|
169
|
-
}
|
|
172
|
+
}
|
|
170
173
|
|
|
171
|
-
return this.bodyWrap ? valueBodyWrap : valueBody
|
|
174
|
+
return this.bodyWrap ? valueBodyWrap : valueBody
|
|
172
175
|
}
|
|
173
176
|
}
|
|
174
177
|
|
|
@@ -183,8 +186,9 @@ export class CreateResponse {
|
|
|
183
186
|
static success({
|
|
184
187
|
data = null,
|
|
185
188
|
count = null,
|
|
186
|
-
message =
|
|
189
|
+
message = 'success',
|
|
187
190
|
bodyWrap = true,
|
|
191
|
+
info = null,
|
|
188
192
|
}: TFuncParams): ResponseVoAWS {
|
|
189
193
|
const result = new Result({
|
|
190
194
|
statusCode: StatusCode.OK,
|
|
@@ -193,8 +197,9 @@ export class CreateResponse {
|
|
|
193
197
|
data,
|
|
194
198
|
count,
|
|
195
199
|
bodyWrap,
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
info,
|
|
201
|
+
})
|
|
202
|
+
return result.bodyToString()
|
|
198
203
|
}
|
|
199
204
|
|
|
200
205
|
/**
|
|
@@ -203,19 +208,15 @@ export class CreateResponse {
|
|
|
203
208
|
* @param message
|
|
204
209
|
* @param bodyWrap
|
|
205
210
|
*/
|
|
206
|
-
static created({
|
|
207
|
-
data,
|
|
208
|
-
message = "created",
|
|
209
|
-
bodyWrap = true,
|
|
210
|
-
}: TFuncParams): ResponseVoAWS {
|
|
211
|
+
static created({ data, message = 'created', bodyWrap = true }: TFuncParams): ResponseVoAWS {
|
|
211
212
|
const result = new Result({
|
|
212
213
|
statusCode: StatusCode.Created,
|
|
213
214
|
statusResult: StatusResult.ok,
|
|
214
215
|
message,
|
|
215
216
|
data,
|
|
216
217
|
bodyWrap,
|
|
217
|
-
})
|
|
218
|
-
return result.bodyToString()
|
|
218
|
+
})
|
|
219
|
+
return result.bodyToString()
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
/**
|
|
@@ -224,19 +225,16 @@ export class CreateResponse {
|
|
|
224
225
|
* @param message
|
|
225
226
|
* @param bodyWrap
|
|
226
227
|
*/
|
|
227
|
-
static updated({
|
|
228
|
-
data,
|
|
229
|
-
message = "updated",
|
|
230
|
-
bodyWrap = true,
|
|
231
|
-
}: TFuncParams): ResponseVoAWS {
|
|
228
|
+
static updated({ data, message = 'updated', bodyWrap = true, info = null }: TFuncParams): ResponseVoAWS {
|
|
232
229
|
const result = new Result({
|
|
233
230
|
statusCode: StatusCode.OK,
|
|
234
231
|
statusResult: StatusResult.ok,
|
|
235
232
|
message,
|
|
236
233
|
data,
|
|
237
234
|
bodyWrap,
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
info,
|
|
236
|
+
})
|
|
237
|
+
return result.bodyToString()
|
|
240
238
|
}
|
|
241
239
|
|
|
242
240
|
/**
|
|
@@ -247,8 +245,9 @@ export class CreateResponse {
|
|
|
247
245
|
*/
|
|
248
246
|
static updateOrCreate({
|
|
249
247
|
data,
|
|
250
|
-
message =
|
|
248
|
+
message = 'update_or_create',
|
|
251
249
|
bodyWrap = true,
|
|
250
|
+
info = null,
|
|
252
251
|
}: TFuncParams): ResponseVoAWS {
|
|
253
252
|
const result = new Result({
|
|
254
253
|
statusCode: StatusCode.OK,
|
|
@@ -256,8 +255,9 @@ export class CreateResponse {
|
|
|
256
255
|
message,
|
|
257
256
|
data,
|
|
258
257
|
bodyWrap,
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
info,
|
|
259
|
+
})
|
|
260
|
+
return result.bodyToString()
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -266,11 +266,7 @@ export class CreateResponse {
|
|
|
266
266
|
* @param message
|
|
267
267
|
* @param bodyWrap
|
|
268
268
|
*/
|
|
269
|
-
static notFound({
|
|
270
|
-
error = null,
|
|
271
|
-
message = "",
|
|
272
|
-
bodyWrap = true,
|
|
273
|
-
}: TFuncParams): ResponseVoAWS {
|
|
269
|
+
static notFound({ error = null, message = '', bodyWrap = true }: TFuncParams): ResponseVoAWS {
|
|
274
270
|
const result = new Result({
|
|
275
271
|
statusCode: StatusCode.NotFound,
|
|
276
272
|
statusResult: StatusResult.notFound,
|
|
@@ -278,8 +274,8 @@ export class CreateResponse {
|
|
|
278
274
|
data: null,
|
|
279
275
|
error,
|
|
280
276
|
bodyWrap,
|
|
281
|
-
})
|
|
282
|
-
return result.bodyToString()
|
|
277
|
+
})
|
|
278
|
+
return result.bodyToString()
|
|
283
279
|
}
|
|
284
280
|
|
|
285
281
|
/**
|
|
@@ -292,7 +288,7 @@ export class CreateResponse {
|
|
|
292
288
|
static error({
|
|
293
289
|
error = null,
|
|
294
290
|
statusCode = StatusCode.BadRequest,
|
|
295
|
-
message =
|
|
291
|
+
message = 'Error',
|
|
296
292
|
bodyWrap = true,
|
|
297
293
|
}: TFuncParams): ResponseVoAWS {
|
|
298
294
|
const result = new Result({
|
|
@@ -302,8 +298,8 @@ export class CreateResponse {
|
|
|
302
298
|
error,
|
|
303
299
|
message,
|
|
304
300
|
bodyWrap,
|
|
305
|
-
})
|
|
306
|
-
return result.bodyToString()
|
|
301
|
+
})
|
|
302
|
+
return result.bodyToString()
|
|
307
303
|
}
|
|
308
304
|
|
|
309
305
|
/**
|
|
@@ -316,7 +312,7 @@ export class CreateResponse {
|
|
|
316
312
|
static unauthorized({
|
|
317
313
|
error = null,
|
|
318
314
|
statusCode = StatusCode.Unauthorized,
|
|
319
|
-
message =
|
|
315
|
+
message = 'Unauthorized',
|
|
320
316
|
bodyWrap = true,
|
|
321
317
|
}: TFuncParams): ResponseVoAWS {
|
|
322
318
|
const result = new Result({
|
|
@@ -326,8 +322,8 @@ export class CreateResponse {
|
|
|
326
322
|
error,
|
|
327
323
|
message,
|
|
328
324
|
bodyWrap,
|
|
329
|
-
})
|
|
330
|
-
return result.bodyToString()
|
|
325
|
+
})
|
|
326
|
+
return result.bodyToString()
|
|
331
327
|
}
|
|
332
328
|
|
|
333
329
|
/**
|
|
@@ -339,9 +335,9 @@ export class CreateResponse {
|
|
|
339
335
|
*/
|
|
340
336
|
static redirect({
|
|
341
337
|
statusCode = StatusCode.MovedTemporarily,
|
|
342
|
-
message =
|
|
338
|
+
message = '',
|
|
343
339
|
bodyWrap = true,
|
|
344
|
-
redirectTo =
|
|
340
|
+
redirectTo = '',
|
|
345
341
|
}: TFuncParams): ResponseVoAWS {
|
|
346
342
|
const result = new Result({
|
|
347
343
|
statusCode,
|
|
@@ -351,8 +347,8 @@ export class CreateResponse {
|
|
|
351
347
|
message,
|
|
352
348
|
redirectTo,
|
|
353
349
|
bodyWrap,
|
|
354
|
-
})
|
|
355
|
-
return result.bodyToString()
|
|
350
|
+
})
|
|
351
|
+
return result.bodyToString()
|
|
356
352
|
}
|
|
357
353
|
|
|
358
354
|
/**
|
|
@@ -368,11 +364,12 @@ export class CreateResponse {
|
|
|
368
364
|
static custom({
|
|
369
365
|
statusCode = StatusCode.OK,
|
|
370
366
|
statusResult = StatusResult.ok,
|
|
371
|
-
message =
|
|
367
|
+
message = '',
|
|
372
368
|
error = null,
|
|
373
369
|
data = null,
|
|
374
370
|
count = null,
|
|
375
371
|
bodyWrap = true,
|
|
372
|
+
info = null,
|
|
376
373
|
}: TFuncParams): ResponseVoAWS {
|
|
377
374
|
const result = new Result({
|
|
378
375
|
statusCode,
|
|
@@ -382,12 +379,13 @@ export class CreateResponse {
|
|
|
382
379
|
data,
|
|
383
380
|
count,
|
|
384
381
|
bodyWrap,
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
info
|
|
383
|
+
})
|
|
384
|
+
return result.bodyToString()
|
|
387
385
|
}
|
|
388
386
|
}
|
|
389
387
|
|
|
390
|
-
export const messagesREST = (prefix: string, suffix: string =
|
|
388
|
+
export const messagesREST = (prefix: string, suffix: string = ''): Record<string, string> => {
|
|
391
389
|
return {
|
|
392
390
|
TOTAL: `${prefix}_TOTAL${suffix}`,
|
|
393
391
|
|
|
@@ -498,12 +496,24 @@ export const messagesREST = (prefix: string, suffix: string = ""): Record<string
|
|
|
498
496
|
USER_AUTHENTICATION_REFRESH: `${prefix}_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
499
497
|
NOT_USER_AUTHENTICATION_REFRESH: `${prefix}_NOT_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
500
498
|
ERROR_USER_AUTHENTICATION_REFRESH: `${prefix}_ERROR_USER_AUTHENTICATION_REFRESH${suffix}`,
|
|
501
|
-
};
|
|
502
|
-
};
|
|
503
499
|
|
|
504
|
-
|
|
500
|
+
MARK_ACTION: `${prefix}_MARK_ACTION${suffix}`,
|
|
501
|
+
NOT_MARK_ACTION: `${prefix}_NOT_MARK_ACTION${suffix}`,
|
|
502
|
+
ERROR_MARK_ACTION: `${prefix}_ERROR_MARK_ACTION${suffix}`,
|
|
503
|
+
|
|
504
|
+
MARK_FOR_DELETE: `${prefix}_MARK_FOR_DELETE${suffix}`,
|
|
505
|
+
NOT_MARK_FOR_DELETE: `${prefix}_NOT_MARK_FOR_DELETE${suffix}`,
|
|
506
|
+
ERROR_MARK_FOR_DELETE: `${prefix}_ERROR_MARK_FOR_DELETE${suffix}`,
|
|
505
507
|
|
|
506
|
-
|
|
508
|
+
MARK_SYSTEM: `${prefix}_MARK_SYSTEM${suffix}`,
|
|
509
|
+
NOT_MARK_SYSTEM: `${prefix}_NOT_MARK_SYSTEM${suffix}`,
|
|
510
|
+
ERROR_MARK_SYSTEM: `${prefix}_ERROR_MARK_SYSTEM${suffix}`,
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export const optionsPaginationParams = ['limit', 'skip', 'count']
|
|
515
|
+
|
|
516
|
+
export type TMongoFilterNormalise = { [fieldName: string]: any }
|
|
507
517
|
|
|
508
518
|
/**
|
|
509
519
|
* Normalise filter for mongoose
|
|
@@ -516,161 +526,141 @@ export const normaliseMongoFilter = (
|
|
|
516
526
|
regexFields: string[],
|
|
517
527
|
excludeFields?: string[]
|
|
518
528
|
) => {
|
|
519
|
-
const _filter: TMongoFilterNormalise = {}
|
|
529
|
+
const _filter: TMongoFilterNormalise = {}
|
|
520
530
|
const excludeParams =
|
|
521
|
-
excludeFields && Array.isArray(excludeFields) && excludeFields.length > 0
|
|
522
|
-
? excludeFields
|
|
523
|
-
: optionsPaginationParams;
|
|
531
|
+
excludeFields && Array.isArray(excludeFields) && excludeFields.length > 0 ? excludeFields : optionsPaginationParams
|
|
524
532
|
|
|
525
533
|
Object.keys(filter).forEach((f) => {
|
|
526
|
-
const v = filter[f]
|
|
534
|
+
const v = filter[f]
|
|
527
535
|
if (
|
|
528
536
|
!(
|
|
529
537
|
v === null ||
|
|
530
|
-
(typeof v ===
|
|
538
|
+
(typeof v === 'number' && isNaN(v)) ||
|
|
531
539
|
v === Infinity ||
|
|
532
540
|
v === undefined ||
|
|
533
541
|
excludeParams.includes(f)
|
|
534
542
|
)
|
|
535
543
|
) {
|
|
536
|
-
_filter[f] = filter[f]
|
|
544
|
+
_filter[f] = filter[f]
|
|
537
545
|
|
|
538
|
-
if (regexFields.includes(f))
|
|
539
|
-
_filter[f] = { $regex: new RegExp(_filter[f], "gi") };
|
|
546
|
+
if (regexFields.includes(f)) _filter[f] = { $regex: new RegExp(_filter[f], 'gi') }
|
|
540
547
|
}
|
|
541
|
-
})
|
|
548
|
+
})
|
|
542
549
|
|
|
543
|
-
return _filter
|
|
544
|
-
}
|
|
550
|
+
return _filter
|
|
551
|
+
}
|
|
545
552
|
|
|
546
553
|
export interface TMongoPaginate {
|
|
547
|
-
skip: number
|
|
548
|
-
limit: number
|
|
554
|
+
skip: number
|
|
555
|
+
limit: number
|
|
549
556
|
}
|
|
550
557
|
|
|
551
558
|
export type TFieldsGQL =
|
|
552
|
-
|
|
|
553
|
-
|
|
|
554
|
-
|
|
555
|
-
|
|
|
556
|
-
|
|
|
557
|
-
|
|
|
558
|
-
|
|
559
|
-
|
|
|
560
|
-
|
|
|
561
|
-
|
|
562
|
-
|
|
|
563
|
-
|
|
|
564
|
-
|
|
|
565
|
-
|
|
566
|
-
|
|
|
567
|
-
|
|
|
568
|
-
|
|
|
569
|
-
|
|
570
|
-
| "activeMarkByIDs"
|
|
571
|
-
| "deleteMarkByIDs"
|
|
572
|
-
| "systemMarkByIDs"
|
|
573
|
-
| "init";
|
|
559
|
+
| 'create'
|
|
560
|
+
| 'count'
|
|
561
|
+
| 'find'
|
|
562
|
+
| 'findOne'
|
|
563
|
+
| 'findMany'
|
|
564
|
+
| 'findOneByID'
|
|
565
|
+
| 'findManyByIDs'
|
|
566
|
+
| 'update'
|
|
567
|
+
| 'updateOneByID'
|
|
568
|
+
| 'updateManyByIDs'
|
|
569
|
+
| 'deleteOne'
|
|
570
|
+
| 'deleteOneByID'
|
|
571
|
+
| 'deleteManyByIDs'
|
|
572
|
+
| 'markActiveByIDs'
|
|
573
|
+
| 'markForDeleteByIDs'
|
|
574
|
+
| 'markSystemByIDs'
|
|
575
|
+
| 'init'
|
|
574
576
|
|
|
575
577
|
/**
|
|
576
578
|
* Normalise Mongo Paginate params
|
|
577
579
|
* @param filter
|
|
578
580
|
*/
|
|
579
|
-
export const normaliseMongoPaginate = (
|
|
580
|
-
filter: TMongoFilterNormalise
|
|
581
|
-
): TMongoPaginate => {
|
|
581
|
+
export const normaliseMongoPaginate = (filter: TMongoFilterNormalise): TMongoPaginate => {
|
|
582
582
|
let res: TMongoPaginate = {
|
|
583
583
|
skip: 0,
|
|
584
584
|
limit: 50,
|
|
585
|
-
}
|
|
585
|
+
}
|
|
586
586
|
|
|
587
|
-
res.skip = filter && filter.skip ? parseInt(filter.skip, 10) || 0 : 0
|
|
588
|
-
res.limit = filter && filter.limit ? parseInt(filter.limit, 10) || 50 : 50
|
|
587
|
+
res.skip = filter && filter.skip ? parseInt(filter.skip, 10) || 0 : 0
|
|
588
|
+
res.limit = filter && filter.limit ? parseInt(filter.limit, 10) || 50 : 50
|
|
589
589
|
|
|
590
|
-
return res
|
|
591
|
-
}
|
|
590
|
+
return res
|
|
591
|
+
}
|
|
592
592
|
|
|
593
593
|
export const controlResponseNull = (
|
|
594
594
|
data: object,
|
|
595
|
-
okResultOf:
|
|
596
|
-
| "create"
|
|
597
|
-
| "update"
|
|
598
|
-
| "update_or_create"
|
|
599
|
-
| "update_many"
|
|
600
|
-
| "increment"
|
|
601
|
-
| "decrement",
|
|
595
|
+
okResultOf: 'create' | 'update' | 'update_or_create' | 'update_many' | 'increment' | 'decrement',
|
|
602
596
|
prefix: string,
|
|
603
597
|
bodyWrap: boolean = true
|
|
604
598
|
) => {
|
|
605
|
-
let result
|
|
599
|
+
let result
|
|
606
600
|
|
|
607
601
|
if (data) {
|
|
608
|
-
if (okResultOf ===
|
|
602
|
+
if (okResultOf === 'create') {
|
|
609
603
|
result = CreateResponse.created({
|
|
610
604
|
data,
|
|
611
605
|
message: messagesREST(prefix).CREATE,
|
|
612
606
|
bodyWrap,
|
|
613
|
-
})
|
|
607
|
+
})
|
|
614
608
|
}
|
|
615
609
|
|
|
616
|
-
if (okResultOf ===
|
|
610
|
+
if (okResultOf === 'update') {
|
|
617
611
|
result = CreateResponse.updated({
|
|
618
612
|
data,
|
|
619
613
|
message: messagesREST(prefix).UPDATE,
|
|
620
614
|
bodyWrap,
|
|
621
|
-
})
|
|
615
|
+
})
|
|
622
616
|
}
|
|
623
617
|
|
|
624
|
-
if (okResultOf ===
|
|
618
|
+
if (okResultOf === 'update_or_create') {
|
|
625
619
|
result = CreateResponse.updateOrCreate({
|
|
626
620
|
data,
|
|
627
621
|
message: messagesREST(prefix).UPDATE_OR_CREATE,
|
|
628
622
|
bodyWrap,
|
|
629
|
-
})
|
|
623
|
+
})
|
|
630
624
|
}
|
|
631
625
|
|
|
632
|
-
if (okResultOf ===
|
|
626
|
+
if (okResultOf === 'update_many') {
|
|
633
627
|
result = CreateResponse.updated({
|
|
634
628
|
data,
|
|
635
629
|
message: messagesREST(prefix).UPDATE_MANY,
|
|
636
630
|
bodyWrap,
|
|
637
|
-
})
|
|
631
|
+
})
|
|
638
632
|
}
|
|
639
633
|
|
|
640
|
-
if (okResultOf ===
|
|
634
|
+
if (okResultOf === 'increment') {
|
|
641
635
|
result = CreateResponse.updated({
|
|
642
636
|
data,
|
|
643
637
|
message: messagesREST(prefix).INCREMENT,
|
|
644
638
|
bodyWrap,
|
|
645
|
-
})
|
|
639
|
+
})
|
|
646
640
|
}
|
|
647
641
|
|
|
648
|
-
if (okResultOf ===
|
|
642
|
+
if (okResultOf === 'decrement') {
|
|
649
643
|
result = CreateResponse.updated({
|
|
650
644
|
data,
|
|
651
645
|
message: messagesREST(prefix).DECREMENT,
|
|
652
646
|
bodyWrap,
|
|
653
|
-
})
|
|
647
|
+
})
|
|
654
648
|
}
|
|
655
649
|
} else {
|
|
656
|
-
let messageErr =
|
|
657
|
-
if (okResultOf ===
|
|
658
|
-
if (okResultOf ===
|
|
659
|
-
if (okResultOf ===
|
|
660
|
-
|
|
661
|
-
if (okResultOf ===
|
|
662
|
-
|
|
663
|
-
if (okResultOf === "increment")
|
|
664
|
-
messageErr = messagesREST(prefix).NOT_INCREMENT;
|
|
665
|
-
if (okResultOf === "decrement")
|
|
666
|
-
messageErr = messagesREST(prefix).NOT_DECREMENT;
|
|
650
|
+
let messageErr = ''
|
|
651
|
+
if (okResultOf === 'create') messageErr = messagesREST(prefix).NOT_CREATE
|
|
652
|
+
if (okResultOf === 'update') messageErr = messagesREST(prefix).NOT_UPDATE
|
|
653
|
+
if (okResultOf === 'update_or_create') messageErr = messagesREST(prefix).NOT_UPDATE_OR_CREATE
|
|
654
|
+
if (okResultOf === 'update_many') messageErr = messagesREST(prefix).NOT_UPDATE_MANY
|
|
655
|
+
if (okResultOf === 'increment') messageErr = messagesREST(prefix).NOT_INCREMENT
|
|
656
|
+
if (okResultOf === 'decrement') messageErr = messagesREST(prefix).NOT_DECREMENT
|
|
667
657
|
|
|
668
658
|
result = CreateResponse.error({
|
|
669
659
|
data: data,
|
|
670
660
|
message: messageErr,
|
|
671
661
|
bodyWrap,
|
|
672
|
-
})
|
|
662
|
+
})
|
|
673
663
|
}
|
|
674
664
|
|
|
675
|
-
return result
|
|
676
|
-
}
|
|
665
|
+
return result
|
|
666
|
+
}
|
package/package.json
CHANGED