Migration ฟิลด์ตาราง profileLeave, profileLeaveHistory & สร้างตาราง profileAbsentLate, profileEmployeeAbsentLate
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m52s

This commit is contained in:
harid 2026-03-23 15:36:54 +07:00
parent 41ad2a44e8
commit a76bda34b4
9 changed files with 706 additions and 0 deletions

View file

@ -0,0 +1,217 @@
import {
Body,
Controller,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { In } from "typeorm";
import {
ProfileAbsentLate,
CreateProfileAbsentLate,
CreateProfileAbsentLateBatch,
UpdateProfileAbsentLate,
} from "../entities/ProfileAbsentLate";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/absent-late")
@Tags("ProfileAbsentLate")
@Security("bearerAuth")
export class ProfileAbsentLateController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private absentLateRepo = AppDataSource.getRepository(ProfileAbsentLate);
/**
* API / user
* @summary API / user
*/
@Get("user")
public async getAbsentLateUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.absentLateRepo.find({
where: { profileId: profile.id, isDeleted: false },
order: { stampDate: "DESC" },
});
return new HttpSuccess(record);
}
/**
* API / profileId
* @summary API / profileId
* @param profileId profile
*/
@Get("{profileId}")
public async getAbsentLate(@Path() profileId: string, @Request() req: RequestWithUser) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.absentLateRepo.find({
where: { profileId, isDeleted: false },
order: { stampDate: "DESC" },
});
return new HttpSuccess(record);
}
/**
* API /
* @summary API /
*/
@Post()
public async newAbsentLate(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAbsentLate,
) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileAbsentLate();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
await this.absentLateRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
return new HttpSuccess(data.id);
}
/**
* API / ( Job)
* @summary API / ( Job)
*/
@Post("batch")
public async newAbsentLateBatch(
@Request() req: RequestWithUser,
@Body() body: CreateProfileAbsentLateBatch,
) {
if (!body.records || body.records.length === 0) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณาระบุข้อมูลอย่างน้อย 1 รายการ");
}
const profileIds = [...new Set(body.records.map((r) => r.profileId))];
const profiles = await this.profileRepo.findBy({
id: In(profileIds),
});
const foundProfileIds = new Set(profiles.map((p) => p.id));
const validRecords = body.records.filter((r) => foundProfileIds.has(r.profileId));
if (validRecords.length === 0) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ที่ระบุ");
}
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
const records = validRecords.map((item) => {
const data = new ProfileAbsentLate();
Object.assign(data, { ...item, ...meta });
return data;
});
const result = await this.absentLateRepo.save(records, { data: req });
return new HttpSuccess({ count: result.length, ids: result.map((r) => r.id) });
}
/**
* API /
* @summary API /
* @param absentLateId /
*/
@Patch("{absentLateId}")
public async editAbsentLate(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileAbsentLate,
@Path() absentLateId: string,
) {
const record = await this.absentLateRepo.findOneBy({ id: absentLateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(
req,
"SYS_REGISTRY_OFFICER",
record.profileId,
);
const before = structuredClone(record);
Object.assign(record, body);
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
await Promise.all([
this.absentLateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
]);
return new HttpSuccess();
}
/**
* API / (Soft Delete)
* @summary API / (Soft Delete)
* @param absentLateId /
*/
@Patch("update-delete/{absentLateId}")
public async updateIsDeleted(
@Request() req: RequestWithUser,
@Path() absentLateId: string,
) {
const record = await this.absentLateRepo.findOneBy({ id: absentLateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (record.isDeleted === true) {
return new HttpSuccess();
}
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
record.isDeleted = true;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
await Promise.all([
this.absentLateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
]);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,217 @@
import {
Body,
Controller,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { In } from "typeorm";
import {
ProfileEmployeeAbsentLate,
CreateProfileEmployeeAbsentLate,
CreateProfileEmployeeAbsentLateBatch,
UpdateProfileEmployeeAbsentLate,
} from "../entities/ProfileEmployeeAbsentLate";
import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/absent-late")
@Tags("ProfileEmployeeAbsentLate")
@Security("bearerAuth")
export class ProfileEmployeeAbsentLateController extends Controller {
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private absentLateRepo = AppDataSource.getRepository(ProfileEmployeeAbsentLate);
/**
* API / user
* @summary API / user
*/
@Get("user")
public async getAbsentLateUser(@Request() request: { user: Record<string, any> }) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.absentLateRepo.find({
where: { profileEmployeeId: profile.id, isDeleted: false },
order: { stampDate: "DESC" },
});
return new HttpSuccess(record);
}
/**
* API / profileId
* @summary API / profileId
* @param profileId profile
*/
@Get("{profileId}")
public async getAbsentLate(@Path() profileId: string, @Request() req: RequestWithUser) {
let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP");
if (_workflow == false)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.absentLateRepo.find({
where: { profileEmployeeId: profileId, isDeleted: false },
order: { stampDate: "DESC" },
});
return new HttpSuccess(record);
}
/**
* API /
* @summary API /
*/
@Post()
public async newAbsentLate(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAbsentLate,
) {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileEmployeeAbsentLate();
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
await this.absentLateRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
return new HttpSuccess(data.id);
}
/**
* API / (Batch)
* @summary API / (Batch) Job
*/
@Post("batch")
public async newAbsentLateBatch(
@Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAbsentLateBatch,
) {
if (!body.records || body.records.length === 0) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณาระบุข้อมูลอย่างน้อย 1 รายการ");
}
const profileIds = [...new Set(body.records.map((r) => r.profileEmployeeId))];
const profiles = await this.profileRepo.findBy({
id: In(profileIds),
});
const foundProfileIds = new Set(profiles.map((p) => p.id));
const validRecords = body.records.filter((r) => foundProfileIds.has(r.profileEmployeeId));
if (validRecords.length === 0) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ที่ระบุ");
}
const meta = {
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
const records = validRecords.map((item) => {
const data = new ProfileEmployeeAbsentLate();
Object.assign(data, { ...item, ...meta });
return data;
});
const result = await this.absentLateRepo.save(records, { data: req });
return new HttpSuccess({ count: result.length, ids: result.map((r) => r.id) });
}
/**
* API /
* @summary API /
* @param absentLateId /
*/
@Patch("{absentLateId}")
public async editAbsentLate(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileEmployeeAbsentLate,
@Path() absentLateId: string,
) {
const record = await this.absentLateRepo.findOneBy({ id: absentLateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(
req,
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
Object.assign(record, body);
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
await Promise.all([
this.absentLateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
]);
return new HttpSuccess();
}
/**
* API / (Soft Delete)
* @summary API / (Soft Delete)
* @param absentLateId /
*/
@Patch("update-delete/{absentLateId}")
public async updateIsDeleted(
@Request() req: RequestWithUser,
@Path() absentLateId: string,
) {
const record = await this.absentLateRepo.findOneBy({ id: absentLateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (record.isDeleted === true) {
return new HttpSuccess();
}
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const before = structuredClone(record);
record.isDeleted = true;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
await Promise.all([
this.absentLateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
]);
return new HttpSuccess();
}
}

View file

@ -50,6 +50,7 @@ import { ProfileAssistance } from "./ProfileAssistance";
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";
import { PositionSalaryEditHistory } from "./PositionSalaryEditHistory";
import { ProfileChangeName } from "./ProfileChangeName";
import { ProfileAbsentLate } from "./ProfileAbsentLate";
@Entity("profile")
export class Profile extends EntityBase {
@ -546,6 +547,9 @@ export class Profile extends EntityBase {
@OneToMany(() => ProfileChangeName, (v) => v.profile)
profileChangeNames: ProfileChangeName[];
@OneToMany(() => ProfileAbsentLate, (v) => v.profile)
profileAbsentLates: ProfileAbsentLate[];
@ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles)
@JoinColumn({ name: "posLevelId" })
posLevel: PosLevel;

View file

@ -0,0 +1,98 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
// Enums
export enum AbsentLateStatus {
LATE = "LATE", // มาสาย
ABSENT = "ABSENT", // ขาดราชการ
}
export enum StampType {
FULL_DAY = "FULL_DAY", // เต็มวัน
MORNING = "MORNING", // ครึ่งเช้า
AFTERNOON = "AFTERNOON", // ครึ่งบ่าย
}
@Entity("profileAbsentLate")
export class ProfileAbsentLate extends EntityBase {
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง Profile",
default: null,
})
profileId: string;
@Column({
type: "enum",
enum: AbsentLateStatus,
comment: "สถานะ มาสาย/ขาดราชการ",
nullable: false,
})
status: AbsentLateStatus;
@Column({
type: "datetime",
comment: "วันที่และเวลาที่ลงเวลา",
nullable: false,
})
stampDate: Date;
@Column({
type: "enum",
enum: StampType,
comment: "เต็มวัน/ครึ่งเช้า/ครึ่งบ่าย",
default: StampType.FULL_DAY,
})
stampType: StampType;
@Column({
type: "decimal",
precision: 2,
scale: 1,
comment: "จำนวน (1.0/0.5)",
default: "1.0",
})
stampAmount: number;
@Column({
type: "varchar",
length: 250,
comment: "หมายเหตุ",
nullable: true,
})
remark: string;
@Column({
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => Profile, (profile) => profile.profileAbsentLates)
@JoinColumn({ name: "profileId" })
profile: Profile;
}
// DTO Classes
export class CreateProfileAbsentLate {
profileId: string;
status: AbsentLateStatus;
stampDate: Date;
stampType?: StampType;
stampAmount?: number;
remark?: string;
}
export class CreateProfileAbsentLateBatch {
records: CreateProfileAbsentLate[];
}
export type UpdateProfileAbsentLate = {
status?: AbsentLateStatus;
stampDate?: Date;
stampType?: StampType;
stampAmount?: number;
remark?: string;
};

View file

@ -38,6 +38,7 @@ import { StateOperatorUser } from "./StateOperatorUser";
import { EmployeeTempPosMaster } from "./EmployeeTempPosMaster";
import { ProfileSalaryTemp } from "./ProfileSalaryTemp";
import { PositionSalaryEditHistory } from "./PositionSalaryEditHistory";
import { ProfileEmployeeAbsentLate } from "./ProfileEmployeeAbsentLate";
@Entity("profileEmployee")
export class ProfileEmployee extends EntityBase {
@ -827,6 +828,9 @@ export class ProfileEmployee extends EntityBase {
@OneToMany(() => PositionSalaryEditHistory, (v) => v.profileEmployee)
positionSalaryEditHistory: PositionSalaryEditHistory[];
@OneToMany(() => ProfileEmployeeAbsentLate, (v) => v.profileEmployee)
profileEmployeeAbsentLates: ProfileEmployeeAbsentLate[];
//ที่อยู่
@Column({
nullable: true,

View file

@ -0,0 +1,87 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { ProfileEmployee } from "./ProfileEmployee";
import { AbsentLateStatus, StampType } from "./ProfileAbsentLate";
@Entity("profileEmployeeAbsentLate")
export class ProfileEmployeeAbsentLate extends EntityBase {
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง ProfileEmployee",
default: null,
})
profileEmployeeId: string;
@Column({
type: "enum",
enum: AbsentLateStatus,
comment: "สถานะ มาสาย/ขาดราชการ",
nullable: false,
})
status: AbsentLateStatus;
@Column({
type: "datetime",
comment: "วันที่และเวลาที่ลงเวลา",
nullable: false,
})
stampDate: Date;
@Column({
type: "enum",
enum: StampType,
comment: "เต็มวัน/ครึ่งเช้า/ครึ่งบ่าย",
default: StampType.FULL_DAY,
})
stampType: StampType;
@Column({
type: "decimal",
precision: 2,
scale: 1,
comment: "จำนวน (1.0/0.5)",
default: "1.0",
})
stampAmount: number;
@Column({
type: "varchar",
length: 250,
comment: "หมายเหตุ",
nullable: true,
})
remark: string;
@Column({
comment: "สถานะลบข้อมูล",
default: false,
})
isDeleted: boolean;
@ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.profileEmployeeAbsentLates)
@JoinColumn({ name: "profileEmployeeId" })
profileEmployee: ProfileEmployee;
}
// DTO Classes
export class CreateProfileEmployeeAbsentLate {
profileEmployeeId: string;
status: AbsentLateStatus;
stampDate: Date;
stampType?: StampType;
stampAmount?: number;
remark?: string;
}
export class CreateProfileEmployeeAbsentLateBatch {
records: CreateProfileEmployeeAbsentLate[];
}
export type UpdateProfileEmployeeAbsentLate = {
status?: AbsentLateStatus;
stampDate?: Date;
stampType?: StampType;
stampAmount?: number;
remark?: string;
};

View file

@ -107,6 +107,24 @@ export class ProfileLeave extends EntityBase {
})
isDeleted: boolean;
@Column({
nullable: true,
comment: "ประเภทย่อยการลา (เช่น ศึกษาต่อ, ฝึกอบรม, ปฎอบัติการวิจัย, ดูงาน)",
type: "varchar",
length: 255,
default: null,
})
leaveSubTypeName: string;
@Column({
nullable: true,
comment: "ประเทศที่ไป",
type: "varchar",
length: 255,
default: null,
})
coupleDayLevelCountry: string;
@OneToMany(() => ProfileLeaveHistory, (v) => v.profileLeave)
histories: ProfileLeaveHistory[];
@ -153,6 +171,8 @@ export class CreateProfileLeave {
status?: string | null;
reason: string | null;
leaveId?: string | null;
leaveSubTypeName?: string | null;
coupleDayLevelCountry?: string | null;
}
export class CreateProfileEmployeeLeave {
@ -166,6 +186,8 @@ export class CreateProfileEmployeeLeave {
status: string | null;
reason: string | null;
leaveId?: string | null;
leaveSubTypeName?: string | null;
coupleDayLevelCountry?: string | null;
}
export type UpdateProfileLeave = {
@ -177,4 +199,6 @@ export type UpdateProfileLeave = {
totalLeave?: number | null;
status?: string | null;
reason?: string | null;
leaveSubTypeName?: string | null;
coupleDayLevelCountry?: string | null;
};

View file

@ -0,0 +1,34 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class CreateTableProfileAbsentLate_1774245696453 implements MigrationInterface {
name = 'CreateTableProfileAbsentLate_1774245696453'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`profileAbsentLate\` (\`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), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`status\` enum ('LATE', 'ABSENT') NOT NULL COMMENT 'สถานะ มาสาย/ขาดราชการ', \`stampDate\` date NOT NULL COMMENT 'วันที่ลงเวลา', \`stampType\` enum ('FULL_DAY', 'MORNING', 'AFTERNOON') NOT NULL COMMENT 'เต็มวัน/ครึ่งเช้า/ครึ่งบ่าย' DEFAULT 'FULL_DAY', \`stampAmount\` decimal(2,1) NOT NULL COMMENT 'จำนวน (1.0/0.5)' DEFAULT '1.0', \`remark\` varchar(250) NULL COMMENT 'หมายเหตุ', \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`profileEmployeeAbsentLate\` (\`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), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'System Administrator', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'System Administrator', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`status\` enum ('LATE', 'ABSENT') NOT NULL COMMENT 'สถานะ มาสาย/ขาดราชการ', \`stampDate\` date NOT NULL COMMENT 'วันที่ลงเวลา', \`stampType\` enum ('FULL_DAY', 'MORNING', 'AFTERNOON') NOT NULL COMMENT 'เต็มวัน/ครึ่งเช้า/ครึ่งบ่าย' DEFAULT 'FULL_DAY', \`stampAmount\` decimal(2,1) NOT NULL COMMENT 'จำนวน (1.0/0.5)' DEFAULT '1.0', \`remark\` varchar(250) NULL COMMENT 'หมายเหตุ', \`isDeleted\` tinyint NOT NULL COMMENT 'สถานะลบข้อมูล' DEFAULT 0, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`profileLeave\` ADD \`leaveSubTypeName\` varchar(255) NULL COMMENT 'ประเภทย่อยการลา (เช่น ศึกษาต่อ, ฝึกอบรม, ปฎอบัติการวิจัย, ดูงาน)'`);
await queryRunner.query(`ALTER TABLE \`profileLeave\` ADD \`coupleDayLevelCountry\` varchar(255) NULL COMMENT 'ประเทศที่ไป'`);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` ADD \`leaveSubTypeName\` varchar(255) NULL COMMENT 'ประเภทย่อยการลา (เช่น ศึกษาต่อ, ฝึกอบรม, ปฎอบัติการวิจัย, ดูงาน)'`);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` ADD \`coupleDayLevelCountry\` varchar(255) NULL COMMENT 'ประเทศที่ไป'`);
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` ADD CONSTRAINT \`FK_28f5579c548da2fd76b5295d8d5\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` ADD CONSTRAINT \`FK_f22d4ae4155cafd14e9c6d888e6\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` DROP FOREIGN KEY \`FK_f22d4ae4155cafd14e9c6d888e6\``);
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` DROP FOREIGN KEY \`FK_28f5579c548da2fd76b5295d8d5\``);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` DROP COLUMN \`coupleDayLevelCountry\``);
await queryRunner.query(`ALTER TABLE \`profileLeaveHistory\` DROP COLUMN \`leaveSubTypeName\``);
await queryRunner.query(`ALTER TABLE \`profileLeave\` DROP COLUMN \`coupleDayLevelCountry\``);
await queryRunner.query(`ALTER TABLE \`profileLeave\` DROP COLUMN \`leaveSubTypeName\``);
await queryRunner.query(`DROP TABLE \`profileEmployeeAbsentLate\``);
await queryRunner.query(`DROP TABLE \`profileAbsentLate\``);
}
}

View file

@ -0,0 +1,21 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileAbsentLate1774253766170 implements MigrationInterface {
name = 'UpdateTableProfileAbsentLate1774253766170'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` DROP COLUMN \`stampDate\``);
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` ADD \`stampDate\` datetime NOT NULL COMMENT 'วันที่และเวลาที่ลงเวลา'`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` DROP COLUMN \`stampDate\``);
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` ADD \`stampDate\` datetime NOT NULL COMMENT 'วันที่และเวลาที่ลงเวลา'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` DROP COLUMN \`stampDate\``);
await queryRunner.query(`ALTER TABLE \`profileEmployeeAbsentLate\` ADD \`stampDate\` date NOT NULL COMMENT 'วันที่ลงเวลา'`);
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` DROP COLUMN \`stampDate\``);
await queryRunner.query(`ALTER TABLE \`profileAbsentLate\` ADD \`stampDate\` date NOT NULL COMMENT 'วันที่ลงเวลา'`);
}
}