pg-mvc-service 1.0.6 → 1.0.8

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
@@ -127,7 +127,7 @@ class Service {
127
127
  });
128
128
  return;
129
129
  }
130
- else if (ex instanceof Exception_1.BusinessLogicException) {
130
+ else if (ex instanceof Exception_1.UnprocessableException) {
131
131
  this.res.status(422).json({
132
132
  errorCode: `${this.apiCode}-${ex.ErrorId}`,
133
133
  errorMessage: ex.message
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BusinessLogicException = exports.DbConflictException = exports.MaintenanceException = exports.InputErrorException = exports.ForbiddenException = exports.AuthException = void 0;
3
+ exports.UnprocessableException = exports.DbConflictException = exports.MaintenanceException = exports.InputErrorException = exports.ForbiddenException = exports.AuthException = void 0;
4
4
  class AuthException extends Error {
5
5
  get Id() {
6
6
  return this.id;
@@ -44,7 +44,7 @@ class DbConflictException extends Error {
44
44
  }
45
45
  }
46
46
  exports.DbConflictException = DbConflictException;
47
- class BusinessLogicException extends Error {
47
+ class UnprocessableException extends Error {
48
48
  get ErrorId() {
49
49
  return this.errorId;
50
50
  }
@@ -55,4 +55,4 @@ class BusinessLogicException extends Error {
55
55
  this.errorId = errorId;
56
56
  }
57
57
  }
58
- exports.BusinessLogicException = BusinessLogicException;
58
+ exports.UnprocessableException = UnprocessableException;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "AuthException", { enumerable: true, get: functio
9
9
  Object.defineProperty(exports, "InputErrorException", { enumerable: true, get: function () { return Exception_1.InputErrorException; } });
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
- Object.defineProperty(exports, "BusinessLogicException", { enumerable: true, get: function () { return Exception_1.BusinessLogicException; } });
12
+ Object.defineProperty(exports, "BusinessLogicException", { enumerable: true, get: function () { return Exception_1.UnprocessableException; } });
13
13
  var Swagger_1 = require("./documents/Swagger");
14
14
  Object.defineProperty(exports, "createSwagger", { enumerable: true, get: function () { return Swagger_1.createSwagger; } });
15
15
  var AwsS3Client_1 = require("./clients/AwsS3Client");
@@ -366,9 +366,6 @@ class TableModel {
366
366
  return { datas: data.rows, count: Number(countData.rows[0].count), lastPage: Math.ceil(Number(countData.rows[0].count) / this.PageCount) };
367
367
  });
368
368
  }
369
- throwValidationError(code, message) {
370
- throw new Exception_1.InputErrorException(code, message);
371
- }
372
369
  validateOptions(options, isInsert) {
373
370
  return __awaiter(this, void 0, void 0, function* () {
374
371
  if (Object.keys(options).length === 0) {
@@ -384,17 +381,17 @@ class TableModel {
384
381
  if (column.attribute === 'nullable') {
385
382
  continue;
386
383
  }
387
- this.throwValidationError("001", this.errorMessages.null.replace('{name}', name));
384
+ throw new Exception_1.UnprocessableException("001", this.errorMessages.null.replace('{name}', name));
388
385
  }
389
386
  if (ValidateValueUtil_1.default.isErrorValue(column.type, value)) {
390
- this.throwValidationError("002", this.errorMessages[column.type].replace('{name}', name));
387
+ throw new Exception_1.UnprocessableException("002", this.errorMessages[column.type].replace('{name}', name));
391
388
  }
392
389
  if (column.type === 'string') {
393
390
  if (Number.isInteger(column.length) === false) {
394
391
  throw new Error(`For strings, please specify the length of the column.(column: ${column.columnName})`);
395
392
  }
396
393
  if (value.toString().length > column.length) {
397
- this.throwValidationError("003", this.errorMessages.length.replace('{name}', name).replace('{length}', column.toString()));
394
+ throw new Exception_1.UnprocessableException("003", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
398
395
  }
399
396
  }
400
397
  else if (column.type === 'string[]') {
@@ -404,7 +401,7 @@ class TableModel {
404
401
  // ValidateValueUtil.isErrorValue(column.type, value)で型チェックしてるのでas []にしている
405
402
  for (const v of value) {
406
403
  if (v.toString().length > column.length) {
407
- this.throwValidationError("004", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
404
+ throw new Exception_1.UnprocessableException("004", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
408
405
  }
409
406
  }
410
407
  }
@@ -420,16 +417,14 @@ class TableModel {
420
417
  // 一部の値がnullの場合はエラー
421
418
  if (refValues.some(value => value === null || value === undefined)) {
422
419
  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(',');
423
- this.throwValidationError("004", this.errorMessages.fk.replace('{name}', name));
420
+ throw new Exception_1.UnprocessableException("004", this.errorMessages.fk.replace('{name}', name));
424
421
  }
425
422
  let refIndex = 1;
426
423
  const sql = `SELECT COUNT(*) as count FROM ${ref.table} WHERE ${ref.columns.map(col => `${col.ref} = $${refIndex++}`).join(" AND ")}`;
427
424
  const datas = yield this.clientQuery(sql, refValues);
428
- console.log(datas);
429
- console.log(datas.rows[0].count == "0");
430
425
  if (datas.rows[0].count == "0") {
431
426
  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(',');
432
- this.throwValidationError("004", this.errorMessages.fk.replace('{name}', name));
427
+ throw new Exception_1.UnprocessableException("004", this.errorMessages.fk.replace('{name}', name));
433
428
  }
434
429
  }
435
430
  }
@@ -443,7 +438,7 @@ class TableModel {
443
438
  if (options[key] === undefined || options[key] === null) {
444
439
  // Null許容されていないカラムにNULLを入れようとしているか?
445
440
  if (column.attribute === "primary" || column.attribute === "noDefault") {
446
- this.throwValidationError("101", this.errorMessages.notInput.replace('{name}', name));
441
+ throw new Exception_1.UnprocessableException("101", this.errorMessages.notInput.replace('{name}', name));
447
442
  }
448
443
  }
449
444
  }
@@ -533,7 +528,7 @@ class TableModel {
533
528
  const sql = `UPDATE ${this.TableName} SET ${updateExpressions.join(',')} WHERE id = $${vars.length}`;
534
529
  const data = yield this.executeQuery(sql, vars);
535
530
  if (data.rowCount !== 1) {
536
- throw new Exception_1.BusinessLogicException("201", this.errorMessages.idNotExist.replace('{id}', id));
531
+ throw new Exception_1.UnprocessableException("201", this.errorMessages.idNotExist.replace('{id}', id));
537
532
  }
538
533
  });
539
534
  }
@@ -567,7 +562,7 @@ class TableModel {
567
562
  let sql = `DELETE FROM ${this.TableName} WHERE id = $1`;
568
563
  const datas = yield this.executeQuery(sql, [id]);
569
564
  if (datas.rowCount !== 1) {
570
- throw new Exception_1.BusinessLogicException("301", this.errorMessages.idNotExist.replace('{id}', id));
565
+ throw new Exception_1.UnprocessableException("301", this.errorMessages.idNotExist.replace('{id}', id));
571
566
  }
572
567
  });
573
568
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Exception_1 = require("../exceptions/Exception");
3
4
  class ValidateClient {
4
5
  constructor(model) {
5
6
  this.model = model;
@@ -50,7 +51,7 @@ class ValidateClient {
50
51
  message = message.replace('{column}', (_b = column.alias) !== null && _b !== void 0 ? _b : column.columnName);
51
52
  message = message.replace('{value}', value.toString());
52
53
  message = message.replace('{list}', list.join(', '));
53
- this.model.throwValidationError(code, message);
54
+ throw new Exception_1.UnprocessableException(code, message);
54
55
  }
55
56
  }
56
57
  validateUnderNow(option, key, error) {
@@ -73,7 +74,7 @@ class ValidateClient {
73
74
  }
74
75
  message = message.replace('{column}', (_b = column.alias) !== null && _b !== void 0 ? _b : column.columnName);
75
76
  message = message.replace('{value}', value.toString());
76
- this.model.throwValidationError(code, message);
77
+ throw new Exception_1.UnprocessableException(code, message);
77
78
  }
78
79
  }
79
80
  validateUnderToday(option, key, isErrorToday, error) {
@@ -109,7 +110,7 @@ class ValidateClient {
109
110
  }
110
111
  message = message.replace('{column}', (_b = column.alias) !== null && _b !== void 0 ? _b : column.columnName);
111
112
  message = message.replace('{value}', value.toString());
112
- this.model.throwValidationError(code, message);
113
+ throw new Exception_1.UnprocessableException(code, message);
113
114
  }
114
115
  }
115
116
  validateRegExp(option, key, regExp, error) {
@@ -133,7 +134,7 @@ class ValidateClient {
133
134
  }
134
135
  message = message.replace('{column}', (_b = column.alias) !== null && _b !== void 0 ? _b : column.columnName);
135
136
  message = message.replace('{value}', value.toString());
136
- this.model.throwValidationError(code, message);
137
+ throw new Exception_1.UnprocessableException(code, message);
137
138
  }
138
139
  }
139
140
  validatePositiveNumber(option, key, error) {
@@ -157,7 +158,7 @@ class ValidateClient {
157
158
  }
158
159
  message = message.replace('{column}', (_b = column.alias) !== null && _b !== void 0 ? _b : column.columnName);
159
160
  message = message.replace('{value}', value.toString());
160
- this.model.throwValidationError(code, message);
161
+ throw new Exception_1.UnprocessableException(code, message);
161
162
  }
162
163
  }
163
164
  }
package/index.d.ts CHANGED
@@ -8,6 +8,8 @@ import { Base64Client } from './src/clients/Base64Client';
8
8
  import { StringClient } from './src/clients/StringClient';
9
9
  import { EncryptClient } from './src/clients/EncryptClient';
10
10
 
11
+ export { AwsS3Client } from './src/clients/AwsS3Client';
12
+
11
13
  // models class
12
14
  import ValidateClient from './src/models/ValidateClient';
13
15
 
@@ -138,6 +140,18 @@ declare module 'pg-mvc-service' {
138
140
  constructor(message?: string);
139
141
  }
140
142
 
143
+ export class DbConflictException extends Error {
144
+ private errorId: string;
145
+ get ErrorId(): string;
146
+ constructor(errorId: string, message?: string);
147
+ }
148
+
149
+ export class UnprocessableException extends Error {
150
+ private errorId: string;
151
+ get ErrorId(): string;
152
+ constructor(errorId: string, message?: string);
153
+ }
154
+
141
155
  export type TSqlValue = string | number | boolean | Date | null | Array<string | null> | Array<number | null> | Array<Date | null> | Array<Boolean | null>;
142
156
 
143
157
  // column type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
package/src/Service.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import axios, { AxiosResponse } from "axios";
2
2
  import { Request, Response } from 'express';
3
3
  import { Pool, type PoolClient } from 'pg';
4
- import { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, BusinessLogicException } from './exceptions/Exception';
4
+ import { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException } from './exceptions/Exception';
5
5
  import { RequestType } from './reqestResponse/RequestType';
6
6
  import { ResponseType } from './reqestResponse/ResponseType';
7
7
  import { AwsS3Client } from './clients/AwsS3Client';
@@ -110,7 +110,7 @@ export class Service {
110
110
  errorMessage : ex.message
111
111
  });
112
112
  return;
113
- } else if (ex instanceof BusinessLogicException) {
113
+ } else if (ex instanceof UnprocessableException) {
114
114
  this.res.status(422).json({
115
115
  errorCode : `${this.apiCode}-${ex.ErrorId}`,
116
116
  errorMessage : ex.message
@@ -45,7 +45,7 @@ export class DbConflictException extends Error {
45
45
  }
46
46
  }
47
47
 
48
- export class BusinessLogicException extends Error {
48
+ export class UnprocessableException extends Error {
49
49
  // for 422 Unprocessable Entity
50
50
  private errorId: string = "";
51
51
  get ErrorId(): string {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Service } from './Service';
2
- export { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, BusinessLogicException } from './exceptions/Exception';
2
+ export { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException } from './exceptions/Exception';
3
3
  export { createSwagger } from './documents/Swagger';
4
4
  export { AwsS3Client } from './clients/AwsS3Client';
5
5
  export { Base64Client } from './clients/Base64Client';
@@ -4,7 +4,7 @@ import ValidateValueUtil from './SqlUtils/ValidateValueUtil';
4
4
  import SelectExpression from './SqlUtils/SelectExpression';
5
5
  import WhereExpression from './SqlUtils/WhereExpression';
6
6
  import ValidateClient from './ValidateClient';
7
- import { BusinessLogicException, InputErrorException } from '../exceptions/Exception';
7
+ import { UnprocessableException } from '../exceptions/Exception';
8
8
 
9
9
  export class TableModel {
10
10
 
@@ -422,9 +422,6 @@ export class TableModel {
422
422
  'fk': 'The value of {name} does not exist in the table.',
423
423
  'idNotExist': 'The specified ID({id}) does not exist in the table.',
424
424
  }
425
- public throwValidationError(code: string, message: string): never {
426
- throw new InputErrorException(code, message);
427
- }
428
425
 
429
426
  protected async validateOptions(options: TOption, isInsert: boolean): Promise<void> {
430
427
  if (Object.keys(options).length === 0) {
@@ -442,11 +439,11 @@ export class TableModel {
442
439
  if (column.attribute === 'nullable') {
443
440
  continue;
444
441
  }
445
- this.throwValidationError("001", this.errorMessages.null.replace('{name}', name));
442
+ throw new UnprocessableException("001", this.errorMessages.null.replace('{name}', name));
446
443
  }
447
444
 
448
445
  if (ValidateValueUtil.isErrorValue(column.type, value)) {
449
- this.throwValidationError("002", this.errorMessages[column.type].replace('{name}', name));
446
+ throw new UnprocessableException("002", this.errorMessages[column.type].replace('{name}', name));
450
447
  }
451
448
 
452
449
  if (column.type === 'string') {
@@ -455,7 +452,7 @@ export class TableModel {
455
452
  }
456
453
 
457
454
  if (value.toString().length > column.length) {
458
- this.throwValidationError("003", this.errorMessages.length.replace('{name}', name).replace('{length}', column.toString()));
455
+ throw new UnprocessableException("003", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
459
456
  }
460
457
  } else if (column.type === 'string[]') {
461
458
  if (Number.isInteger(column.length) === false) {
@@ -465,7 +462,7 @@ export class TableModel {
465
462
  // ValidateValueUtil.isErrorValue(column.type, value)で型チェックしてるのでas []にしている
466
463
  for (const v of value as Array<string | number | boolean>) {
467
464
  if (v.toString().length > column.length) {
468
- this.throwValidationError("004", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
465
+ throw new UnprocessableException("004", this.errorMessages.length.replace('{name}', name).replace('{length}', column.length.toString()));
469
466
  }
470
467
  }
471
468
  }
@@ -483,17 +480,15 @@ export class TableModel {
483
480
  // 一部の値がnullの場合はエラー
484
481
  if (refValues.some(value => value === null || value === undefined)) {
485
482
  const name = ref.columns.map(col => this.getColumn(col.target).alias ?? this.getColumn(col.target).columnName).join(',');
486
- this.throwValidationError("004", this.errorMessages.fk.replace('{name}', name));
483
+ throw new UnprocessableException("004", this.errorMessages.fk.replace('{name}', name));
487
484
  }
488
485
 
489
486
  let refIndex = 1;
490
487
  const sql = `SELECT COUNT(*) as count FROM ${ref.table} WHERE ${ref.columns.map(col => `${col.ref} = $${refIndex++}`).join(" AND ")}`;
491
488
  const datas = await this.clientQuery(sql, refValues);
492
- console.log(datas);
493
- console.log(datas.rows[0].count == "0");
494
489
  if (datas.rows[0].count == "0") {
495
490
  const name = ref.columns.map(col => this.getColumn(col.target).alias ?? this.getColumn(col.target).columnName).join(',');
496
- this.throwValidationError("004", this.errorMessages.fk.replace('{name}', name));
491
+ throw new UnprocessableException("004", this.errorMessages.fk.replace('{name}', name));
497
492
  }
498
493
  }
499
494
  }
@@ -506,7 +501,7 @@ export class TableModel {
506
501
  if (options[key] === undefined || options[key] === null) {
507
502
  // Null許容されていないカラムにNULLを入れようとしているか?
508
503
  if (column.attribute === "primary" || column.attribute === "noDefault") {
509
- this.throwValidationError("101", this.errorMessages.notInput.replace('{name}', name));
504
+ throw new UnprocessableException("101", this.errorMessages.notInput.replace('{name}', name));
510
505
  }
511
506
  }
512
507
  }
@@ -601,7 +596,7 @@ export class TableModel {
601
596
  const sql = `UPDATE ${this.TableName} SET ${updateExpressions.join(',')} WHERE id = $${vars.length}`;
602
597
  const data = await this.executeQuery(sql, vars);
603
598
  if (data.rowCount !== 1) {
604
- throw new BusinessLogicException("201", this.errorMessages.idNotExist.replace('{id}', id));
599
+ throw new UnprocessableException("201", this.errorMessages.idNotExist.replace('{id}', id));
605
600
  }
606
601
  }
607
602
 
@@ -638,7 +633,7 @@ export class TableModel {
638
633
 
639
634
  const datas = await this.executeQuery(sql, [id]);
640
635
  if (datas.rowCount !== 1) {
641
- throw new BusinessLogicException("301", this.errorMessages.idNotExist.replace('{id}', id));
636
+ throw new UnprocessableException("301", this.errorMessages.idNotExist.replace('{id}', id));
642
637
  }
643
638
  }
644
639
 
@@ -1,3 +1,4 @@
1
+ import { UnprocessableException } from "../exceptions/Exception";
1
2
  import { TableModel } from "./TableModel";
2
3
  import { TOption, TSqlValue } from "./Type";
3
4
 
@@ -58,7 +59,7 @@ export default class ValidateClient {
58
59
  message = message.replace('{column}', column.alias ?? column.columnName);
59
60
  message = message.replace('{value}', value.toString());
60
61
  message = message.replace('{list}', list.join(', '));
61
- this.model.throwValidationError(code, message);
62
+ throw new UnprocessableException(code, message);
62
63
  }
63
64
  }
64
65
 
@@ -83,7 +84,7 @@ export default class ValidateClient {
83
84
  }
84
85
  message = message.replace('{column}', column.alias ?? column.columnName);
85
86
  message = message.replace('{value}', value.toString());
86
- this.model.throwValidationError(code, message);
87
+ throw new UnprocessableException(code, message);
87
88
  }
88
89
  }
89
90
 
@@ -122,7 +123,7 @@ export default class ValidateClient {
122
123
  }
123
124
  message = message.replace('{column}', column.alias ?? column.columnName);
124
125
  message = message.replace('{value}', value.toString());
125
- this.model.throwValidationError(code, message);
126
+ throw new UnprocessableException(code, message);
126
127
  }
127
128
  }
128
129
 
@@ -149,7 +150,7 @@ export default class ValidateClient {
149
150
  }
150
151
  message = message.replace('{column}', column.alias ?? column.columnName);
151
152
  message = message.replace('{value}', value.toString());
152
- this.model.throwValidationError(code, message);
153
+ throw new UnprocessableException(code, message);
153
154
  }
154
155
  }
155
156
 
@@ -176,7 +177,7 @@ export default class ValidateClient {
176
177
  }
177
178
  message = message.replace('{column}', column.alias ?? column.columnName);
178
179
  message = message.replace('{value}', value.toString());
179
- this.model.throwValidationError(code, message);
180
+ throw new UnprocessableException(code, message);
180
181
  }
181
182
  }
182
183
  }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MigrateDatabase = exports.rollback = exports.migrate = exports.MigrateTable = exports.createTableDoc = exports.TableModel = void 0;
4
- var TableModel_1 = require("./TableModel");
5
- Object.defineProperty(exports, "TableModel", { enumerable: true, get: function () { return TableModel_1.TableModel; } });
6
- var TableDoc_1 = require("./TableDoc");
7
- Object.defineProperty(exports, "createTableDoc", { enumerable: true, get: function () { return TableDoc_1.createTableDoc; } });
8
- var MigrateTable_1 = require("./MigrateTable");
9
- Object.defineProperty(exports, "MigrateTable", { enumerable: true, get: function () { return MigrateTable_1.MigrateTable; } });
10
- var MigrateRollback_1 = require("./MigrateRollback");
11
- Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return MigrateRollback_1.migrate; } });
12
- Object.defineProperty(exports, "rollback", { enumerable: true, get: function () { return MigrateRollback_1.rollback; } });
13
- var MigrateDatabase_1 = require("./MigrateDatabase");
14
- Object.defineProperty(exports, "MigrateDatabase", { enumerable: true, get: function () { return MigrateDatabase_1.MigrateDatabase; } });
@@ -1,7 +0,0 @@
1
- export { TableModel } from './TableModel';
2
- export { createTableDoc } from './TableDoc';
3
-
4
- export { MigrateTable } from './MigrateTable';
5
- export { migrate, rollback } from './MigrateRollback';
6
-
7
- export { MigrateDatabase } from './MigrateDatabase';