pg-mvc-service 2.0.41 → 2.0.43

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.
Files changed (37) hide show
  1. package/dist/Service.js +16 -9
  2. package/dist/assets/favicon.ico +0 -0
  3. package/dist/models/TableDoc.js +4 -1
  4. package/package.json +8 -2
  5. package/index.d.ts +0 -189
  6. package/src/PoolManager.ts +0 -48
  7. package/src/Service.ts +0 -269
  8. package/src/Utils/DateTimeUtil.ts +0 -146
  9. package/src/Utils/NumberUtil.ts +0 -23
  10. package/src/Utils/StringUtil.ts +0 -33
  11. package/src/clients/AwsS3Client.ts +0 -310
  12. package/src/clients/Base64Client.ts +0 -305
  13. package/src/clients/EncryptClient.ts +0 -100
  14. package/src/clients/StringClient.ts +0 -19
  15. package/src/cron/BaseCron.ts +0 -122
  16. package/src/cron/CronExecuter.ts +0 -34
  17. package/src/cron/CronType.ts +0 -25
  18. package/src/documents/Swagger.ts +0 -105
  19. package/src/exceptions/Exception.ts +0 -72
  20. package/src/index.ts +0 -23
  21. package/src/models/ExpressionClient.ts +0 -72
  22. package/src/models/MigrateDatabase.ts +0 -135
  23. package/src/models/MigrateRollback.ts +0 -151
  24. package/src/models/MigrateTable.ts +0 -56
  25. package/src/models/SqlUtils/SelectExpression.ts +0 -97
  26. package/src/models/SqlUtils/UpdateExpression.ts +0 -29
  27. package/src/models/SqlUtils/ValidateValueUtil.ts +0 -354
  28. package/src/models/SqlUtils/WhereExpression.ts +0 -421
  29. package/src/models/TableDoc.ts +0 -366
  30. package/src/models/TableModel.ts +0 -701
  31. package/src/models/Type.ts +0 -62
  32. package/src/models/Utils/MessageUtil.ts +0 -60
  33. package/src/models/ValidateClient.ts +0 -182
  34. package/src/reqestResponse/ReqResType.ts +0 -170
  35. package/src/reqestResponse/RequestType.ts +0 -918
  36. package/src/reqestResponse/ResponseType.ts +0 -420
  37. package/tsconfig.json +0 -14
package/dist/Service.js CHANGED
@@ -44,12 +44,12 @@ class Service {
44
44
  this.response = new ResponseType_1.ResponseType();
45
45
  this.isTest = process.env.NODE_ENV === 'test';
46
46
  this.tags = [];
47
- this.dbUser = this.isTest ? process.env.TEST_DB_USER : process.env.DB_USER;
48
- this.dbHost = this.isTest ? process.env.TEST_DB_HOST : process.env.DB_HOST;
49
- this.dbName = this.isTest ? process.env.TEST_DB_DATABASE : process.env.DB_DATABASE;
50
- this.dbPassword = this.isTest ? process.env.TEST_DB_PASSWORD : process.env.DB_PASSWORD;
51
- this.dbPort = this.isTest ? process.env.TEST_DB_PORT : process.env.DB_PORT;
52
- this.dbIsSslConnect = (this.isTest ? process.env.TEST_DB_IS_SSL : process.env.DB_IS_SSL) === 'true';
47
+ this.dbUser = process.env.DB_USER;
48
+ this.dbHost = process.env.DB_HOST;
49
+ this.dbName = process.env.DB_DATABASE;
50
+ this.dbPassword = process.env.DB_PASSWORD;
51
+ this.dbPort = process.env.DB_PORT;
52
+ this.dbIsSslConnect = process.env.DB_IS_SSL === 'true';
53
53
  this.isExecuteRollback = false;
54
54
  this.req = request;
55
55
  this.res = response;
@@ -147,9 +147,16 @@ class Service {
147
147
  });
148
148
  return;
149
149
  }
150
- this.res.status(500).json({
151
- message: 'Internal server error'
152
- });
150
+ if (this.isTest) {
151
+ this.res.status(500).json({
152
+ message: ex.stack
153
+ });
154
+ }
155
+ else {
156
+ this.res.status(500).json({
157
+ message: 'Internal server error'
158
+ });
159
+ }
153
160
  return;
154
161
  }
155
162
  get Pool() {
Binary file
@@ -9,6 +9,7 @@ const createTableDoc = (models, serviceName) => {
9
9
  <head>
10
10
  <meta charset="UTF-8">
11
11
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
12
+ <link rel="icon" href="assets/favicon.ico" type="image/x-icon">
12
13
  <title>table document</title>
13
14
  </head>
14
15
  <style>
@@ -48,6 +49,8 @@ button:hover {
48
49
  h1 {
49
50
  font-size: 28px;
50
51
  font-weight: bold;
52
+ margin-top: 16px;
53
+ margin-bottom: 16px;
51
54
  }
52
55
 
53
56
  /* db-title*/
@@ -76,7 +79,7 @@ h3 {
76
79
 
77
80
  .table-wrapper {
78
81
  padding: 0px;
79
- margin-bottom: 16px;
82
+ margin-bottom: 64px;
80
83
  }
81
84
 
82
85
  .table-title-wrapper {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.41",
3
+ "version": "2.0.43",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -14,13 +14,19 @@
14
14
  "author": "Sho Nakadaira",
15
15
  "type": "commonjs",
16
16
  "main": "dist/index.js",
17
+ "files": [
18
+ "dist",
19
+ "dist/assets"
20
+ ],
17
21
  "scripts": {
18
- "build": "rm -rf dist/* && tsc",
22
+ "build": "rm -rf dist/* && tsc && npm run copy-assets",
23
+ "copy-assets": "copyfiles -u 2 src/assets/* dist/assets",
19
24
  "test": "echo \"Error: no test specified\" && exit 1"
20
25
  },
21
26
  "devDependencies": {
22
27
  "@types/jest": "29.5.14",
23
28
  "@types/pg": "8.11.11",
29
+ "copyfiles": "2.4.1",
24
30
  "jest": "29.7.0",
25
31
  "ts-jest": "29.3.1",
26
32
  "typescript": "5.8.2"
package/index.d.ts DELETED
@@ -1,189 +0,0 @@
1
- import { AxiosResponse } from "axios";
2
- import { Request, Response } from 'express';
3
- import { Pool, PoolClient } from 'pg';
4
- import { ErrorMessageType, IncomingHttpHeaders } from './src/reqestResponse/RequestType';
5
- import { ArrayType, EnumType, ObjectType, PrimitiveType } from './src/reqestResponse/ReqResType';
6
-
7
- import { MethodType } from './src/Service';
8
- export { MethodType } from './src/Service';
9
-
10
- import { Base64Client } from './src/clients/Base64Client';
11
- import { StringClient } from './src/clients/StringClient';
12
- import { EncryptClient } from './src/clients/EncryptClient';
13
-
14
- import { AwsS3Client } from './src/clients/AwsS3Client';
15
- export { AwsS3Client } from './src/clients/AwsS3Client';
16
-
17
- // models class
18
- import ValidateClient from './src/models/ValidateClient';
19
-
20
- import { TableModel } from "./src/models/TableModel";
21
- export { TableModel } from "./src/models/TableModel";
22
-
23
- export { TColumnAttribute, TColumnType, TColumnArrayType, TColumn, TColumnDetail, TOperator, TColumnInfo, TQuery, TSelectExpression, TAggregateFuncType, TCondition, TNestedCondition, TSortKeyword, TKeyFormat } from './src/models/Type';
24
-
25
- export { DayType, MonthType, DateType, HourType, MinuteSecondType } from './src/cron/CronType';
26
- export { BaseCron } from "./src/cron/BaseCron";
27
- export { runCron } from "./src/cron/CronExecuter";
28
-
29
- declare module 'pg-mvc-service' {
30
- export class Service {
31
- protected readonly method: MethodType;
32
- get Method(): MethodType;
33
- protected readonly endpoint: string;
34
- get Endpoint(): string;
35
- protected readonly apiCode: string;
36
- get ApiCode(): string;
37
- protected readonly summary: string;
38
- get Summary(): string;
39
- protected readonly apiUserAvailable: string;
40
- get ApiUserAvailable(): string;
41
- protected readonly request: RequestType;
42
- get AuthToken(): string;
43
- protected readonly response: ResponseType;
44
- protected readonly isTest: boolean;
45
- protected readonly tags: Array<string>;
46
- get Tags(): Array<string>;
47
-
48
- protected readonly req: Request;
49
- protected readonly res: Response;
50
- constructor(request: Request, response: Response);
51
-
52
- public inintialize(): void;
53
-
54
- protected dbUser?: string;
55
- protected dbHost?: string;
56
- protected dbName?: string;
57
- protected dbPassword?: string;
58
- protected dbPort?: number;
59
- protected dbIsSslConnect?: boolean;
60
- protected checkMaintenance(): Promise<void>;
61
- protected middleware(): Promise<void>;
62
-
63
- public resSuccess(): void;
64
- public handleException(ex: any): void;
65
- protected outputErrorLog(ex: any): Promise<void>;
66
-
67
- protected get Pool(): Pool;
68
- protected get Client(): PoolClient;
69
-
70
- public startConnect(): Promise<void>;
71
- public commit(): Promise<void>;
72
- public rollback(): Promise<void>;
73
- public release(): Promise<void>;
74
-
75
- get S3Client(): AwsS3Client;
76
- get Base64Client(): Base64Client;
77
- get StringClient(): StringClient;
78
- get EncryptClient(): EncryptClient;
79
-
80
- public requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
81
- method: MethodType, url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>>;
82
- }
83
-
84
- export interface IParams {
85
- in: 'header' | 'path',
86
- name: string,
87
- require?: boolean,
88
- description?: string,
89
- example?: string
90
- }
91
- export function createSwagger(services: Service[], name: string, url: string, params: Array<IParams>): string;
92
-
93
- export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType;
94
-
95
- export class RequestType {
96
- constructor();
97
-
98
- protected properties: { [key: string]: PropertyType; };
99
- protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }>;
100
- protected readonly ERROR_MESSAGE: ErrorMessageType;
101
-
102
- protected throwException(code: string, message: string): never;
103
-
104
- public setRequest(request: Request): void;
105
- get Data(): { [key: string]: any };
106
- get Headers(): IncomingHttpHeaders;
107
- get Params(): { [key: string]: any };
108
- get RemoteAddress(): string | undefined;
109
- get Authorization(): string | null;
110
- }
111
-
112
- export class ResponseType {
113
- public Data: { [key: string]: any };
114
-
115
- protected properties: { [key: string]: PropertyType; };
116
- get ResponseData(): { [key: string]: any };
117
- }
118
-
119
- export class AuthException extends Error {
120
- private id: string;
121
- get Id(): string;
122
- constructor(id: string, message?: string);
123
- }
124
-
125
- export class ForbiddenException extends Error {
126
- }
127
-
128
- export class InputErrorException extends Error {
129
- private errorId: string;
130
- get ErrorId(): string;
131
- private errorLog: string;
132
- get ErrorLog(): string;
133
- constructor(errorId: string, message?: string, errorLog?: string);
134
- }
135
-
136
- export class MaintenanceException extends Error {
137
- constructor(message?: string);
138
- }
139
-
140
- export class DbConflictException extends Error {
141
- private errorId: string;
142
- get ErrorId(): string;
143
- constructor(errorId: string, message?: string);
144
- }
145
-
146
- export class NotFoundException extends Error {
147
- private errorId: string;
148
- get ErrorId(): string;
149
- constructor(errorId: string, message?: string);
150
- }
151
-
152
- export class UnprocessableException extends Error {
153
- private errorId: string;
154
- get ErrorId(): string;
155
- constructor(errorId: string, message?: string);
156
- }
157
-
158
- export function createTableDoc(models: Array<TableModel>, serviceName?: string): string;
159
- export function migrate(migrates: Array<MigrateTable>, poolParam: {
160
- host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
161
- }): Promise<void>;
162
- export function rollback(toNumber: number, poolParam: {
163
- host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
164
- }): Promise<void>;
165
- export class MigrateTable {
166
- protected readonly migrateSql: string;
167
- protected readonly rollbackSql: string;
168
- protected readonly addGrantTables: Array<string>;
169
- protected readonly user: string;
170
-
171
- constructor();
172
- constructor(user: string);
173
- }
174
-
175
- export class MigrateDatabase {
176
- constructor(dbName: string, userName: string, pool: Pool);
177
-
178
- get DbName(): string;
179
- get UserName(): string;
180
- get Password(): string | null;
181
-
182
- public IsExistUser(): Promise<boolean>;
183
- public CreateUser(password?: string): Promise<void>;
184
- public IsExistDb(): Promise<boolean>;
185
- public CreateDb(collateType?: string): Promise<void>;
186
- public RollbackDbSql(): string;
187
- public RollbackUserSql(otherUserName: string): string;
188
- }
189
- }
@@ -1,48 +0,0 @@
1
- // PoolManager.ts
2
- import { Pool } from 'pg';
3
-
4
- export default class PoolManager {
5
- private static poolMap: Record<string, Pool> = {};
6
-
7
- static getPool(user: string, host: string, database: string, password: string, port: number | string, isSslConnect: boolean): Pool {
8
- const key = `${user}@${host}/${database}`;
9
- if (!this.poolMap[key]) {
10
- this.poolMap[key] = new Pool({
11
- user: user,
12
- host: host,
13
- database: database,
14
- password: password,
15
- port: Number(port),
16
- ssl: isSslConnect ? {
17
- rejectUnauthorized: false
18
- } : false
19
- });
20
- }
21
-
22
- return this.poolMap[key];
23
- }
24
-
25
- static async shutdownAll(): Promise<void> {
26
- for (const [key, pool] of Object.entries(this.poolMap)) {
27
- try {
28
- await pool.end();
29
- console.log(`Closed pool: ${key}`);
30
- } catch (e) {
31
- console.error(`Error closing pool ${key}`, e);
32
- }
33
- }
34
- }
35
- }
36
-
37
- // ✅ 自動実行されるシャットダウン登録
38
- process.on('SIGINT', async () => {
39
- console.log('🔌 SIGINT received. Closing all pools...');
40
- await PoolManager.shutdownAll();
41
- process.exit(0);
42
- });
43
-
44
- process.on('SIGTERM', async () => {
45
- console.log('🔌 SIGTERM received. Closing all pools...');
46
- await PoolManager.shutdownAll();
47
- process.exit(0);
48
- });
package/src/Service.ts DELETED
@@ -1,269 +0,0 @@
1
- import axios, { AxiosResponse } from "axios";
2
- import { Request, Response } from 'express';
3
- import { Pool, type PoolClient } from 'pg';
4
- import { MaintenanceException, AuthException, InputErrorException, ForbiddenException, DbConflictException, UnprocessableException, NotFoundException } from './exceptions/Exception';
5
- import { RequestType } from './reqestResponse/RequestType';
6
- import { ResponseType } from './reqestResponse/ResponseType';
7
- import { AwsS3Client } from './clients/AwsS3Client';
8
- import { Base64Client } from './clients/Base64Client';
9
- import { StringClient } from './clients/StringClient';
10
- import { EncryptClient } from './clients/EncryptClient';
11
- import PoolManager from './PoolManager';
12
-
13
- export type MethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
14
-
15
- export class Service {
16
- protected readonly method: MethodType = 'GET';
17
- get Method(): MethodType { return this.method; }
18
- protected readonly endpoint: string = '';
19
- get Endpoint(): string { return this.endpoint + this.request.paramPath; }
20
- protected readonly apiCode: string = '';
21
- get ApiCode(): string { return this.apiCode; }
22
- protected readonly summary: string = '';
23
- get Summary(): string { return `${this.ApiCode !== '' ? this.apiCode + ': ' : ''}${this.summary}`; }
24
- protected readonly apiUserAvailable: string = '';
25
- get ApiUserAvailable(): string { return this.apiUserAvailable; }
26
- protected readonly request: RequestType = new RequestType();
27
- get Request(): RequestType { return this.request }; // swaggerで必要なので、ここだけ宣言
28
- get AuthToken(): string { return this.request.Authorization ?? ''; }
29
- protected readonly response: ResponseType = new ResponseType();
30
- get Response(): ResponseType { return this.response }; // swaggerで必要なので、ここだけ宣言
31
- protected readonly isTest: boolean = process.env.NODE_ENV === 'test';
32
- protected readonly tags: Array<string> = [];
33
- get Tags(): Array<string> { return this.tags; }
34
-
35
- protected readonly req: Request;
36
- protected readonly res: Response;
37
- constructor(request: Request, response: Response) {
38
- this.req = request;
39
- this.res = response;
40
- }
41
-
42
- public async inintialize(): Promise<void> {
43
- this.request.setRequest(this.req);
44
- await this.checkMaintenance();
45
- await this.middleware();
46
- }
47
-
48
- protected dbUser?: string = this.isTest ? process.env.TEST_DB_USER : process.env.DB_USER;
49
- protected dbHost?: string = this.isTest ? process.env.TEST_DB_HOST : process.env.DB_HOST;
50
- protected dbName?: string = this.isTest ? process.env.TEST_DB_DATABASE : process.env.DB_DATABASE;
51
- protected dbPassword?: string = this.isTest ? process.env.TEST_DB_PASSWORD : process.env.DB_PASSWORD;
52
- protected dbPort?: string | number = this.isTest ? process.env.TEST_DB_PORT : process.env.DB_PORT;
53
- protected dbIsSslConnect: boolean = (this.isTest ? process.env.TEST_DB_IS_SSL : process.env.DB_IS_SSL) === 'true';
54
- private setPool(): Pool {
55
- if (this.dbUser === undefined) {
56
- throw new Error("Database user is not configured");
57
- }
58
- if (this.dbHost === undefined) {
59
- throw new Error("Database host is not configured");
60
- }
61
- if (this.dbName === undefined) {
62
- throw new Error("Database name is not configured");
63
- }
64
- if (this.dbPassword === undefined) {
65
- throw new Error("Database password is not configured");
66
- }
67
- if (this.dbPort === undefined) {
68
- throw new Error("Database port is not configured");
69
- }
70
-
71
- try {
72
- return PoolManager.getPool(this.dbUser, this.dbHost, this.dbName, this.dbPassword, this.dbPort, this.dbIsSslConnect);
73
- } catch (ex) {
74
- throw new Error("Failed to connect to the database. Please check the connection settings.");
75
- }
76
- }
77
- protected async checkMaintenance(): Promise<void> { }
78
- protected async middleware(): Promise<void>{ }
79
-
80
- public resSuccess(): void {
81
- this.res.status(200).json(this.response.ResponseData);
82
- }
83
-
84
- protected async outputErrorLog(ex: any): Promise<void>{ }
85
- public handleException(ex: any): void {
86
- // To avoid slowing down the response, make this asynchronous
87
- this.outputErrorLog(ex).catch((ex) => {
88
- console.error(ex);
89
- });
90
-
91
- if (ex instanceof AuthException) {
92
- this.res.status(401).json({
93
- message : "Authentication expired. Please login again."
94
- });
95
- return;
96
- } else if (ex instanceof ForbiddenException) {
97
- this.res.status(403).json({
98
- message : 'Forbidden error'
99
- });
100
- return;
101
- } else if (ex instanceof InputErrorException) {
102
- this.res.status(400).json({
103
- errorCode : `${this.apiCode}-${ex.ErrorId}`,
104
- errorMessage : ex.message
105
- });
106
- return;
107
- } else if (ex instanceof DbConflictException) {
108
- this.res.status(409).json({
109
- errorCode : `${this.apiCode}-${ex.ErrorId}`,
110
- errorMessage : ex.message
111
- });
112
- return;
113
- } else if (ex instanceof UnprocessableException) {
114
- this.res.status(422).json({
115
- errorCode : `${this.apiCode}-${ex.ErrorId}`,
116
- errorMessage : ex.message
117
- });
118
- return;
119
- } else if (ex instanceof MaintenanceException) {
120
- this.res.status(503).json({
121
- errorMessage : ex.message
122
- });
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;
130
- }
131
-
132
- this.res.status(500).json({
133
- message : 'Internal server error'
134
- });
135
- return;
136
- }
137
-
138
- private pool?: Pool;
139
- protected get Pool(): Pool {
140
- if (this.pool === undefined) {
141
- this.pool = this.setPool();
142
- this.pool.query(`SET TIME ZONE '${process.env.TZ ?? 'Asia/Tokyo'}';`);
143
- }
144
- return this.pool;
145
- }
146
- private client?: PoolClient;
147
- private isExecuteRollback: boolean = false;
148
- protected get Client(): PoolClient {
149
- if (this.client === undefined) {
150
- throw new Error("Please call this.PoolClient after using the startConnect method.");
151
- }
152
- return this.client;
153
- }
154
-
155
- public async startConnect(): Promise<void> {
156
- this.client = await this.Pool.connect();
157
- await this.Client.query('BEGIN');
158
- this.isExecuteRollback = true;
159
- }
160
-
161
- public async commit(): Promise<void> {
162
- await this.Client.query('COMMIT');
163
- this.isExecuteRollback = false;
164
- }
165
-
166
- public async rollback(): Promise<void> {
167
- if (this.isExecuteRollback) {
168
- await this.Client.query('ROLLBACK');
169
- }
170
- this.isExecuteRollback = false;
171
- }
172
-
173
- public async release(): Promise<void> {
174
- await this.rollback();
175
- if (this.client !== undefined) {
176
- await this.client.release();
177
- }
178
-
179
- if (this.isTest) {
180
- // In tests, the connection is terminated because it is shut down every time
181
- await this.Pool.end();
182
- }
183
- }
184
-
185
- private s3Client?: AwsS3Client;
186
- get S3Client(): AwsS3Client {
187
- if (this.s3Client === undefined) {
188
- this.s3Client = new AwsS3Client({
189
- bucketName: process.env.S3_BUCKET_NAME,
190
- region: process.env.S3_REGION,
191
- accessKeyId: process.env.S3_ACCESS_KEY_ID,
192
- secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
193
- });
194
- }
195
- return this.s3Client;
196
- }
197
-
198
- private base64Client? : Base64Client;
199
- get Base64Client(): Base64Client {
200
- if (this.base64Client === undefined) {
201
- this.base64Client = new Base64Client();
202
- }
203
- return this.base64Client;
204
- }
205
-
206
- private stringClient? : StringClient;
207
- get StringClient(): StringClient {
208
- if (this.stringClient === undefined) {
209
- this.stringClient = new StringClient();
210
- }
211
- return this.stringClient;
212
- }
213
-
214
- private encryptClient?: EncryptClient;
215
- get EncryptClient(): EncryptClient {
216
- if (this.encryptClient === undefined) {
217
- this.encryptClient = new EncryptClient({
218
- secretKeyHex: process.env.SECRET_KEY_HEX,
219
- hmacKeyBase64: process.env.HMAC_KEY_BASE64
220
- });
221
- }
222
-
223
- return this.encryptClient;
224
- }
225
-
226
- public async requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
227
- method: MethodType, url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>> {
228
-
229
- // GET,DELETEのparamをURLクエリに
230
- if (method === 'GET' || method === 'DELETE') {
231
- for (const [key, value] of Object.entries(params as Record<string, any>)) {
232
- if (value === undefined || value === null) {
233
- continue;
234
- }
235
-
236
- if (Array.isArray(value)) {
237
- for (const arrayValue of value) {
238
- url += url.includes('?') ? '&' : '?';
239
- url += `${key}=${arrayValue.toString()}`;
240
- }
241
- } else {
242
- url += url.includes('?') ? '&' : '?';
243
- url += `${key}=${value.toString()}`;
244
- }
245
- }
246
- }
247
-
248
- try {
249
- switch (method) {
250
- case 'GET':
251
- return await axios.get(url, header === undefined ? {} : { headers: header });
252
- case 'POST':
253
- return await axios.post(url, params, header === undefined ? {} : { headers: header });
254
- case 'PUT':
255
- return await axios.put(url, params, header === undefined ? {} : { headers: header });
256
- case 'DELETE':
257
- return await axios.delete(url, header === undefined ? {} : { headers: header });
258
- case 'PATCH':
259
- return await axios.patch(url, params, header === undefined ? {} : { headers: header });
260
- }
261
- } catch (ex) {
262
- let response = (ex as any).response as AxiosResponse<TResponse>;
263
- if (response && [400, 401, 403, 404, 409, 422].includes(response.status)) {
264
- return response;
265
- }
266
- throw ex;
267
- }
268
- }
269
- }