pg-mvc-service 1.0.11 → 1.0.12
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.
|
@@ -15,22 +15,42 @@ class RequestType extends ReqResType_1.default {
|
|
|
15
15
|
// エラー文言
|
|
16
16
|
// エラーメッセージの変更はサブクラスで行ってください
|
|
17
17
|
// *****************************************
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
this.ERROR_MESSAGE_ENGLISH = {
|
|
19
|
+
REQUIRED: '{property} is required.',
|
|
20
|
+
UNNECESSARY: '{property} is unnecessary input. ',
|
|
21
|
+
INVALID_OBJECT: '{property} must be of type Object. ({value})',
|
|
22
|
+
INVALID_ARRAY: '{property} must be of type Array. ({value})',
|
|
23
|
+
INVALID_NUMBER: '{property} must be of type number. ({value})',
|
|
24
|
+
INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
|
|
25
|
+
INVALID_STRING: '{property} must be of type string. ({value})',
|
|
26
|
+
INVALID_UUID: '{property} must be a UUID. ({value})',
|
|
27
|
+
INVALID_MAIL: '{property} must be an email. ({value})',
|
|
28
|
+
INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
|
|
29
|
+
INVALID_DATE: '{property} must be a string in "YYYY-MM-DD" format and a valid date. ({value})',
|
|
30
|
+
INVALID_TIME: '{property} must be a string in "hh:mi" format and a valid time. ({value})',
|
|
31
|
+
INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
|
|
32
|
+
INVALID_BASE64: '{property} must be in Base64 format. ({value})',
|
|
33
|
+
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
34
|
+
};
|
|
35
|
+
this.ERROR_MESSAGE_JAPAN = {
|
|
36
|
+
BODY_REQUIRED: 'リクエストボディが必要です。',
|
|
37
|
+
REQUIRED: '{property}は必須項目です。',
|
|
38
|
+
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})'
|
|
52
|
+
};
|
|
53
|
+
this.ERROR_MESSAGE = process.env.TZ === 'Tokyo/Asia' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
34
54
|
}
|
|
35
55
|
get Params() {
|
|
36
56
|
var _a;
|
|
@@ -64,15 +84,18 @@ class RequestType extends ReqResType_1.default {
|
|
|
64
84
|
setRequest(request) {
|
|
65
85
|
var _a, _b, _c;
|
|
66
86
|
this.createBody(request);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
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
|
+
// }
|
|
76
99
|
this.params = (_a = request.params) !== null && _a !== void 0 ? _a : {};
|
|
77
100
|
this.headers = (_b = request.headers) !== null && _b !== void 0 ? _b : {};
|
|
78
101
|
this.remoteAddress = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress;
|
|
@@ -87,44 +110,42 @@ class RequestType extends ReqResType_1.default {
|
|
|
87
110
|
*/
|
|
88
111
|
ErrorMessage(code, keys, value) {
|
|
89
112
|
const list = {
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"211": this.
|
|
103
|
-
"212": this.
|
|
104
|
-
"213": this.
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
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,
|
|
120
144
|
};
|
|
121
|
-
let errorMessage =
|
|
145
|
+
let errorMessage = list[code];
|
|
122
146
|
if (code === "401" || code === "402") {
|
|
123
147
|
const property = this.getProperty(keys);
|
|
124
|
-
errorMessage =
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
errorMessage = list[code];
|
|
148
|
+
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
128
149
|
}
|
|
129
150
|
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
|
|
130
151
|
return errorMessage;
|
package/package.json
CHANGED
|
@@ -10,22 +10,42 @@ export class RequestType extends ReqResType {
|
|
|
10
10
|
// エラー文言
|
|
11
11
|
// エラーメッセージの変更はサブクラスで行ってください
|
|
12
12
|
// *****************************************
|
|
13
|
-
public readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
public readonly ERROR_MESSAGE_ENGLISH = {
|
|
14
|
+
REQUIRED: '{property} is required.',
|
|
15
|
+
UNNECESSARY: '{property} is unnecessary input. ',
|
|
16
|
+
INVALID_OBJECT: '{property} must be of type Object. ({value})',
|
|
17
|
+
INVALID_ARRAY: '{property} must be of type Array. ({value})',
|
|
18
|
+
INVALID_NUMBER: '{property} must be of type number. ({value})',
|
|
19
|
+
INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
|
|
20
|
+
INVALID_STRING: '{property} must be of type string. ({value})',
|
|
21
|
+
INVALID_UUID: '{property} must be a UUID. ({value})',
|
|
22
|
+
INVALID_MAIL: '{property} must be an email. ({value})',
|
|
23
|
+
INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
|
|
24
|
+
INVALID_DATE: '{property} must be a string in "YYYY-MM-DD" format and a valid date. ({value})',
|
|
25
|
+
INVALID_TIME: '{property} must be a string in "hh:mi" format and a valid time. ({value})',
|
|
26
|
+
INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
|
|
27
|
+
INVALID_BASE64: '{property} must be in Base64 format. ({value})',
|
|
28
|
+
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
29
|
+
}
|
|
30
|
+
public readonly ERROR_MESSAGE_JAPAN = {
|
|
31
|
+
BODY_REQUIRED: 'リクエストボディが必要です。',
|
|
32
|
+
REQUIRED: '{property}は必須項目です。',
|
|
33
|
+
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})'
|
|
47
|
+
}
|
|
48
|
+
public readonly ERROR_MESSAGE = process.env.TZ === 'Tokyo/Asia' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
29
49
|
|
|
30
50
|
private params?: {[key: string]: any};
|
|
31
51
|
get Params(): {[key: string]: any} {
|
|
@@ -60,15 +80,18 @@ export class RequestType extends ReqResType {
|
|
|
60
80
|
|
|
61
81
|
public setRequest(request: Request) {
|
|
62
82
|
this.createBody(request);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
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
|
+
// }
|
|
72
95
|
this.params = request.params ?? {};
|
|
73
96
|
this.headers = request.headers ?? {};
|
|
74
97
|
|
|
@@ -83,49 +106,49 @@ export class RequestType extends ReqResType {
|
|
|
83
106
|
* @param {any} value - The value that caused the error. エラーを引き起こした値
|
|
84
107
|
* @returns {string} The generated error message. 生成されたエラーメッセージ
|
|
85
108
|
*/
|
|
86
|
-
private ErrorMessage(code: "
|
|
109
|
+
private ErrorMessage(code: "000" | "001" | "002" | "003" | "004" | "101" | "102" | "103" | "104" |
|
|
87
110
|
"201" | "211" | "212" | "213" | "221" | "231" | "241" | "251" | "252" |
|
|
88
111
|
"261" | "271" | "272" | "281" | "291" | "301" | "401" | "402" | "411" | "421" | "422" | "423" | "431", keys: Array<string | number>, value: any): string {
|
|
89
112
|
const list = {
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"211": this.
|
|
103
|
-
"212": this.
|
|
104
|
-
"213": this.
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
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,
|
|
120
144
|
}
|
|
121
145
|
|
|
122
|
-
let errorMessage =
|
|
146
|
+
let errorMessage = list[code];
|
|
123
147
|
if (code === "401" || code === "402") {
|
|
124
148
|
const property = this.getProperty(keys);
|
|
125
|
-
errorMessage =
|
|
126
|
-
} else {
|
|
127
|
-
errorMessage = list[code];
|
|
149
|
+
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
128
150
|
}
|
|
151
|
+
|
|
129
152
|
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value)
|
|
130
153
|
return errorMessage;
|
|
131
154
|
}
|