From 666a7f802141c3adfb7ea3e81eafa4331d4d1927 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 15 Aug 2024 13:28:20 +0700 Subject: [PATCH] service call service --- src/interfaces/call-api.ts | 44 ++++++++++--------- src/interfaces/permission.ts | 17 ++++--- ...13928787-update_table_migration07302024.ts | 14 ------ ...13963408-update_table_migration08072024.ts | 20 --------- .../1723605750693-import0508241320.ts | 28 ++++++++++++ 5 files changed, 63 insertions(+), 60 deletions(-) delete mode 100644 src/migration/1722313928787-update_table_migration07302024.ts delete mode 100644 src/migration/1723013963408-update_table_migration08072024.ts create mode 100644 src/migration/1723605750693-import0508241320.ts diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index e95592a..78f0f14 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -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; } } diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 74bb1de..539def0 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -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"); } } diff --git a/src/migration/1722313928787-update_table_migration07302024.ts b/src/migration/1722313928787-update_table_migration07302024.ts deleted file mode 100644 index 2b8fef8..0000000 --- a/src/migration/1722313928787-update_table_migration07302024.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableMigration073020241722313928787 implements MigrationInterface { - name = 'UpdateTableMigration073020241722313928787' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isProfile\` tinyint NOT NULL COMMENT 'มีข้อมูลอยู่ในทะเบียนประวัติ' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isProfile\``); - } - -} diff --git a/src/migration/1723013963408-update_table_migration08072024.ts b/src/migration/1723013963408-update_table_migration08072024.ts deleted file mode 100644 index 18d23e8..0000000 --- a/src/migration/1723013963408-update_table_migration08072024.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableMigration080720241723013963408 implements MigrationInterface { - name = 'UpdateTableMigration080720241723013963408' - - public async up(queryRunner: QueryRunner): Promise { - 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 { - 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\``); - } - -} diff --git a/src/migration/1723605750693-import0508241320.ts b/src/migration/1723605750693-import0508241320.ts new file mode 100644 index 0000000..97a5c4b --- /dev/null +++ b/src/migration/1723605750693-import0508241320.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Import05082413201723605750693 implements MigrationInterface { + name = 'Import05082413201723605750693' + + public async up(queryRunner: QueryRunner): Promise { + 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 { + 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\``); + } + +}