service call service
This commit is contained in:
parent
5a92e60e0e
commit
666a7f8021
5 changed files with 63 additions and 60 deletions
|
|
@ -24,6 +24,7 @@ class CallAPI {
|
|||
headers: {
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
|
|
@ -38,16 +39,16 @@ class CallAPI {
|
|||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +61,7 @@ class CallAPI {
|
|||
headers: {
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
|
|
@ -75,17 +77,17 @@ class CallAPI {
|
|||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,13 @@ import HttpStatus from "./http-status";
|
|||
|
||||
class CheckAuth {
|
||||
public async Permission(req: RequestWithUser, system: string, action: string) {
|
||||
if (
|
||||
req.headers.hasOwnProperty("api_key") &&
|
||||
req.headers["api_key"] &&
|
||||
req.headers["api_key"] == process.env.API_KEY
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
await new CallAPI()
|
||||
.GetData(req, "/org/permission")
|
||||
.then((x) => {
|
||||
|
|
@ -39,19 +46,19 @@ class CheckAuth {
|
|||
});
|
||||
}
|
||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "CREATE");
|
||||
return await this.Permission(req, system, "CREATE");
|
||||
}
|
||||
public async PermissionDelete(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "DELETE");
|
||||
return await this.Permission(req, system, "DELETE");
|
||||
}
|
||||
public async PermissionGet(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "GET");
|
||||
return await this.Permission(req, system, "GET");
|
||||
}
|
||||
public async PermissionList(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "LIST");
|
||||
return await this.Permission(req, system, "LIST");
|
||||
}
|
||||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "UPDATE");
|
||||
return await this.Permission(req, system, "UPDATE");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableMigration073020241722313928787 implements MigrationInterface {
|
||||
name = 'UpdateTableMigration073020241722313928787'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isProfile\` tinyint NOT NULL COMMENT 'มีข้อมูลอยู่ในทะเบียนประวัติ' DEFAULT 0`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isProfile\``);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableMigration080720241723013963408 implements MigrationInterface {
|
||||
name = 'UpdateTableMigration080720241723013963408'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``);
|
||||
}
|
||||
|
||||
}
|
||||
28
src/migration/1723605750693-import0508241320.ts
Normal file
28
src/migration/1723605750693-import0508241320.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Import05082413201723605750693 implements MigrationInterface {
|
||||
name = 'Import05082413201723605750693'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`developmentOther\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน', \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน', \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``);
|
||||
await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``);
|
||||
await queryRunner.query(`DROP TABLE \`developmentOther\``);
|
||||
await queryRunner.query(`DROP TABLE \`developmentRisk\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue