2026-01-28 09:22:52 +07:00
|
|
|
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;
|
|
|
|
|
|
2026-02-04 10:43:11 +07:00
|
|
|
@Column({ type: "varchar", nullable: true, length: 255, comment: "อีเมลผู้รายงาน" })
|
|
|
|
|
email: string | null;
|
|
|
|
|
|
|
|
|
|
@Column({ type: "varchar", nullable: true, length: 20, comment: "เบอร์โทรผู้รายงาน" })
|
|
|
|
|
phone: string | null;
|
|
|
|
|
|
2026-01-28 09:22:52 +07:00
|
|
|
@Column({
|
|
|
|
|
type: "enum",
|
2026-05-08 10:01:02 +07:00
|
|
|
enum: ["NEW", "IN_PROGRESS", "RESOLVED", "CLOSED", "HELPDESK_IN_PROGRESS", "REPLIED"],
|
2026-01-28 09:22:52 +07:00
|
|
|
default: "NEW",
|
|
|
|
|
comment: "สถานะการแก้ไขปัญหา",
|
|
|
|
|
})
|
2026-05-08 10:01:02 +07:00
|
|
|
status: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED" | "HELPDESK_IN_PROGRESS" | "REPLIED";
|
2026-01-28 09:22:52 +07:00
|
|
|
|
|
|
|
|
@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;
|
2026-05-08 10:01:02 +07:00
|
|
|
status: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED" | "HELPDESK_IN_PROGRESS" | "REPLIED";
|
2026-01-28 09:22:52 +07:00
|
|
|
createdAt: Date;
|
|
|
|
|
lastUpdatedAt: Date;
|
|
|
|
|
createdFullName: string;
|
|
|
|
|
lastUpdateFullName: string;
|
2026-02-04 10:43:11 +07:00
|
|
|
email: string | null;
|
|
|
|
|
phone: string | null;
|
2026-01-28 09:22:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateIssueRequest {
|
|
|
|
|
title: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
system: string;
|
2026-05-08 10:01:02 +07:00
|
|
|
status?: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED" | "HELPDESK_IN_PROGRESS" | "REPLIED";
|
2026-01-28 09:22:52 +07:00
|
|
|
menu?: string;
|
|
|
|
|
org?: string;
|
2026-02-04 10:43:11 +07:00
|
|
|
email?: string;
|
|
|
|
|
phone?: string;
|
2026-01-28 09:22:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UpdateIssueRequest {
|
2026-05-08 10:01:02 +07:00
|
|
|
status?: "NEW" | "IN_PROGRESS" | "RESOLVED" | "CLOSED" | "HELPDESK_IN_PROGRESS" | "REPLIED";
|
2026-01-28 09:22:52 +07:00
|
|
|
remark?: string;
|
|
|
|
|
}
|