diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 074e07b4..34209372 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -503,4 +503,141 @@ export class CommandController extends Controller { await this.commandRepository.delete(command.id); return new HttpSuccess(); } + + /** + * API รายละเอียดรายการคำสั่ง tab0 + * + * @summary API รายละเอียดรายการคำสั่ง tab0 + * + * @param {string} id Id คำสั่ง + */ + @Get("tab0/{id}") + async GetByIdTab0(@Path() id: string) { + const command = await this.commandRepository.findOne({ + where: { id }, + }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + + const _command = { + id: command.id, + isSignature: command.isSignature, + status: command.status, + isDraft: command.isDraft, + isSign: command.isSign, + }; + return new HttpSuccess(_command); + } + + /** + * API ทำคำสั่งใหม่ + * + * @summary API ทำคำสั่งใหม่ + * + * @param {string} id Id คำสั่ง + */ + @Put("sign/{id}") + async PutSelectSign( + @Path() id: string, + @Body() + requestBody: { sign: boolean }, + @Request() request: RequestWithUser, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + command.isSignature = requestBody.sign; + command.status = "DRAFT"; + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(); + } + + /** + * API ทำคำสั่งใหม่ + * + * @summary API ทำคำสั่งใหม่ + * + * @param {string} id Id คำสั่ง + */ + @Put("draft/{id}") + async PutSelectDraft( + @Path() id: string, + @Body() + 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.status = "PENDING"; + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(); + } + + /** + * API ทำคำสั่งใหม่ + * + * @summary API ทำคำสั่งใหม่ + * + * @param {string} id Id คำสั่ง + */ + @Put("pending-check/{id}") + async PutSelectPending_Check( + @Path() id: string, + @Body() + requestBody: { sign?: boolean }, + @Request() request: RequestWithUser, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + command.isSign = true; + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(); + } + + /** + * API ทำคำสั่งใหม่ + * + * @summary API ทำคำสั่งใหม่ + * + * @param {string} id Id คำสั่ง + */ + @Put("pending/{id}") + async PutSelectPending( + @Path() id: string, + @Body() + requestBody: { sign?: boolean }, + @Request() request: RequestWithUser, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + command.isSign = true; + if (new Date().getDate() > command.commandExcecuteDate.getDate()) { + command.status = "WAITING"; + } else { + command.status = "REPORTED"; + } + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(); + } } diff --git a/src/entities/Command.ts b/src/entities/Command.ts index 86db45f4..dbe6a3b2 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -94,6 +94,24 @@ export class Command extends EntityBase { }) isAttachment: boolean; + @Column({ + comment: "ออกคำสั่งแบบ Digital Signature", + default: null, + }) + isSignature: boolean; + + @Column({ + comment: "ยืนยันทำแบบร่าง", + default: false, + }) + isDraft: boolean; + + @Column({ + comment: "ผู้มีอำนาจลงนาม", + default: false, + }) + isSign: boolean; + @ManyToOne(() => CommandType, (commandType) => commandType.commands) @JoinColumn({ name: "commandTypeId" }) commandType: CommandType; diff --git a/src/migration/1727151717676-update_command_add_isSign.ts b/src/migration/1727151717676-update_command_add_isSign.ts new file mode 100644 index 00000000..16ce4d43 --- /dev/null +++ b/src/migration/1727151717676-update_command_add_isSign.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateCommandAddIsSign1727151717676 implements MigrationInterface { + name = 'UpdateCommandAddIsSign1727151717676' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`command\` ADD \`isSignature\` tinyint NULL COMMENT 'ออกคำสั่งแบบ Digital Signature'`); + await queryRunner.query(`ALTER TABLE \`command\` ADD \`isDraft\` tinyint NOT NULL COMMENT 'ยืนยันทำแบบร่าง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`command\` ADD \`isSign\` tinyint NOT NULL COMMENT 'ผู้มีอำนาจลงนาม' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`isSign\``); + await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`isDraft\``); + await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`isSignature\``); + } + +}