pg-mvc-service 2.0.37 → 2.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Service.js CHANGED
@@ -140,6 +140,13 @@ class Service {
140
140
  });
141
141
  return;
142
142
  }
143
+ else if (ex instanceof Exception_1.NotFoundException) {
144
+ this.res.status(404).json({
145
+ errorCode: `${this.apiCode}-${ex.ErrorId}`,
146
+ errorMessage: ex.message
147
+ });
148
+ return;
149
+ }
143
150
  this.res.status(500).json({
144
151
  message: 'Internal server error'
145
152
  });
@@ -260,7 +267,7 @@ class Service {
260
267
  }
261
268
  catch (ex) {
262
269
  let response = ex.response;
263
- if (response && [400, 401, 403, 409, 422].includes(response.status)) {
270
+ if (response && [400, 401, 403, 404, 409, 422].includes(response.status)) {
264
271
  return response;
265
272
  }
266
273
  throw ex;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
3
+ exports.runCron = exports.BaseCron = exports.rollback = exports.migrate = exports.MigrateDatabase = exports.MigrateTable = exports.createTableDoc = exports.TableModel = exports.ResponseType = exports.RequestType = exports.EncryptClient = exports.StringClient = exports.Base64Client = exports.AwsS3Client = exports.createSwagger = exports.NotFoundException = exports.UnprocessableException = exports.DbConflictException = exports.ForbiddenException = exports.InputErrorException = exports.AuthException = exports.MaintenanceException = exports.Service = void 0;
4
4
  var Service_1 = require("./Service");
5
5
  Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return Service_1.Service; } });
6
6
  var Exception_1 = require("./exceptions/Exception");
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "InputErrorException", { enumerable: true, get: f
10
10
  Object.defineProperty(exports, "ForbiddenException", { enumerable: true, get: function () { return Exception_1.ForbiddenException; } });
11
11
  Object.defineProperty(exports, "DbConflictException", { enumerable: true, get: function () { return Exception_1.DbConflictException; } });
12
12
  Object.defineProperty(exports, "UnprocessableException", { enumerable: true, get: function () { return Exception_1.UnprocessableException; } });
13
+ Object.defineProperty(exports, "NotFoundException", { enumerable: true, get: function () { return Exception_1.NotFoundException; } });
13
14
  var Swagger_1 = require("./documents/Swagger");
14
15
  Object.defineProperty(exports, "createSwagger", { enumerable: true, get: function () { return Swagger_1.createSwagger; } });
15
16
  var AwsS3Client_1 = require("./clients/AwsS3Client");
@@ -217,7 +217,7 @@ td:nth-child(11) {
217
217
  html += `
218
218
  <div class="table-wrapper">
219
219
  <div class="table-title-wrapper">
220
- <div class="table-title-left">${model.TableName} ${model.TableDescription !== '' ? ` : ${model.TableDescription}` : ''}</div>
220
+ <div class="table-title-left">${model.Id !== "" ? `[${model.Id}] ` : ""}${model.TableName} ${model.TableDescription !== '' ? ` : ${model.TableDescription}` : ''}</div>
221
221
  <button class="table-title-right" onclick="${createFuncName}()">Copy Create Query</button>
222
222
  </div>
223
223
  <div class="comment-wrapper">${model.Comment.replace('\n', '<br>')}</div>
@@ -22,6 +22,7 @@ const ExpressionClient_1 = __importDefault(require("./ExpressionClient"));
22
22
  const UpdateExpression_1 = __importDefault(require("./SqlUtils/UpdateExpression"));
23
23
  const MessageUtil_1 = __importDefault(require("./Utils/MessageUtil"));
24
24
  class TableModel {
25
+ get Id() { return this.id; }
25
26
  get DbName() { return this.dbName; }
26
27
  get TableName() {
27
28
  if (this.tableName === "") {
@@ -98,6 +99,7 @@ class TableModel {
98
99
  return this.client;
99
100
  }
100
101
  constructor(client, tableAlias) {
102
+ this.id = "";
101
103
  this.dbName = "default";
102
104
  this.tableName = "";
103
105
  this.tableDescription = "";
@@ -344,7 +346,13 @@ class TableModel {
344
346
  if (message.includes("{length}") && (column.type === 'string' || column.type === 'string[]')) {
345
347
  message = message.replace('{length}', ((_a = column.length) !== null && _a !== void 0 ? _a : '未設定').toString());
346
348
  }
347
- throw new Exception_1.UnprocessableException(code, message);
349
+ this.throwUnprocessableException(code, message);
350
+ }
351
+ throwDbCoflictException(code, message) {
352
+ throw new Exception_1.DbConflictException(`${this.id}-${code}`, message);
353
+ }
354
+ throwUnprocessableException(code, message) {
355
+ throw new Exception_1.UnprocessableException(`${this.id}-${code}`, message);
348
356
  }
349
357
  validateOptions(options, isInsert, pkOrId) {
350
358
  return __awaiter(this, void 0, void 0, function* () {
@@ -406,14 +414,14 @@ class TableModel {
406
414
  // 一部の値がnullの場合はエラー
407
415
  if (refValues.some(value => value === null || value === undefined)) {
408
416
  const name = ref.columns.map(col => { var _a; return (_a = this.getColumn(col.target).alias) !== null && _a !== void 0 ? _a : this.getColumn(col.target).columnName; }).join(',');
409
- throw new Exception_1.UnprocessableException("006", this.errorMessages.null.replace('{name}', name));
417
+ this.throwUnprocessableException("006", this.errorMessages.null.replace('{name}', name));
410
418
  }
411
419
  let refIndex = 1;
412
420
  const sql = `SELECT COUNT(*) as count FROM ${ref.table} WHERE ${ref.columns.map(col => `${col.ref} = $${refIndex++}`).join(" AND ")}`;
413
421
  const datas = yield this.clientQuery(sql, refValues);
414
422
  if (datas.rows[0].count == "0") {
415
423
  const name = ref.columns.map(col => { var _a; return (_a = this.getColumn(col.target).alias) !== null && _a !== void 0 ? _a : this.getColumn(col.target).columnName; }).join(',');
416
- throw new Exception_1.DbConflictException("007", this.errorMessages.fk.replace('{name}', name));
424
+ this.throwDbCoflictException("007", this.errorMessages.fk.replace('{name}', name));
417
425
  }
418
426
  }
419
427
  }
@@ -452,7 +460,7 @@ class TableModel {
452
460
  const sql = updateSetQuery.expression + ' WHERE ' + whereQuery.expression;
453
461
  const data = yield this.executeQuery(sql, whereQuery.vars);
454
462
  if (data.rowCount !== 1) {
455
- throw new Exception_1.UnprocessableException("201", this.errorMessages.find.replace('{pks}', ((_a = whereQuery.vars) !== null && _a !== void 0 ? _a : []).join(',')));
463
+ this.throwUnprocessableException("201", this.errorMessages.find.replace('{pks}', ((_a = whereQuery.vars) !== null && _a !== void 0 ? _a : []).join(',')));
456
464
  }
457
465
  });
458
466
  }
@@ -470,7 +478,7 @@ class TableModel {
470
478
  const sql = `DELETE FROM ${this.TableName} WHERE ${whereQuery.expression}`;
471
479
  const data = yield this.executeQuery(sql, whereQuery.vars);
472
480
  if (data.rowCount !== 1) {
473
- throw new Exception_1.UnprocessableException("301", this.errorMessages.find.replace('{pks}', ((_a = whereQuery.vars) !== null && _a !== void 0 ? _a : []).join(',')));
481
+ this.throwUnprocessableException("301", this.errorMessages.find.replace('{pks}', ((_a = whereQuery.vars) !== null && _a !== void 0 ? _a : []).join(',')));
474
482
  }
475
483
  });
476
484
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.37",
3
+ "version": "2.0.39",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
package/src/Service.ts CHANGED
@@ -121,6 +121,12 @@ export class Service {
121
121
  errorMessage : ex.message
122
122
  });
123
123
  return;
124
+ } else if (ex instanceof NotFoundException) {
125
+ this.res.status(404).json({
126
+ errorCode : `${this.apiCode}-${ex.ErrorId}`,
127
+ errorMessage : ex.message
128
+ });
129
+ return;
124
130
  }
125
131
 
126
132
  this.res.status(500).json({
@@ -254,7 +260,7 @@ export class Service {
254
260
  }
255
261
  } catch (ex) {
256
262
  let response = (ex as any).response as AxiosResponse<TResponse>;
257
- if (response && [400, 401, 403, 409, 422].includes(response.status)) {
263
+ if (response && [400, 401, 403, 404, 409, 422].includes(response.status)) {
258
264
  return response;
259
265
  }
260
266
  throw ex;
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Service } from './Service';
2
- export { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException } from './exceptions/Exception';
2
+ export { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException, NotFoundException } from './exceptions/Exception';
3
3
  export { createSwagger } from './documents/Swagger';
4
4
  export { AwsS3Client } from './clients/AwsS3Client';
5
5
  export { Base64Client } from './clients/Base64Client';
@@ -219,7 +219,7 @@ td:nth-child(11) {
219
219
  html += `
220
220
  <div class="table-wrapper">
221
221
  <div class="table-title-wrapper">
222
- <div class="table-title-left">${model.TableName} ${model.TableDescription !== '' ? ` : ${model.TableDescription}` : ''}</div>
222
+ <div class="table-title-left">${model.Id !== "" ? `[${model.Id}] ` : ""}${model.TableName} ${model.TableDescription !== '' ? ` : ${model.TableDescription}` : ''}</div>
223
223
  <button class="table-title-right" onclick="${createFuncName}()">Copy Create Query</button>
224
224
  </div>
225
225
  <div class="comment-wrapper">${model.Comment.replace('\n', '<br>')}</div>
@@ -11,6 +11,8 @@ import MessageUtil, { TOptionErrorMessage } from './Utils/MessageUtil';
11
11
 
12
12
  export class TableModel {
13
13
 
14
+ protected readonly id: string = "";
15
+ get Id(): string { return this.id; }
14
16
  protected readonly dbName: string = "default";
15
17
  get DbName(): string { return this.dbName; }
16
18
  protected readonly tableName: string = "";
@@ -406,7 +408,15 @@ export class TableModel {
406
408
  message = message.replace('{length}', (column.length ?? '未設定').toString());
407
409
  }
408
410
 
409
- throw new UnprocessableException(code, message);
411
+ this.throwUnprocessableException(code, message);
412
+ }
413
+
414
+ protected throwDbCoflictException(code: string, message: string): never {
415
+ throw new DbConflictException(`${this.id}-${code}`, message);
416
+ }
417
+
418
+ protected throwUnprocessableException(code: string, message: string): never {
419
+ throw new UnprocessableException(`${this.id}-${code}`, message);
410
420
  }
411
421
 
412
422
  protected async validateOptions(options: {[key: string]: any}, isInsert: boolean, pkOrId?: string | number | boolean | {[key: string]: any}): Promise<void> {
@@ -476,7 +486,7 @@ export class TableModel {
476
486
  // 一部の値がnullの場合はエラー
477
487
  if (refValues.some(value => value === null || value === undefined)) {
478
488
  const name = ref.columns.map(col => this.getColumn(col.target).alias ?? this.getColumn(col.target).columnName).join(',');
479
- throw new UnprocessableException("006", this.errorMessages.null.replace('{name}', name));
489
+ this.throwUnprocessableException("006", this.errorMessages.null.replace('{name}', name));
480
490
  }
481
491
 
482
492
  let refIndex = 1;
@@ -484,7 +494,7 @@ export class TableModel {
484
494
  const datas = await this.clientQuery(sql, refValues);
485
495
  if (datas.rows[0].count == "0") {
486
496
  const name = ref.columns.map(col => this.getColumn(col.target).alias ?? this.getColumn(col.target).columnName).join(',');
487
- throw new DbConflictException("007", this.errorMessages.fk.replace('{name}', name));
497
+ this.throwDbCoflictException("007", this.errorMessages.fk.replace('{name}', name))
488
498
  }
489
499
  }
490
500
  }
@@ -525,7 +535,7 @@ export class TableModel {
525
535
  const sql = updateSetQuery.expression + ' WHERE ' + whereQuery.expression;
526
536
  const data = await this.executeQuery(sql, whereQuery.vars);
527
537
  if (data.rowCount !== 1) {
528
- throw new UnprocessableException("201", this.errorMessages.find.replace('{pks}', (whereQuery.vars ?? []).join(',')));
538
+ this.throwUnprocessableException("201", this.errorMessages.find.replace('{pks}', (whereQuery.vars ?? []).join(',')));
529
539
  }
530
540
  }
531
541
 
@@ -541,7 +551,7 @@ export class TableModel {
541
551
  const sql = `DELETE FROM ${this.TableName} WHERE ${whereQuery.expression}`;
542
552
  const data = await this.executeQuery(sql, whereQuery.vars);
543
553
  if (data.rowCount !== 1) {
544
- throw new UnprocessableException("301", this.errorMessages.find.replace('{pks}', (whereQuery.vars ?? []).join(',')));
554
+ this.throwUnprocessableException("301", this.errorMessages.find.replace('{pks}', (whereQuery.vars ?? []).join(',')));
545
555
  }
546
556
  }
547
557