From 000bc2aad9cc557afe93cc57fdd27ca3c95a26ed Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 23:33:45 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 125 ++++++++++-------- src/entities/ProfileSalary.ts | 11 +- ...727795520589-update_ProfileDevelopment1.ts | 22 +++ 3 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 src/migration/1727795520589-update_ProfileDevelopment1.ts diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 9544aa3f..efccce68 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -831,9 +831,9 @@ export class CommandController extends Controller { } /** - * API ทำคำสั่งใหม่ + * API ออกคำสั่ง * - * @summary API ทำคำสั่งใหม่ + * @summary API ออกคำสั่ง * * @param {string} id Id คำสั่ง */ @@ -844,7 +844,10 @@ export class CommandController extends Controller { requestBody: { sign?: boolean }, @Request() request: RequestWithUser, ) { - const command = await this.commandRepository.findOne({ where: { id: id } }); + const command = await this.commandRepository.findOne({ + where: { id: id }, + relations: ["commandType", "commandRecives"], + }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } @@ -861,16 +864,25 @@ export class CommandController extends Controller { ) { command.status = "WAITING"; } else { - let path = this.commandTypePath(command.commandType.name); + const path = this.commandTypePath(command.commandType.code); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); new CallAPI() .PostData(request, path + "excecute", { - refIds: command.commandRecives.map((x) => x.refId), + refIds: command.commandRecives + .filter((x) => x.refId != null) + .map((x) => ({ + refId: x.refId, + commandAffectDate: command.commandAffectDate, + commandNo: command.commandNo, + commandYear: command.commandYear, + templateDoc: command.positionDetail, + })), }) .then(async (res) => {}) - .catch(() => {}); - command.status = "REPORTED"; + .catch((e) => { + command.status = "REPORTED"; + }); } command.lastUpdateUserId = request.user.sub; command.lastUpdateFullName = request.user.name; @@ -940,7 +952,7 @@ export class CommandController extends Controller { } let _command: any = []; - let path = this.commandTypePath(command.commandType.name); + const path = this.commandTypePath(command.commandType.code); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); new CallAPI() @@ -985,6 +997,7 @@ export class CommandController extends Controller { @Request() request: RequestWithUser, ) { let command = new Command(); + let commandCode = null; if ( requestBody.commandId != undefined && requestBody.commandId != null && @@ -992,7 +1005,7 @@ export class CommandController extends Controller { ) { const _command = await this.commandRepository.findOne({ where: { id: requestBody.commandId }, - relations: ["commandRecives"], + relations: ["commandRecives", "commandType"], order: { commandRecives: { order: "DESC", @@ -1002,6 +1015,7 @@ export class CommandController extends Controller { if (!_command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบคำสั่งนี้ในระบบ"); } + commandCode = _command.commandType.code; command = _command; } else { command = Object.assign(new Command(), requestBody); @@ -1012,6 +1026,7 @@ export class CommandController extends Controller { if (!commandType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); } + commandCode = commandType.code; command.detailHeader = commandType.detailHeader; command.detailBody = commandType.detailBody; command.detailFooter = commandType.detailFooter; @@ -1027,7 +1042,7 @@ export class CommandController extends Controller { await this.commandRepository.save(command); } - let path = this.commandTypePath(command.commandType.name); + const path = this.commandTypePath(commandCode); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); new CallAPI() .PostData(request, path, { @@ -1066,94 +1081,92 @@ export class CommandController extends Controller { return new HttpSuccess(command.id); } - commandTypePath(commandType: string) { - let path = null; - switch (commandType) { + commandTypePath(commandCode: string) { + switch (commandCode) { case "C-PM-01": - path = "/placemant/main/report/"; + return "/placement/recruit/report/"; case "C-PM-02": - path = "/placemant/recive/report/"; + return "/placemant/recruit/report/"; case "C-PM-03": - path = "/discipline/recive/report/"; + return "/discipline/recive/report/"; case "C-PM-04": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-05": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-06": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-07": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-08": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-09": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-10": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-11": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-12": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-13": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-14": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-15": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-16": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-17": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-18": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-19": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-20": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-21": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-22": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-23": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-24": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-25": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-26": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-27": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-28": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-29": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-30": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-31": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-32": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-33": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-34": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-35": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-36": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-37": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-38": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-39": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-40": - path = "/xxxxxx/"; + return "/xxxxxx/"; case "C-PM-41": - path = "/xxxxxx/"; + return "/xxxxxx/"; default: - path = null; + return null; } - return path; } } diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index 641f88e0..91458be0 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -1,11 +1,4 @@ -import { - Entity, - Column, - OneToMany, - JoinColumn, - ManyToOne, - Double, -} from "typeorm"; +import { Entity, Column, OneToMany, JoinColumn, ManyToOne, Double } from "typeorm"; import { EntityBase } from "./base/Base"; import { Profile } from "./Profile"; import { ProfileEmployee } from "./ProfileEmployee"; @@ -174,7 +167,7 @@ export class CreateProfileSalary { positionType: string | null; positionLevel: string | null; refCommandNo: string | null; - commandType?: string | null; + // commandType?: string | null; templateDoc: string | null; } diff --git a/src/migration/1727795520589-update_ProfileDevelopment1.ts b/src/migration/1727795520589-update_ProfileDevelopment1.ts new file mode 100644 index 00000000..8c325978 --- /dev/null +++ b/src/migration/1727795520589-update_ProfileDevelopment1.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateProfileDevelopment11727795520589 implements MigrationInterface { + name = 'UpdateProfileDevelopment11727795520589' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_fb29bfd315d0d43d0b49b362995\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`org\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`profileId\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`refId\` varchar(40) NULL COMMENT 'refId'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`refId\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`org\` varchar(255) NULL COMMENT 'หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_fb29bfd315d0d43d0b49b362995\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +}