#migrate add ssues
This commit is contained in:
parent
64a7010d0a
commit
dd01e2a79d
3 changed files with 186 additions and 0 deletions
93
src/entities/Issues.ts
Normal file
93
src/entities/Issues.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import { Entity, Column, BeforeInsert } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { EntityBase } from "./base/Base";
|
||||
|
||||
@Entity("issues")
|
||||
export class Issues extends EntityBase {
|
||||
@Column({
|
||||
type: "varchar",
|
||||
nullable: false,
|
||||
length: 20,
|
||||
comment: "รหัส issue เช่น ISS20260127001",
|
||||
})
|
||||
codeIssue: string;
|
||||
|
||||
@Column({ type: "varchar", nullable: false, length: 255, comment: "หัวข้อ" })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "text", nullable: false, comment: "รายละเอียดของปัญหา" })
|
||||
description: string | null;
|
||||
|
||||
@Column({ type: "varchar", nullable: false, length: 50, comment: "ระบบ" })
|
||||
system: string;
|
||||
|
||||
@Column({ type: "varchar", nullable: false, length: 255, comment: "เมนู" })
|
||||
menu: string | null;
|
||||
|
||||
@Column({ type: "varchar", nullable: true, length: 500, comment: "สังกัด" })
|
||||
org: string | null;
|
||||
|
||||
@Column({ type: "text", nullable: true, comment: "หมายเหตุ" })
|
||||
remark: string | null;
|
||||
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: ["NEW", "IN_PROGRESS", "RESOLVED", "CLOSED"],
|
||||
default: "NEW",
|
||||
comment: "สถานะการแก้ไขปัญหา",
|
||||
})
|
||||
status: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED";
|
||||
|
||||
@BeforeInsert()
|
||||
async generateCodeIssue() {
|
||||
const today = new Date();
|
||||
const dateStr = today.toISOString().slice(0, 10).replace(/-/g, "");
|
||||
const prefix = `ISS${dateStr}`;
|
||||
|
||||
const repository = AppDataSource.getRepository(Issues);
|
||||
const lastIssue = await repository
|
||||
.createQueryBuilder("issue")
|
||||
.where("issue.codeIssue LIKE :prefix", { prefix: `${prefix}%` })
|
||||
.orderBy("issue.codeIssue", "DESC")
|
||||
.getOne();
|
||||
|
||||
let runningNumber = 1;
|
||||
if (lastIssue) {
|
||||
const lastNumber = parseInt(lastIssue.codeIssue.slice(-3), 10);
|
||||
runningNumber = lastNumber + 1;
|
||||
}
|
||||
|
||||
this.codeIssue = `${prefix}${runningNumber.toString().padStart(3, "0")}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Interface สำหรับ TSOA Response
|
||||
export interface IssueResponse {
|
||||
id: string;
|
||||
codeIssue: string;
|
||||
title: string;
|
||||
description: string | null;
|
||||
system: string;
|
||||
menu: string | null;
|
||||
org: string | null;
|
||||
remark: string | null;
|
||||
status: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED";
|
||||
createdAt: Date;
|
||||
lastUpdatedAt: Date;
|
||||
createdFullName: string;
|
||||
lastUpdateFullName: string;
|
||||
}
|
||||
|
||||
export interface CreateIssueRequest {
|
||||
title: string;
|
||||
description?: string;
|
||||
system: string;
|
||||
status?: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED";
|
||||
menu?: string;
|
||||
org?: string;
|
||||
}
|
||||
|
||||
export interface UpdateIssueRequest {
|
||||
status?: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED";
|
||||
remark?: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue