แก้ ไข คำ สั่ง tab0

This commit is contained in:
kittapath 2024-09-24 11:30:07 +07:00
parent 22ae951626
commit 5ccbdd1f61
3 changed files with 173 additions and 0 deletions

View file

@ -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();
}
}

View file

@ -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;

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateCommandAddIsSign1727151717676 implements MigrationInterface {
name = 'UpdateCommandAddIsSign1727151717676'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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\``);
}
}