pg-mvc-service 1.0.12 → 1.0.14

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.
@@ -33,24 +33,24 @@ class RequestType extends ReqResType_1.default {
33
33
  INVALID_ENUM: '{property} must be in {enums}. ({value})'
34
34
  };
35
35
  this.ERROR_MESSAGE_JAPAN = {
36
- BODY_REQUIRED: 'リクエストボディが必要です。',
37
36
  REQUIRED: '{property}は必須項目です。',
38
37
  UNNECESSARY: '{property}は不要な入力です。',
39
- INVALID_OBJECT: '{property}はオブジェクト型である必要があります。({value})',
40
- INVALID_ARRAY: '{property}は配列型である必要があります。({value})',
41
- INVALID_NUMBER: '{property}は数値型である必要があります。({value})',
42
- INVALID_BOOL: '{property}は真偽値型、またはtrue、falseの文字列、または0、1の数値である必要があります。({value})',
43
- INVALID_STRING: '{property}は文字列型である必要があります。({value})',
44
- INVALID_UUID: '{property}はUUIDである必要があります。({value})',
45
- INVALID_MAIL: '{property}はメールアドレスである必要があります。({value})',
46
- INVALID_HTTPS: '{property}はhttpsまたはhttpのURLである必要があります。({value})',
47
- INVALID_DATE: '{property}は"YYYY-MM-DD"形式の文字列で有効な日付である必要があります。({value})',
48
- INVALID_TIME: '{property}は"hh:mi"形式の文字列で有効な時刻である必要があります。({value})',
49
- INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式の文字列で有効な日時である必要があります。({value})',
50
- INVALID_BASE64: '{property}はBase64形式である必要があります。({value})',
51
- INVALID_ENUM: '{property}は{enums}のいずれかである必要があります。({value})'
38
+ INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
39
+ INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
40
+ INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
41
+ INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
42
+ INVALID_STRING: '{property}はstring型で入力してください。({value})',
43
+ INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
44
+ INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
45
+ INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
46
+ INVALID_DATE: '{property}は"YYYY-MM-DD"形式のstring型で入力してください。({value})',
47
+ INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
48
+ INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
49
+ INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
50
+ INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
52
51
  };
53
- this.ERROR_MESSAGE = process.env.TZ === 'Tokyo/Asia' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
52
+ this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
53
+ this.paramProperties = {};
54
54
  }
55
55
  get Params() {
56
56
  var _a;
@@ -84,18 +84,16 @@ class RequestType extends ReqResType_1.default {
84
84
  setRequest(request) {
85
85
  var _a, _b, _c;
86
86
  this.createBody(request);
87
- // todo: param設定、Requestと同じようにする
88
- // Swaggerも自動作成できると良い
89
- // Arrayでエンドポイントの順番決めるのがいいのか?
90
- // if (request.params !== undefined) {
91
- // for (const [key, value] of Object.entries(request.params)) {
92
- // if (key.includes("id") || key.includes("Id")) {
93
- // if (this.isUUID(value) === false) {
94
- // throw new InputErrorException("990", this.ErrorMessage("990", [key], value));
95
- // }
96
- // }
97
- // }
98
- // }
87
+ this.params = {};
88
+ if (request.params !== undefined) {
89
+ for (const [key, value] of Object.entries(request.params)) {
90
+ const property = this.paramProperties[key];
91
+ if (property === undefined) {
92
+ throw new Error(`${key} is not set in paramProperties.`);
93
+ }
94
+ this.paramProperties[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${property.pathIndex})`], false);
95
+ }
96
+ }
99
97
  this.params = (_a = request.params) !== null && _a !== void 0 ? _a : {};
100
98
  this.headers = (_b = request.headers) !== null && _b !== void 0 ? _b : {};
101
99
  this.remoteAddress = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress;
@@ -108,47 +106,58 @@ class RequestType extends ReqResType_1.default {
108
106
  * @param {any} value - The value that caused the error. エラーを引き起こした値
109
107
  * @returns {string} The generated error message. 生成されたエラーメッセージ
110
108
  */
111
- ErrorMessage(code, keys, value) {
109
+ throwInputError(code, keys, value) {
112
110
  const list = {
113
- "000": this.ERROR_MESSAGE.REQUIRED,
114
- "001": this.ERROR_MESSAGE.REQUIRED,
115
- "101": this.ERROR_MESSAGE.REQUIRED,
116
- "301": this.ERROR_MESSAGE.REQUIRED,
117
- "002": this.ERROR_MESSAGE.INVALID_OBJECT,
118
- "102": this.ERROR_MESSAGE.INVALID_OBJECT,
119
- "003": this.ERROR_MESSAGE.INVALID_ARRAY,
120
- "103": this.ERROR_MESSAGE.INVALID_ARRAY,
121
- "004": this.ERROR_MESSAGE.UNNECESSARY,
122
- "104": this.ERROR_MESSAGE.UNNECESSARY,
123
- "201": this.ERROR_MESSAGE.INVALID_NUMBER,
124
- "411": this.ERROR_MESSAGE.INVALID_NUMBER,
125
- "211": this.ERROR_MESSAGE.INVALID_BOOL,
126
- "212": this.ERROR_MESSAGE.INVALID_BOOL,
127
- "213": this.ERROR_MESSAGE.INVALID_BOOL,
128
- "421": this.ERROR_MESSAGE.INVALID_BOOL,
129
- "422": this.ERROR_MESSAGE.INVALID_BOOL,
130
- "423": this.ERROR_MESSAGE.INVALID_BOOL,
131
- "221": this.ERROR_MESSAGE.INVALID_STRING,
132
- "431": this.ERROR_MESSAGE.INVALID_STRING,
133
- "231": this.ERROR_MESSAGE.INVALID_UUID,
134
- "241": this.ERROR_MESSAGE.INVALID_MAIL,
135
- "251": this.ERROR_MESSAGE.INVALID_DATE,
136
- "252": this.ERROR_MESSAGE.INVALID_DATE,
137
- "261": this.ERROR_MESSAGE.INVALID_TIME,
138
- "271": this.ERROR_MESSAGE.INVALID_DATETIME,
139
- "272": this.ERROR_MESSAGE.INVALID_DATETIME,
140
- "281": this.ERROR_MESSAGE.INVALID_HTTPS,
141
- "291": this.ERROR_MESSAGE.INVALID_BASE64,
142
- "401": this.ERROR_MESSAGE.INVALID_ENUM,
143
- "402": this.ERROR_MESSAGE.INVALID_ENUM,
111
+ "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
112
+ "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
113
+ "OBJECT_01": this.ERROR_MESSAGE.INVALID_OBJECT,
114
+ "ARRAY_01": this.ERROR_MESSAGE.INVALID_ARRAY,
115
+ "UNNECESSARY_01": this.ERROR_MESSAGE.UNNECESSARY,
116
+ "REQUIRE_11": this.ERROR_MESSAGE.REQUIRED,
117
+ "OBJECT_11": this.ERROR_MESSAGE.INVALID_OBJECT,
118
+ "ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
119
+ "UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
120
+ "NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
121
+ "BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
122
+ "BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
123
+ "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
124
+ "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
125
+ "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
126
+ "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
127
+ "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
128
+ "DATE_22": this.ERROR_MESSAGE.INVALID_DATE,
129
+ "TIME_21": this.ERROR_MESSAGE.INVALID_TIME,
130
+ "DATETIME_21": this.ERROR_MESSAGE.INVALID_DATETIME,
131
+ "DATETIME_22": this.ERROR_MESSAGE.INVALID_DATETIME,
132
+ "HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
133
+ "BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
134
+ "REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
135
+ "NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
136
+ "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
137
+ "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
138
+ "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
139
+ "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
140
+ "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
141
+ "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
142
+ "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
143
+ "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
144
+ "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
145
+ "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
146
+ "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
147
+ "DATE_92": this.ERROR_MESSAGE.INVALID_DATE,
148
+ "TIME_91": this.ERROR_MESSAGE.INVALID_TIME,
149
+ "DATETIME_91": this.ERROR_MESSAGE.INVALID_DATETIME,
150
+ "DATETIME_92": this.ERROR_MESSAGE.INVALID_DATETIME,
151
+ "HTTPS_91": this.ERROR_MESSAGE.INVALID_HTTPS,
152
+ "BASE64_91": this.ERROR_MESSAGE.INVALID_BASE64,
144
153
  };
145
154
  let errorMessage = list[code];
146
- if (code === "401" || code === "402") {
155
+ if (code === "ENUM_41" || code === "ENUM_42") {
147
156
  const property = this.getProperty(keys);
148
157
  errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
149
158
  }
150
159
  errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
151
- return errorMessage;
160
+ throw new Exception_1.InputErrorException(code, errorMessage);
152
161
  }
153
162
  /**
154
163
  * Sets the values of the request body to the class properties.
@@ -197,7 +206,7 @@ class RequestType extends ReqResType_1.default {
197
206
  continue;
198
207
  }
199
208
  else {
200
- throw new Exception_1.InputErrorException("000", this.ErrorMessage("000", [key, 0], ""));
209
+ this.throwInputError("REQUIRE_00", [key, 0], "");
201
210
  }
202
211
  }
203
212
  else {
@@ -206,7 +215,7 @@ class RequestType extends ReqResType_1.default {
206
215
  continue;
207
216
  }
208
217
  else {
209
- throw new Exception_1.InputErrorException("001", this.ErrorMessage("001", [key], ""));
218
+ this.throwInputError("REQUIRE_01", [key], "");
210
219
  }
211
220
  }
212
221
  }
@@ -218,7 +227,7 @@ class RequestType extends ReqResType_1.default {
218
227
  this.setObject([key], value);
219
228
  }
220
229
  else {
221
- throw new Exception_1.InputErrorException("002", this.ErrorMessage("002", [key], value));
230
+ this.throwInputError("OBJECT_01", [key], value);
222
231
  }
223
232
  break;
224
233
  case 'array':
@@ -230,10 +239,10 @@ class RequestType extends ReqResType_1.default {
230
239
  if (request.method === 'GET' || request.method === 'DELETE') {
231
240
  // GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
232
241
  // ?array=1のみで終わる場合は配列にならないため、直接配列にしている
233
- this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0])];
242
+ this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0], true)];
234
243
  }
235
244
  else {
236
- throw new Exception_1.InputErrorException("003", this.ErrorMessage("003", [key], value));
245
+ this.throwInputError("ARRAY_01", [key], value);
237
246
  }
238
247
  }
239
248
  break;
@@ -249,7 +258,7 @@ class RequestType extends ReqResType_1.default {
249
258
  // 不要項目チェック
250
259
  for (const [key, value] of Object.entries(this.data)) {
251
260
  if (key in this.properties === false) {
252
- throw new Exception_1.InputErrorException("004", this.ErrorMessage("004", [key], value));
261
+ this.throwInputError("UNNECESSARY_01", [key], value);
253
262
  }
254
263
  }
255
264
  }
@@ -271,14 +280,14 @@ class RequestType extends ReqResType_1.default {
271
280
  this.changeBody(keys, null);
272
281
  }
273
282
  else {
274
- throw new Exception_1.InputErrorException("401", this.ErrorMessage("401", keys, value));
283
+ this.throwInputError("ENUM_41", keys, value);
275
284
  }
276
285
  }
277
286
  switch (enumType) {
278
287
  case 'number':
279
288
  case 'number?':
280
289
  if (this.isNumber(value) === false) {
281
- throw new Exception_1.InputErrorException("411", this.ErrorMessage("411", keys, value));
290
+ this.throwInputError("NUMBER_41", keys, value);
282
291
  }
283
292
  value = Number(value);
284
293
  break;
@@ -292,12 +301,12 @@ class RequestType extends ReqResType_1.default {
292
301
  value = value;
293
302
  break;
294
303
  default:
295
- throw new Exception_1.InputErrorException("431", this.ErrorMessage("431", keys, value));
304
+ this.throwInputError("STRING_41", keys, value);
296
305
  }
297
306
  break;
298
307
  }
299
308
  if (Object.keys(property.enums).includes(value.toString()) === false) {
300
- throw new Exception_1.InputErrorException("402", this.ErrorMessage("402", keys, value));
309
+ this.throwInputError("ENUM_42", keys, value);
301
310
  }
302
311
  this.changeBody(keys, value);
303
312
  }
@@ -324,7 +333,7 @@ class RequestType extends ReqResType_1.default {
324
333
  continue;
325
334
  }
326
335
  else {
327
- throw new Exception_1.InputErrorException("301", this.ErrorMessage("301", [...keys, i], ""));
336
+ this.throwInputError("REQUIRE_31", [...keys, i], "");
328
337
  }
329
338
  }
330
339
  switch (property.properties.type) {
@@ -420,7 +429,7 @@ class RequestType extends ReqResType_1.default {
420
429
  continue;
421
430
  }
422
431
  else {
423
- throw new Exception_1.InputErrorException("101", this.ErrorMessage("101", [...keys, key], ""));
432
+ this.throwInputError("REQUIRE_11", [...keys, key], "");
424
433
  }
425
434
  }
426
435
  const value = values[key];
@@ -431,7 +440,7 @@ class RequestType extends ReqResType_1.default {
431
440
  this.setObject([...keys, key], value);
432
441
  }
433
442
  else {
434
- throw new Exception_1.InputErrorException("102", this.ErrorMessage("102", [...keys, key], value));
443
+ this.throwInputError("OBJECT_11", [...keys, key], value);
435
444
  }
436
445
  break;
437
446
  case 'array':
@@ -440,7 +449,7 @@ class RequestType extends ReqResType_1.default {
440
449
  this.setArray([...keys, key], value);
441
450
  }
442
451
  else {
443
- throw new Exception_1.InputErrorException("103", this.ErrorMessage("103", [...keys, key], value));
452
+ this.throwInputError("ARRAY_11", [...keys, key], value);
444
453
  }
445
454
  break;
446
455
  case 'enum':
@@ -455,7 +464,7 @@ class RequestType extends ReqResType_1.default {
455
464
  // unnecessary input check
456
465
  for (const [key, value] of Object.entries(values)) {
457
466
  if (key in property.properties === false) {
458
- throw new Exception_1.InputErrorException("104", this.ErrorMessage("104", [...keys, key], value));
467
+ this.throwInputError("UNNECESSARY_11", [...keys, key], value);
459
468
  }
460
469
  }
461
470
  }
@@ -474,12 +483,12 @@ class RequestType extends ReqResType_1.default {
474
483
  * @returns {any} The converted value, 変換された値
475
484
  * @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
476
485
  */
477
- convertValue(type, value, keys) {
486
+ convertValue(type, value, keys, isRequestBody) {
478
487
  switch (type) {
479
488
  case 'number':
480
489
  case 'number?':
481
490
  if (this.isNumber(value) === false) {
482
- throw new Exception_1.InputErrorException("201", this.ErrorMessage("201", keys, value));
491
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
483
492
  }
484
493
  return Number(value);
485
494
  case 'boolean':
@@ -489,16 +498,16 @@ class RequestType extends ReqResType_1.default {
489
498
  return value;
490
499
  case 'number':
491
500
  if (value !== 0 && value !== 1) {
492
- throw new Exception_1.InputErrorException("211", this.ErrorMessage("211", keys, value));
501
+ this.throwInputError(isRequestBody ? "BOOL_21" : "BOOL_91", keys, value);
493
502
  }
494
503
  return value === 1 ? true : false;
495
504
  case 'string':
496
505
  if (value !== 'true' && value !== 'false') {
497
- throw new Exception_1.InputErrorException("212", this.ErrorMessage("212", keys, value));
506
+ this.throwInputError(isRequestBody ? "BOOL_22" : "BOOL_92", keys, value);
498
507
  }
499
508
  return value === 'true' ? true : false;
500
509
  default:
501
- throw new Exception_1.InputErrorException("213", this.ErrorMessage("213", keys, value));
510
+ this.throwInputError(isRequestBody ? "BOOL_23" : "BOOL_93", keys, value);
502
511
  }
503
512
  case 'string':
504
513
  case 'string?':
@@ -508,27 +517,27 @@ class RequestType extends ReqResType_1.default {
508
517
  case 'string':
509
518
  return value;
510
519
  default:
511
- throw new Exception_1.InputErrorException("221", this.ErrorMessage("221", keys, value));
520
+ this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
512
521
  }
513
522
  case 'uuid':
514
523
  case 'uuid?':
515
524
  if (this.isUUID(value)) {
516
525
  return value;
517
526
  }
518
- throw new Exception_1.InputErrorException("231", this.ErrorMessage("231", keys, value));
527
+ this.throwInputError(isRequestBody ? "UUID_21" : "UUID_91", keys, value);
519
528
  case 'mail':
520
529
  case 'mail?':
521
530
  if (this.isMail(value)) {
522
531
  return value;
523
532
  }
524
- throw new Exception_1.InputErrorException("241", this.ErrorMessage("241", keys, value));
533
+ this.throwInputError(isRequestBody ? "MAIL_21" : "MAIL_91", keys, value);
525
534
  case 'date':
526
535
  case 'date?':
527
536
  if (this.isYYYYMMDD(value) === false) {
528
- throw new Exception_1.InputErrorException("251", this.ErrorMessage("251", keys, value));
537
+ this.throwInputError(isRequestBody ? "DATE_21" : "DATE_91", keys, value);
529
538
  }
530
539
  if (this.isErrorDateTime(value)) {
531
- throw new Exception_1.InputErrorException("252", this.ErrorMessage("252", keys, value));
540
+ this.throwInputError(isRequestBody ? "DATE_22" : "DATE_92", keys, value);
532
541
  }
533
542
  return value;
534
543
  case 'time':
@@ -536,17 +545,17 @@ class RequestType extends ReqResType_1.default {
536
545
  if (this.isHHMM(value)) {
537
546
  return `${value}`;
538
547
  }
539
- throw new Exception_1.InputErrorException("261", this.ErrorMessage("261", keys, value));
548
+ this.throwInputError(isRequestBody ? "TIME_21" : "TIME_91", keys, value);
540
549
  case 'datetime':
541
550
  case 'datetime?':
542
551
  if (this.isYYYYMMDDhhmi(value)) {
543
552
  value += ':00';
544
553
  }
545
554
  if (this.isYYYYMMDDhhmiss(value) === false) {
546
- throw new Exception_1.InputErrorException("271", this.ErrorMessage("271", keys, value));
555
+ this.throwInputError(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys, value);
547
556
  }
548
557
  if (this.isErrorDateTime(value)) {
549
- throw new Exception_1.InputErrorException("272", this.ErrorMessage("272", keys, value));
558
+ this.throwInputError(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys, value);
550
559
  }
551
560
  return value.replace('T', ' ');
552
561
  case 'https':
@@ -554,13 +563,13 @@ class RequestType extends ReqResType_1.default {
554
563
  if (this.isHttps(value)) {
555
564
  return value;
556
565
  }
557
- throw new Exception_1.InputErrorException("281", this.ErrorMessage("281", keys, value));
566
+ this.throwInputError(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys, value);
558
567
  case 'base64':
559
568
  case 'base64?':
560
569
  if (this.isBase64(value)) {
561
570
  return value;
562
571
  }
563
- throw new Exception_1.InputErrorException("291", this.ErrorMessage("291", keys, value));
572
+ this.throwInputError(isRequestBody ? "BASE64_21" : "BASE64_91", keys, value);
564
573
  }
565
574
  return value;
566
575
  }
@@ -578,7 +587,7 @@ class RequestType extends ReqResType_1.default {
578
587
  */
579
588
  convertInput(keys, value) {
580
589
  const property = this.getProperty(keys);
581
- this.changeBody(keys, this.convertValue(property.type, value, keys));
590
+ this.changeBody(keys, this.convertValue(property.type, value, keys, true));
582
591
  }
583
592
  // ****************************************************************************
584
593
  // for create swagger
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from "axios";
2
2
  import { Request, Response } from 'express';
3
3
  import { Pool, PoolClient } from 'pg';
4
- import { IncomingHttpHeaders } from './src/reqestResponse/RequestType';
4
+ import { ErrorMessageType, IncomingHttpHeaders } from './src/reqestResponse/RequestType';
5
5
  import { ArrayType, EnumType, ObjectType, PrimitiveType } from './src/reqestResponse/ReqResType';
6
6
  import { AwsS3Client } from './src/clients/AwsS3Client';
7
7
  import { Base64Client } from './src/clients/Base64Client';
@@ -85,22 +85,8 @@ declare module 'pg-mvc-service' {
85
85
  constructor();
86
86
 
87
87
  protected properties: { [key: string]: PropertyType; };
88
-
89
- public readonly INVALID_PATH_PARAM_UUID_ERROR_MESSAGE: string;
90
- public readonly REQUIRED_ERROR_MESSAGE: string;
91
- public readonly UNNECESSARY_INPUT_ERROR_MESSAGE: string;
92
- public readonly INVALID_OBJECT_ERROR_MESSAGE: string;
93
- public readonly INVALID_ARRAY_ERROR_MESSAGE: string;
94
- public readonly INVALID_NUMBER_ERROR_MESSAGE: string;
95
- public readonly INVALID_BOOL_ERROR_MESSAGE: string;
96
- public readonly INVALID_STRING_ERROR_MESSAGE: string;
97
- public readonly INVALID_UUID_ERROR_MESSAGE: string;
98
- public readonly INVALID_MAIL_ERROR_MESSAGE: string;
99
- public readonly INVALID_DATE_ERROR_MESSAGE: string;
100
- public readonly INVALID_TIME_ERROR_MESSAGE: string;
101
- public readonly INVALID_DATETIME_ERROR_MESSAGE: string;
102
- public readonly INVALID_BASE64_ERROR_MESSAGE: string;
103
- public readonly INVALID_ENUM_ERROR_MESSAGE: string;
88
+ protected paramProperties: { [key: string]: (PrimitiveType | EnumType) & { pathIndex: number }; };
89
+ protected readonly ERROR_MESSAGE: ErrorMessageType;
104
90
 
105
91
  protected throwException(code: string, message: string): never;
106
92
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -4,7 +4,6 @@ export type PrimitiveType = {
4
4
  'string?' | 'number?' | 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
5
5
  description?: string;
6
6
  };
7
-
8
7
  export type ObjectType = {
9
8
  type: 'object' | 'object?';
10
9
  description?: string;
@@ -1,7 +1,26 @@
1
1
  import { Request } from 'express';
2
- import ReqResType from "./ReqResType";
2
+ import ReqResType, { EnumType, PrimitiveType, PropertyType } from "./ReqResType";
3
3
  import { InputErrorException } from '../exceptions/Exception';
4
4
 
5
+ // エラーメッセージの型定義
6
+ export interface ErrorMessageType {
7
+ REQUIRED: string;
8
+ UNNECESSARY: string;
9
+ INVALID_OBJECT: string;
10
+ INVALID_ARRAY: string;
11
+ INVALID_NUMBER: string;
12
+ INVALID_BOOL: string;
13
+ INVALID_STRING: string;
14
+ INVALID_UUID: string;
15
+ INVALID_MAIL: string;
16
+ INVALID_HTTPS: string;
17
+ INVALID_DATE: string;
18
+ INVALID_TIME: string;
19
+ INVALID_DATETIME: string;
20
+ INVALID_BASE64: string;
21
+ INVALID_ENUM: string;
22
+ }
23
+
5
24
  export class RequestType extends ReqResType {
6
25
 
7
26
  // *****************************************
@@ -10,7 +29,7 @@ export class RequestType extends ReqResType {
10
29
  // エラー文言
11
30
  // エラーメッセージの変更はサブクラスで行ってください
12
31
  // *****************************************
13
- public readonly ERROR_MESSAGE_ENGLISH = {
32
+ private readonly ERROR_MESSAGE_ENGLISH: ErrorMessageType = {
14
33
  REQUIRED: '{property} is required.',
15
34
  UNNECESSARY: '{property} is unnecessary input. ',
16
35
  INVALID_OBJECT: '{property} must be of type Object. ({value})',
@@ -27,25 +46,28 @@ export class RequestType extends ReqResType {
27
46
  INVALID_BASE64: '{property} must be in Base64 format. ({value})',
28
47
  INVALID_ENUM: '{property} must be in {enums}. ({value})'
29
48
  }
30
- public readonly ERROR_MESSAGE_JAPAN = {
31
- BODY_REQUIRED: 'リクエストボディが必要です。',
49
+ private readonly ERROR_MESSAGE_JAPAN: ErrorMessageType = {
32
50
  REQUIRED: '{property}は必須項目です。',
33
51
  UNNECESSARY: '{property}は不要な入力です。',
34
- INVALID_OBJECT: '{property}はオブジェクト型である必要があります。({value})',
35
- INVALID_ARRAY: '{property}は配列型である必要があります。({value})',
36
- INVALID_NUMBER: '{property}は数値型である必要があります。({value})',
37
- INVALID_BOOL: '{property}は真偽値型、またはtrue、falseの文字列、または0、1の数値である必要があります。({value})',
38
- INVALID_STRING: '{property}は文字列型である必要があります。({value})',
39
- INVALID_UUID: '{property}はUUIDである必要があります。({value})',
40
- INVALID_MAIL: '{property}はメールアドレスである必要があります。({value})',
41
- INVALID_HTTPS: '{property}はhttpsまたはhttpのURLである必要があります。({value})',
42
- INVALID_DATE: '{property}は"YYYY-MM-DD"形式の文字列で有効な日付である必要があります。({value})',
43
- INVALID_TIME: '{property}は"hh:mi"形式の文字列で有効な時刻である必要があります。({value})',
44
- INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式の文字列で有効な日時である必要があります。({value})',
45
- INVALID_BASE64: '{property}はBase64形式である必要があります。({value})',
46
- INVALID_ENUM: '{property}は{enums}のいずれかである必要があります。({value})'
52
+ INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
53
+ INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
54
+ INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
55
+ INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
56
+ INVALID_STRING: '{property}はstring型で入力してください。({value})',
57
+ INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
58
+ INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
59
+ INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
60
+ INVALID_DATE: '{property}は"YYYY-MM-DD"形式のstring型で入力してください。({value})',
61
+ INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
62
+ INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
63
+ INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
64
+ INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
47
65
  }
48
- public readonly ERROR_MESSAGE = process.env.TZ === 'Tokyo/Asia' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
66
+ protected readonly ERROR_MESSAGE: ErrorMessageType = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
67
+
68
+ protected paramProperties: {
69
+ [key: string]: (PrimitiveType | EnumType) & { pathIndex: number };
70
+ } = {};
49
71
 
50
72
  private params?: {[key: string]: any};
51
73
  get Params(): {[key: string]: any} {
@@ -80,18 +102,17 @@ export class RequestType extends ReqResType {
80
102
 
81
103
  public setRequest(request: Request) {
82
104
  this.createBody(request);
83
- // todo: param設定、Requestと同じようにする
84
- // Swaggerも自動作成できると良い
85
- // Arrayでエンドポイントの順番決めるのがいいのか?
86
- // if (request.params !== undefined) {
87
- // for (const [key, value] of Object.entries(request.params)) {
88
- // if (key.includes("id") || key.includes("Id")) {
89
- // if (this.isUUID(value) === false) {
90
- // throw new InputErrorException("990", this.ErrorMessage("990", [key], value));
91
- // }
92
- // }
93
- // }
94
- // }
105
+
106
+ this.params = {};
107
+ if (request.params !== undefined) {
108
+ for (const [key, value] of Object.entries(request.params)) {
109
+ const property = this.paramProperties[key];
110
+ if (property === undefined) {
111
+ throw new Error(`${key} is not set in paramProperties.`);
112
+ }
113
+ this.paramProperties[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${property.pathIndex})`], false);
114
+ }
115
+ }
95
116
  this.params = request.params ?? {};
96
117
  this.headers = request.headers ?? {};
97
118
 
@@ -105,52 +126,71 @@ export class RequestType extends ReqResType {
105
126
  * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
106
127
  * @param {any} value - The value that caused the error. エラーを引き起こした値
107
128
  * @returns {string} The generated error message. 生成されたエラーメッセージ
108
- */
109
- private ErrorMessage(code: "000" | "001" | "002" | "003" | "004" | "101" | "102" | "103" | "104" |
110
- "201" | "211" | "212" | "213" | "221" | "231" | "241" | "251" | "252" |
111
- "261" | "271" | "272" | "281" | "291" | "301" | "401" | "402" | "411" | "421" | "422" | "423" | "431", keys: Array<string | number>, value: any): string {
129
+ */
130
+ private throwInputError(code:
131
+ "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
132
+ "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
133
+ "NUMBER_21" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
134
+ "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
135
+ "REQUIRE_31" |
136
+ "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
137
+ "NUMBER_91" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
138
+ "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
139
+ , keys: Array<string | number>, value: any): never {
112
140
  const list = {
113
- "000": this.ERROR_MESSAGE.REQUIRED,
114
- "001": this.ERROR_MESSAGE.REQUIRED,
115
- "101": this.ERROR_MESSAGE.REQUIRED,
116
- "301": this.ERROR_MESSAGE.REQUIRED,
117
- "002": this.ERROR_MESSAGE.INVALID_OBJECT,
118
- "102": this.ERROR_MESSAGE.INVALID_OBJECT,
119
- "003": this.ERROR_MESSAGE.INVALID_ARRAY,
120
- "103": this.ERROR_MESSAGE.INVALID_ARRAY,
121
- "004": this.ERROR_MESSAGE.UNNECESSARY,
122
- "104": this.ERROR_MESSAGE.UNNECESSARY,
123
- "201": this.ERROR_MESSAGE.INVALID_NUMBER,
124
- "411": this.ERROR_MESSAGE.INVALID_NUMBER,
125
- "211": this.ERROR_MESSAGE.INVALID_BOOL,
126
- "212": this.ERROR_MESSAGE.INVALID_BOOL,
127
- "213": this.ERROR_MESSAGE.INVALID_BOOL,
128
- "421": this.ERROR_MESSAGE.INVALID_BOOL,
129
- "422": this.ERROR_MESSAGE.INVALID_BOOL,
130
- "423": this.ERROR_MESSAGE.INVALID_BOOL,
131
- "221": this.ERROR_MESSAGE.INVALID_STRING,
132
- "431": this.ERROR_MESSAGE.INVALID_STRING,
133
- "231": this.ERROR_MESSAGE.INVALID_UUID,
134
- "241": this.ERROR_MESSAGE.INVALID_MAIL,
135
- "251": this.ERROR_MESSAGE.INVALID_DATE,
136
- "252": this.ERROR_MESSAGE.INVALID_DATE,
137
- "261": this.ERROR_MESSAGE.INVALID_TIME,
138
- "271": this.ERROR_MESSAGE.INVALID_DATETIME,
139
- "272": this.ERROR_MESSAGE.INVALID_DATETIME,
140
- "281": this.ERROR_MESSAGE.INVALID_HTTPS,
141
- "291": this.ERROR_MESSAGE.INVALID_BASE64,
142
- "401": this.ERROR_MESSAGE.INVALID_ENUM,
143
- "402": this.ERROR_MESSAGE.INVALID_ENUM,
141
+ "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
142
+ "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
143
+ "OBJECT_01": this.ERROR_MESSAGE.INVALID_OBJECT,
144
+ "ARRAY_01": this.ERROR_MESSAGE.INVALID_ARRAY,
145
+ "UNNECESSARY_01": this.ERROR_MESSAGE.UNNECESSARY,
146
+ "REQUIRE_11": this.ERROR_MESSAGE.REQUIRED,
147
+ "OBJECT_11": this.ERROR_MESSAGE.INVALID_OBJECT,
148
+ "ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
149
+ "UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
150
+ "NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
151
+ "BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
152
+ "BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
153
+ "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
154
+ "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
155
+ "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
156
+ "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
157
+ "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
158
+ "DATE_22": this.ERROR_MESSAGE.INVALID_DATE,
159
+ "TIME_21": this.ERROR_MESSAGE.INVALID_TIME,
160
+ "DATETIME_21": this.ERROR_MESSAGE.INVALID_DATETIME,
161
+ "DATETIME_22": this.ERROR_MESSAGE.INVALID_DATETIME,
162
+ "HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
163
+ "BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
164
+ "REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
165
+ "NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
166
+ "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
167
+ "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
168
+ "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
169
+ "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
170
+ "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
171
+ "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
172
+ "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
173
+ "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
174
+ "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
175
+ "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
176
+ "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
177
+ "DATE_92": this.ERROR_MESSAGE.INVALID_DATE,
178
+ "TIME_91": this.ERROR_MESSAGE.INVALID_TIME,
179
+ "DATETIME_91": this.ERROR_MESSAGE.INVALID_DATETIME,
180
+ "DATETIME_92": this.ERROR_MESSAGE.INVALID_DATETIME,
181
+ "HTTPS_91": this.ERROR_MESSAGE.INVALID_HTTPS,
182
+ "BASE64_91": this.ERROR_MESSAGE.INVALID_BASE64,
144
183
  }
145
184
 
146
- let errorMessage = list[code];
147
- if (code === "401" || code === "402") {
185
+ let errorMessage = list[code];
186
+ if (code === "ENUM_41" || code === "ENUM_42") {
148
187
  const property = this.getProperty(keys);
149
188
  errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
150
189
  }
151
190
 
152
- errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value)
153
- return errorMessage;
191
+ errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
192
+
193
+ throw new InputErrorException(code, errorMessage);
154
194
  }
155
195
 
156
196
  /**
@@ -200,14 +240,14 @@ export class RequestType extends ReqResType {
200
240
  }
201
241
  continue;
202
242
  } else {
203
- throw new InputErrorException("000", this.ErrorMessage("000", [key, 0], ""));
243
+ this.throwInputError("REQUIRE_00", [key, 0], "");
204
244
  }
205
245
  } else {
206
246
  if (this.properties[key].type.endsWith('?')) {
207
247
  this.changeBody([key], null);
208
248
  continue;
209
249
  } else {
210
- throw new InputErrorException("001", this.ErrorMessage("001", [key], ""));
250
+ this.throwInputError("REQUIRE_01", [key], "");
211
251
  }
212
252
  }
213
253
  }
@@ -219,7 +259,7 @@ export class RequestType extends ReqResType {
219
259
  if (typeof value === 'object') {
220
260
  this.setObject([key], value);
221
261
  } else {
222
- throw new InputErrorException("002", this.ErrorMessage("002", [key], value));
262
+ this.throwInputError("OBJECT_01", [key], value);
223
263
  }
224
264
  break;
225
265
  case 'array':
@@ -230,9 +270,9 @@ export class RequestType extends ReqResType {
230
270
  if (request.method === 'GET' || request.method === 'DELETE') {
231
271
  // GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
232
272
  // ?array=1のみで終わる場合は配列にならないため、直接配列にしている
233
- this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0])];
273
+ this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0], true)];
234
274
  } else {
235
- throw new InputErrorException("003", this.ErrorMessage("003", [key], value));
275
+ this.throwInputError("ARRAY_01", [key], value);
236
276
  }
237
277
  }
238
278
  break;
@@ -249,7 +289,7 @@ export class RequestType extends ReqResType {
249
289
  // 不要項目チェック
250
290
  for (const [key, value] of Object.entries(this.data)) {
251
291
  if (key in this.properties === false) {
252
- throw new InputErrorException("004", this.ErrorMessage("004", [key], value));
292
+ this.throwInputError("UNNECESSARY_01", [key], value);
253
293
  }
254
294
  }
255
295
  }
@@ -272,7 +312,7 @@ export class RequestType extends ReqResType {
272
312
  if (enumType.endsWith('?')) {
273
313
  this.changeBody(keys, null);
274
314
  } else {
275
- throw new InputErrorException("401", this.ErrorMessage("401", keys, value));
315
+ this.throwInputError("ENUM_41", keys, value);
276
316
  }
277
317
  }
278
318
 
@@ -280,7 +320,7 @@ export class RequestType extends ReqResType {
280
320
  case 'number':
281
321
  case 'number?':
282
322
  if (this.isNumber(value) === false) {
283
- throw new InputErrorException("411", this.ErrorMessage("411", keys, value));
323
+ this.throwInputError("NUMBER_41", keys, value);
284
324
  }
285
325
  value = Number(value);
286
326
  break;
@@ -294,13 +334,13 @@ export class RequestType extends ReqResType {
294
334
  value = value;
295
335
  break;
296
336
  default:
297
- throw new InputErrorException("431", this.ErrorMessage("431", keys, value));
337
+ this.throwInputError("STRING_41", keys, value);
298
338
  }
299
339
  break;
300
340
  }
301
341
 
302
342
  if (Object.keys(property.enums).includes(value.toString()) === false) {
303
- throw new InputErrorException("402", this.ErrorMessage("402", keys, value));
343
+ this.throwInputError("ENUM_42", keys, value);
304
344
  }
305
345
 
306
346
  this.changeBody(keys, value);
@@ -329,7 +369,7 @@ export class RequestType extends ReqResType {
329
369
  this.changeBody([...keys, i], values[i] === undefined ? undefined : null);
330
370
  continue;
331
371
  } else {
332
- throw new InputErrorException("301", this.ErrorMessage("301", [...keys, i], ""));
372
+ this.throwInputError("REQUIRE_31", [...keys, i], "");
333
373
  }
334
374
  }
335
375
 
@@ -432,7 +472,7 @@ export class RequestType extends ReqResType {
432
472
  this.changeBody([...keys, key], null);
433
473
  continue;
434
474
  } else {
435
- throw new InputErrorException("101", this.ErrorMessage("101", [...keys, key], ""));
475
+ this.throwInputError("REQUIRE_11", [...keys, key], "");
436
476
  }
437
477
  }
438
478
 
@@ -443,7 +483,7 @@ export class RequestType extends ReqResType {
443
483
  if (typeof value === 'object') {
444
484
  this.setObject([...keys, key], value);
445
485
  } else {
446
- throw new InputErrorException("102", this.ErrorMessage("102", [...keys, key], value));
486
+ this.throwInputError("OBJECT_11", [...keys, key], value);
447
487
  }
448
488
  break;
449
489
  case 'array':
@@ -451,7 +491,7 @@ export class RequestType extends ReqResType {
451
491
  if (Array.isArray(value)) {
452
492
  this.setArray([...keys, key], value);
453
493
  } else {
454
- throw new InputErrorException("103", this.ErrorMessage("103", [...keys, key], value));
494
+ this.throwInputError("ARRAY_11", [...keys, key], value);
455
495
  }
456
496
  break;
457
497
  case 'enum':
@@ -467,7 +507,7 @@ export class RequestType extends ReqResType {
467
507
  // unnecessary input check
468
508
  for (const [key, value] of Object.entries(values)) {
469
509
  if (key in property.properties === false) {
470
- throw new InputErrorException("104", this.ErrorMessage("104", [...keys, key], value));
510
+ this.throwInputError("UNNECESSARY_11", [...keys, key], value);
471
511
  }
472
512
  }
473
513
  }
@@ -487,13 +527,13 @@ export class RequestType extends ReqResType {
487
527
  * @returns {any} The converted value, 変換された値
488
528
  * @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
489
529
  */
490
- private convertValue(type: string, value: any, keys: Array<string | number>) {
530
+ private convertValue(type: string, value: any, keys: Array<string | number>, isRequestBody: boolean) {
491
531
 
492
532
  switch (type) {
493
533
  case 'number':
494
534
  case 'number?':
495
535
  if (this.isNumber(value) === false) {
496
- throw new InputErrorException("201", this.ErrorMessage("201", keys, value));
536
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
497
537
  }
498
538
  return Number(value);
499
539
  case 'boolean':
@@ -503,16 +543,16 @@ export class RequestType extends ReqResType {
503
543
  return value;
504
544
  case 'number':
505
545
  if (value !== 0 && value !== 1) {
506
- throw new InputErrorException("211", this.ErrorMessage("211", keys, value));
546
+ this.throwInputError(isRequestBody ? "BOOL_21" : "BOOL_91", keys, value);
507
547
  }
508
548
  return value === 1 ? true : false;
509
549
  case 'string':
510
550
  if (value !== 'true' && value !== 'false') {
511
- throw new InputErrorException("212", this.ErrorMessage("212", keys, value));
551
+ this.throwInputError(isRequestBody ? "BOOL_22" : "BOOL_92", keys, value);
512
552
  }
513
553
  return value === 'true' ? true : false;
514
554
  default:
515
- throw new InputErrorException("213", this.ErrorMessage("213", keys, value));
555
+ this.throwInputError(isRequestBody ? "BOOL_23" : "BOOL_93", keys, value);
516
556
  }
517
557
  case 'string':
518
558
  case 'string?':
@@ -522,28 +562,28 @@ export class RequestType extends ReqResType {
522
562
  case 'string':
523
563
  return value;
524
564
  default:
525
- throw new InputErrorException("221", this.ErrorMessage("221", keys, value));
565
+ this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
526
566
  }
527
567
  case 'uuid':
528
568
  case 'uuid?':
529
569
  if (this.isUUID(value)) {
530
570
  return value;
531
571
  }
532
- throw new InputErrorException("231", this.ErrorMessage("231", keys, value));
572
+ this.throwInputError(isRequestBody ? "UUID_21" : "UUID_91", keys, value);
533
573
  case 'mail':
534
574
  case 'mail?':
535
575
  if (this.isMail(value)) {
536
576
  return value;
537
577
  }
538
- throw new InputErrorException("241", this.ErrorMessage("241", keys, value));
578
+ this.throwInputError(isRequestBody ? "MAIL_21" : "MAIL_91", keys, value);
539
579
  case 'date':
540
580
  case 'date?':
541
581
  if (this.isYYYYMMDD(value) === false) {
542
- throw new InputErrorException("251", this.ErrorMessage("251", keys, value));
582
+ this.throwInputError(isRequestBody ? "DATE_21" : "DATE_91", keys, value);
543
583
  }
544
584
 
545
585
  if (this.isErrorDateTime(value)) {
546
- throw new InputErrorException("252", this.ErrorMessage("252", keys, value));
586
+ this.throwInputError(isRequestBody ? "DATE_22" : "DATE_92", keys, value);
547
587
  }
548
588
  return value;
549
589
  case 'time':
@@ -551,7 +591,7 @@ export class RequestType extends ReqResType {
551
591
  if (this.isHHMM(value)) {
552
592
  return `${value}`;
553
593
  }
554
- throw new InputErrorException("261", this.ErrorMessage("261", keys, value));
594
+ this.throwInputError(isRequestBody ? "TIME_21" : "TIME_91", keys, value);
555
595
  case 'datetime':
556
596
  case 'datetime?':
557
597
  if (this.isYYYYMMDDhhmi(value)) {
@@ -559,11 +599,11 @@ export class RequestType extends ReqResType {
559
599
  }
560
600
 
561
601
  if (this.isYYYYMMDDhhmiss(value) === false) {
562
- throw new InputErrorException("271", this.ErrorMessage("271", keys, value));
602
+ this.throwInputError(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys, value);
563
603
  }
564
604
 
565
605
  if (this.isErrorDateTime(value)) {
566
- throw new InputErrorException("272", this.ErrorMessage("272", keys, value));
606
+ this.throwInputError(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys, value);
567
607
  }
568
608
  return value.replace('T', ' ');
569
609
  case 'https':
@@ -571,13 +611,13 @@ export class RequestType extends ReqResType {
571
611
  if (this.isHttps(value)) {
572
612
  return value;
573
613
  }
574
- throw new InputErrorException("281", this.ErrorMessage("281", keys, value));
614
+ this.throwInputError(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys, value);
575
615
  case 'base64':
576
616
  case 'base64?':
577
617
  if (this.isBase64(value)) {
578
618
  return value;
579
619
  }
580
- throw new InputErrorException("291", this.ErrorMessage("291", keys, value));
620
+ this.throwInputError(isRequestBody ? "BASE64_21" : "BASE64_91", keys, value);
581
621
  }
582
622
 
583
623
  return value;
@@ -597,7 +637,7 @@ export class RequestType extends ReqResType {
597
637
  */
598
638
  private convertInput(keys: Array<string | number>, value: any) {
599
639
  const property = this.getProperty(keys);
600
- this.changeBody(keys, this.convertValue(property.type, value, keys));
640
+ this.changeBody(keys, this.convertValue(property.type, value, keys, true));
601
641
  }
602
642
 
603
643