pg-mvc-service 2.0.115 → 2.0.117

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.
@@ -1040,7 +1040,7 @@ class RequestType extends ReqResType_1.default {
1040
1040
  code: code + '-OBJECT_01',
1041
1041
  description: this.createErrorMessage('OBJECT_01', [key])
1042
1042
  });
1043
- // TODO: obj
1043
+ errorList = [...errorList, ...this.getErrorObject([key], code)];
1044
1044
  break;
1045
1045
  case 'array':
1046
1046
  case 'array?':
@@ -1049,7 +1049,7 @@ class RequestType extends ReqResType_1.default {
1049
1049
  code: code + '-ARRAY_01',
1050
1050
  description: this.createErrorMessage('ARRAY_01', [key])
1051
1051
  });
1052
- // TODO: Arr
1052
+ errorList = [...errorList, ...this.getErrorArray([key], code)];
1053
1053
  break;
1054
1054
  case 'map':
1055
1055
  case 'map?':
@@ -1094,6 +1094,144 @@ class RequestType extends ReqResType_1.default {
1094
1094
  }
1095
1095
  return errorList;
1096
1096
  }
1097
+ getErrorObject(keys, code) {
1098
+ let errorList = [];
1099
+ const property = this.getProperty(keys);
1100
+ if (property.type !== 'object' && property.type !== 'object?') {
1101
+ throw new Error(`sgetErrorObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
1102
+ }
1103
+ for (const key of Object.keys(property.properties)) {
1104
+ if (property.properties[key].type.endsWith('?') === false) {
1105
+ errorList.push({
1106
+ status: 400,
1107
+ code: code + '-REQUIRE_11',
1108
+ description: this.createErrorMessage('REQUIRE_11', [...keys, key]),
1109
+ });
1110
+ }
1111
+ switch (property.properties[key].type) {
1112
+ case 'object':
1113
+ case 'object?':
1114
+ errorList.push({
1115
+ status: 400,
1116
+ code: code + '-OBJECT_11',
1117
+ description: this.createErrorMessage('OBJECT_11', [...keys, key]),
1118
+ });
1119
+ errorList = [...errorList, ...this.getErrorObject([...keys, key], code)];
1120
+ break;
1121
+ case 'array':
1122
+ case 'array?':
1123
+ errorList.push({
1124
+ status: 400,
1125
+ code: code + '-ARRAY_11',
1126
+ description: this.createErrorMessage('ARRAY_11', [...keys, key]),
1127
+ });
1128
+ errorList = [...errorList, ...this.getErrorArray([key], code)];
1129
+ break;
1130
+ case 'map':
1131
+ case 'map?':
1132
+ switch (property.properties[key].mapType) {
1133
+ case 'number':
1134
+ errorList.push({
1135
+ status: 400,
1136
+ code: code + '-MAP_11',
1137
+ description: this.createErrorMessage('MAP_11', [key])
1138
+ });
1139
+ break;
1140
+ case 'string':
1141
+ errorList.push({
1142
+ status: 400,
1143
+ code: code + '-MAP_12',
1144
+ description: this.createErrorMessage('MAP_12', [key])
1145
+ });
1146
+ break;
1147
+ case 'bool':
1148
+ errorList.push({
1149
+ status: 400,
1150
+ code: code + '-MAP_13',
1151
+ description: this.createErrorMessage('MAP_13', [key])
1152
+ });
1153
+ errorList.push({
1154
+ status: 400,
1155
+ code: code + '-MAP_14',
1156
+ description: this.createErrorMessage('MAP_14', [key])
1157
+ });
1158
+ errorList.push({
1159
+ status: 400,
1160
+ code: code + '-MAP_15',
1161
+ description: this.createErrorMessage('MAP_15', [key])
1162
+ });
1163
+ break;
1164
+ }
1165
+ break;
1166
+ default:
1167
+ errorList = [...errorList, ...this.getError([...keys, key], code, false)];
1168
+ break;
1169
+ }
1170
+ }
1171
+ return errorList;
1172
+ }
1173
+ getErrorArray(keys, code) {
1174
+ let errorList = [];
1175
+ const property = this.getProperty(keys);
1176
+ if (property.type !== 'array' && property.type !== 'array?') {
1177
+ throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
1178
+ }
1179
+ errorList.push({
1180
+ status: 400,
1181
+ code: code + '-REQUIRE_31',
1182
+ description: this.createErrorMessage('REQUIRE_31', [...keys]),
1183
+ });
1184
+ switch (property.item.type) {
1185
+ case 'object':
1186
+ case 'object?':
1187
+ errorList = [...errorList, ...this.getErrorObject([...keys, 0], code)];
1188
+ break;
1189
+ case 'array':
1190
+ case 'array?':
1191
+ errorList = [...errorList, ...this.getErrorArray([...keys, 0], code)];
1192
+ break;
1193
+ case 'map':
1194
+ case 'map?':
1195
+ switch (property.item.mapType) {
1196
+ case 'number':
1197
+ errorList.push({
1198
+ status: 400,
1199
+ code: code + '-MAP_11',
1200
+ description: this.createErrorMessage('MAP_31', [...keys, 0])
1201
+ });
1202
+ break;
1203
+ case 'string':
1204
+ errorList.push({
1205
+ status: 400,
1206
+ code: code + '-MAP_12',
1207
+ description: this.createErrorMessage('MAP_32', [...keys, 0])
1208
+ });
1209
+ break;
1210
+ case 'bool':
1211
+ errorList.push({
1212
+ status: 400,
1213
+ code: code + '-MAP_13',
1214
+ description: this.createErrorMessage('MAP_33', [...keys, 0])
1215
+ });
1216
+ errorList.push({
1217
+ status: 400,
1218
+ code: code + '-MAP_14',
1219
+ description: this.createErrorMessage('MAP_34', [...keys, 0])
1220
+ });
1221
+ errorList.push({
1222
+ status: 400,
1223
+ code: code + '-MAP_15',
1224
+ description: this.createErrorMessage('MAP_35', [...keys, 0])
1225
+ });
1226
+ break;
1227
+ }
1228
+ break;
1229
+ default:
1230
+ errorList = [...errorList, ...this.getError([...keys, 0], code, false)];
1231
+ break;
1232
+ }
1233
+ return errorList;
1234
+ }
1097
1235
  getError(keys, code, isRequestBody) {
1098
1236
  const errorList = [];
1099
1237
  const property = this.getProperty(keys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.115",
3
+ "version": "2.0.117",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -1142,7 +1142,8 @@ export class RequestType extends ReqResType {
1142
1142
  code: code + '-OBJECT_01',
1143
1143
  description: this.createErrorMessage('OBJECT_01', [key])
1144
1144
  });
1145
- // TODO: obj
1145
+
1146
+ errorList = [...errorList, ...this.getErrorObject([key], code)];
1146
1147
  break;
1147
1148
  case 'array':
1148
1149
  case 'array?':
@@ -1151,7 +1152,8 @@ export class RequestType extends ReqResType {
1151
1152
  code: code + '-ARRAY_01',
1152
1153
  description: this.createErrorMessage('ARRAY_01', [key])
1153
1154
  });
1154
- // TODO: Arr
1155
+
1156
+ errorList = [...errorList, ...this.getErrorArray([key], code)];
1155
1157
  break;
1156
1158
  case 'map':
1157
1159
  case 'map?':
@@ -1198,7 +1200,157 @@ export class RequestType extends ReqResType {
1198
1200
  return errorList;
1199
1201
  }
1200
1202
 
1201
- private getError(keys: Array<string | number>, code: string, isRequestBody: boolean) {
1203
+ private getErrorObject(keys: Array<string | number>, code: string): Array<IError> {
1204
+ let errorList: Array<IError> = [];
1205
+
1206
+ const property = this.getProperty(keys);
1207
+ if (property.type !== 'object' && property.type !== 'object?') {
1208
+ throw new Error(`sgetErrorObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
1209
+ }
1210
+
1211
+ for (const key of Object.keys(property.properties)) {
1212
+ if (property.properties[key].type.endsWith('?') === false) {
1213
+ errorList.push({
1214
+ status: 400,
1215
+ code: code + '-REQUIRE_11',
1216
+ description: this.createErrorMessage('REQUIRE_11', [...keys, key]),
1217
+ });
1218
+ }
1219
+
1220
+ switch (property.properties[key].type) {
1221
+ case 'object':
1222
+ case 'object?':
1223
+ errorList.push({
1224
+ status: 400,
1225
+ code: code + '-OBJECT_11',
1226
+ description: this.createErrorMessage('OBJECT_11', [...keys, key]),
1227
+ });
1228
+
1229
+ errorList = [...errorList, ...this.getErrorObject([...keys, key], code)];
1230
+ break;
1231
+ case 'array':
1232
+ case 'array?':
1233
+ errorList.push({
1234
+ status: 400,
1235
+ code: code + '-ARRAY_11',
1236
+ description: this.createErrorMessage('ARRAY_11', [...keys, key]),
1237
+ });
1238
+
1239
+ errorList = [...errorList, ...this.getErrorArray([key], code)];
1240
+ break;
1241
+ case 'map':
1242
+ case 'map?':
1243
+ switch (property.properties[key].mapType) {
1244
+ case 'number':
1245
+ errorList.push({
1246
+ status: 400,
1247
+ code: code + '-MAP_11',
1248
+ description: this.createErrorMessage('MAP_11', [key])
1249
+ });
1250
+ break;
1251
+ case 'string':
1252
+ errorList.push({
1253
+ status: 400,
1254
+ code: code + '-MAP_12',
1255
+ description: this.createErrorMessage('MAP_12', [key])
1256
+ });
1257
+ break;
1258
+ case 'bool':
1259
+ errorList.push({
1260
+ status: 400,
1261
+ code: code + '-MAP_13',
1262
+ description: this.createErrorMessage('MAP_13', [key])
1263
+ });
1264
+ errorList.push({
1265
+ status: 400,
1266
+ code: code + '-MAP_14',
1267
+ description: this.createErrorMessage('MAP_14', [key])
1268
+ });
1269
+ errorList.push({
1270
+ status: 400,
1271
+ code: code + '-MAP_15',
1272
+ description: this.createErrorMessage('MAP_15', [key])
1273
+ });
1274
+ break;
1275
+ }
1276
+ break;
1277
+ default:
1278
+ errorList = [...errorList, ...this.getError([...keys, key], code, false)];
1279
+ break;
1280
+ }
1281
+ }
1282
+
1283
+ return errorList;
1284
+ }
1285
+
1286
+ private getErrorArray(keys: Array<string | number>, code: string) {
1287
+ let errorList: Array<IError> = [];
1288
+
1289
+ const property = this.getProperty(keys);
1290
+ if (property.type !== 'array' && property.type !== 'array?') {
1291
+ throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
1292
+ }
1293
+
1294
+ errorList.push({
1295
+ status: 400,
1296
+ code: code + '-REQUIRE_31',
1297
+ description: this.createErrorMessage('REQUIRE_31', [...keys]),
1298
+ });
1299
+
1300
+ switch (property.item.type) {
1301
+ case 'object':
1302
+ case 'object?':
1303
+ errorList = [...errorList, ...this.getErrorObject([...keys, 0], code)];
1304
+ break;
1305
+ case 'array':
1306
+ case 'array?':
1307
+ errorList = [...errorList, ...this.getErrorArray([...keys, 0], code)];
1308
+ break;
1309
+ case 'map':
1310
+ case 'map?':
1311
+ switch (property.item.mapType) {
1312
+ case 'number':
1313
+ errorList.push({
1314
+ status: 400,
1315
+ code: code + '-MAP_11',
1316
+ description: this.createErrorMessage('MAP_31', [...keys, 0])
1317
+ });
1318
+ break;
1319
+ case 'string':
1320
+ errorList.push({
1321
+ status: 400,
1322
+ code: code + '-MAP_12',
1323
+ description: this.createErrorMessage('MAP_32', [...keys, 0])
1324
+ });
1325
+ break;
1326
+ case 'bool':
1327
+ errorList.push({
1328
+ status: 400,
1329
+ code: code + '-MAP_13',
1330
+ description: this.createErrorMessage('MAP_33', [...keys, 0])
1331
+ });
1332
+ errorList.push({
1333
+ status: 400,
1334
+ code: code + '-MAP_14',
1335
+ description: this.createErrorMessage('MAP_34', [...keys, 0])
1336
+ });
1337
+ errorList.push({
1338
+ status: 400,
1339
+ code: code + '-MAP_15',
1340
+ description: this.createErrorMessage('MAP_35', [...keys, 0])
1341
+ });
1342
+ break;
1343
+ }
1344
+ break;
1345
+ default:
1346
+ errorList = [...errorList, ...this.getError([...keys, 0], code, false)];
1347
+ break;
1348
+ }
1349
+
1350
+ return errorList;
1351
+ }
1352
+
1353
+ private getError(keys: Array<string | number>, code: string, isRequestBody: boolean): Array<IError> {
1202
1354
  const errorList: Array<IError> = [];
1203
1355
  const property = this.getProperty(keys);
1204
1356
  switch (property.type) {