From b2b97aecf050149175bf2a1ef79f0e2e7161fb07 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 24 Sep 2024 16:42:24 +0700 Subject: [PATCH] no message --- src/controllers/CommandController.ts | 77 +++++++++++++++- src/entities/Command.ts | 31 ++++++- src/entities/CommandRecive.ts | 89 +++++++++++++++++++ src/entities/CommandSalary.ts | 6 +- src/entities/Profile.ts | 4 + ...69710-update_command_add_positiondetail.ts | 24 +++++ 6 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 src/entities/CommandRecive.ts create mode 100644 src/migration/1727167169710-update_command_add_positiondetail.ts diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 2b8a989f..714a4247 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -234,6 +234,78 @@ export class CommandController extends Controller { return new HttpSuccess(); } + /** + * API รายละเอียดรายการคำสั่ง tab2 + * + * @summary API รายละเอียดรายการคำสั่ง tab2 + * + * @param {string} id Id คำสั่ง + */ + @Get("tab2/{id}") + async GetByIdTab2(@Path() id: string) { + const command = await this.commandRepository.findOne({ + where: { id }, + relations: ["commandSalary", "commandRecives"], + }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + + const _command = { + id: command.id, + commandSalaryId: command.commandSalaryId, + commandSalary: command.commandSalary?.name || null, + positionDetail: command.positionDetail, + sendCC: command.commandRecives + .sort((a, b) => a.order - b.order) + .map((x) => ({ + citizenId: x.citizenId, + prefix: x.prefix, + fristName: x.fristName, + lastName: x.lastName, + profileId: x.profileId, + order: x.order, + })), + }; + return new HttpSuccess(_command); + } + + /** + * API แก้ไขรายการ body คำสั่ง Tab2 + * + * @summary API แก้ไขรายการ body คำสั่ง Tab2 + * + * @param {string} id Id คำสั่ง + */ + @Put("tab2/{id}") + async PutTab2( + @Path() id: string, + @Body() + requestBody: { + commandNo: string | null; + commandYear: number | null; + issue: string | null; + detailHeader: string | null; + detailBody: string | null; + detailFooter: string | null; + commandAffectDate: Date | null; + commandExcecuteDate: Date | null; + }, + @Request() request: RequestWithUser, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + const data = new Command(); + Object.assign(data, { ...command, ...requestBody }); + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.lastUpdatedAt = new Date(); + await this.commandRepository.save(data); + return new HttpSuccess(); + } + /** * API รายละเอียดรายการคำสั่ง tab3 * @@ -526,6 +598,7 @@ export class CommandController extends Controller { status: command.status, isDraft: command.isDraft, isSign: command.isSign, + isAttachment: command.isAttachment, }; return new HttpSuccess(_command); } @@ -568,14 +641,14 @@ export class CommandController extends Controller { async PutSelectDraft( @Path() id: string, @Body() - requestBody: { sign?: boolean }, + requestBody: { sign: boolean }, @Request() request: RequestWithUser, ) { const command = await this.commandRepository.findOne({ where: { id: id } }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } - command.isDraft = true; + command.isDraft = requestBody.sign; command.status = "PENDING"; command.lastUpdateUserId = request.user.sub; command.lastUpdateFullName = request.user.name; diff --git a/src/entities/Command.ts b/src/entities/Command.ts index dbe6a3b2..f0d31665 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -2,6 +2,8 @@ import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { CommandType } from "./CommandType"; import { CommandSend } from "./CommandSend"; +import { CommandSalary } from "./CommandSalary"; +import { CommandRecive } from "./CommandRecive"; @Entity("command") export class Command extends EntityBase { @@ -83,10 +85,12 @@ export class Command extends EntityBase { detailFooter: string; @Column({ - length: 40, - comment: "คีย์นอก(FK)ของตาราง commandType", + nullable: true, + comment: "ตำแหน่ง", + type: "text", + default: null, }) - commandTypeId: string; + positionDetail: string; @Column({ comment: "สถานะบัญชีแนบท้าย", @@ -112,12 +116,33 @@ export class Command extends EntityBase { }) isSign: boolean; + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง commandType", + }) + commandTypeId: string; + @ManyToOne(() => CommandType, (commandType) => commandType.commands) @JoinColumn({ name: "commandTypeId" }) commandType: CommandType; + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง commandSalary", + default: null, + }) + commandSalaryId: string; + + @ManyToOne(() => CommandSalary, (commandSalary) => commandSalary.commands) + @JoinColumn({ name: "commandSalaryId" }) + commandSalary: CommandSalary; + @OneToMany(() => CommandSend, (commandSend) => commandSend.command) commandSends: CommandSend[]; + + @OneToMany(() => CommandRecive, (commandRecive) => commandRecive.command) + commandRecives: CommandRecive[]; } export class CreateCommand { diff --git a/src/entities/CommandRecive.ts b/src/entities/CommandRecive.ts new file mode 100644 index 00000000..70a52ab3 --- /dev/null +++ b/src/entities/CommandRecive.ts @@ -0,0 +1,89 @@ +import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Command } from "./Command"; +import { Profile } from "./Profile"; + +@Entity("commandRecive") +export class CommandRecive extends EntityBase { + @Column({ + nullable: true, + comment: "เลขประจำตัวประชาชน", + length: 255, + default: null, + }) + citizenId: string; + + @Column({ + nullable: true, + comment: "คำนำหน้า", + length: 255, + default: null, + }) + prefix: string; + + @Column({ + nullable: true, + comment: "ชื่อ", + length: 255, + default: null, + }) + fristName: string; + + @Column({ + nullable: true, + comment: "สกุล", + length: 255, + default: null, + }) + lastName: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + length: 255, + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "หน่วยงาน", + length: 255, + default: null, + }) + org: string; + + @Column({ + nullable: true, + comment: "ลำดับแสดงผล", + default: null, + }) + order: number; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง command", + }) + commandId: string; + + @ManyToOne(() => Command, (command) => command.commandRecives) + @JoinColumn({ name: "commandId" }) + command: Command; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + }) + profileId: string; + + @ManyToOne(() => Profile, (profile) => profile.commandRecives) + @JoinColumn({ name: "profileId" }) + profile: Profile; +} + +export class CreateCommandRecive { + @Column() + name: string; +} + +// export type UpdateCommandRecive = Partial; diff --git a/src/entities/CommandSalary.ts b/src/entities/CommandSalary.ts index ab97cf0b..5d610ca0 100644 --- a/src/entities/CommandSalary.ts +++ b/src/entities/CommandSalary.ts @@ -1,6 +1,7 @@ -import { Entity, Column, JoinColumn, ManyToOne } from "typeorm"; +import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { CommandSys } from "./CommandSys"; +import { Command } from "./Command"; @Entity("commandSalary") export class CommandSalary extends EntityBase { @@ -29,6 +30,9 @@ export class CommandSalary extends EntityBase { @ManyToOne(() => CommandSys, (commandSys) => commandSys.commandSalarys) @JoinColumn({ name: "commandSysId" }) commandSalarySys: CommandSys; + + @OneToMany(() => Command, (command) => command.commandSalary) + commands: Command[]; } export class CreateCommandSalary { diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 3de83737..f83df7d5 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -32,6 +32,7 @@ import { ProfileDevelopment } from "./ProfileDevelopment"; import { OrgRoot } from "./OrgRoot"; import { PermissionOrg } from "./PermissionOrg"; import { CommandSend } from "./CommandSend"; +import { CommandRecive } from "./CommandRecive"; @Entity("profile") export class Profile extends EntityBase { @@ -375,6 +376,9 @@ export class Profile extends EntityBase { @OneToMany(() => CommandSend, (v) => v.profile) commandSends: CommandSend[]; + @OneToMany(() => CommandRecive, (v) => v.profile) + commandRecives: CommandRecive[]; + @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) @JoinColumn({ name: "posLevelId" }) posLevel: PosLevel; diff --git a/src/migration/1727167169710-update_command_add_positiondetail.ts b/src/migration/1727167169710-update_command_add_positiondetail.ts new file mode 100644 index 00000000..6399ec30 --- /dev/null +++ b/src/migration/1727167169710-update_command_add_positiondetail.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateCommandAddPositiondetail1727167169710 implements MigrationInterface { + name = 'UpdateCommandAddPositiondetail1727167169710' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`commandRecive\` (\`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', \`citizenId\` varchar(255) NULL COMMENT 'เลขประจำตัวประชาชน', \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`fristName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'สกุล', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`org\` varchar(255) NULL COMMENT 'หน่วยงาน', \`commandId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง command', \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`command\` ADD \`positionDetail\` text NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`command\` ADD \`commandSalaryId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง commandSalary'`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_66de028b0d8e4cff62bc43a58be\` FOREIGN KEY (\`commandId\`) REFERENCES \`command\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_fb29bfd315d0d43d0b49b362995\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`command\` ADD CONSTRAINT \`FK_c85f006fc84cebf07b0980c6b94\` FOREIGN KEY (\`commandSalaryId\`) REFERENCES \`commandSalary\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`command\` DROP FOREIGN KEY \`FK_c85f006fc84cebf07b0980c6b94\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_fb29bfd315d0d43d0b49b362995\``); + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_66de028b0d8e4cff62bc43a58be\``); + await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`commandSalaryId\``); + await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`positionDetail\``); + await queryRunner.query(`DROP TABLE \`commandRecive\``); + } + +}