fix leave
This commit is contained in:
parent
d8a47d88bc
commit
816682357c
2 changed files with 44 additions and 0 deletions
|
|
@ -260,6 +260,40 @@ export class ProfileLeaveController extends Controller {
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Patch("cancel/{leaveId}")
|
||||||
|
public async updateCancel(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() leaveId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.leaveRepo.findOneBy({ leaveId: leaveId });
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการลา");
|
||||||
|
|
||||||
|
const before = structuredClone(record);
|
||||||
|
const history = new ProfileLeaveHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
|
||||||
|
record.status = "CANCEL";
|
||||||
|
history.profileLeaveId = leaveId;
|
||||||
|
record.lastUpdateUserId = req.user.sub;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
record.lastUpdatedAt = new Date();
|
||||||
|
history.lastUpdateUserId = req.user.sub;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
history.createdUserId = req.user.sub;
|
||||||
|
history.createdFullName = req.user.name;
|
||||||
|
history.createdAt = new Date();
|
||||||
|
history.lastUpdatedAt = new Date();
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.leaveRepo.save(record, { data: req }),
|
||||||
|
setLogDataDiff(req, { before, after: record }),
|
||||||
|
this.leaveHistoryRepo.save(history, { data: req }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
@Delete("{leaveId}")
|
@Delete("{leaveId}")
|
||||||
public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) {
|
public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) {
|
||||||
const _record = await this.leaveRepo.findOneBy({ id: leaveId });
|
const _record = await this.leaveRepo.findOneBy({ id: leaveId });
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,14 @@ export class ProfileLeave extends EntityBase {
|
||||||
})
|
})
|
||||||
reason: string;
|
reason: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง LeaveRequest(hrms)",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
leaveId: string;
|
||||||
|
|
||||||
@OneToMany(() => ProfileLeaveHistory, (v) => v.profileLeave)
|
@OneToMany(() => ProfileLeaveHistory, (v) => v.profileLeave)
|
||||||
histories: ProfileLeaveHistory[];
|
histories: ProfileLeaveHistory[];
|
||||||
|
|
||||||
|
|
@ -124,6 +132,7 @@ export class CreateProfileLeave {
|
||||||
totalLeave?: number | null;
|
totalLeave?: number | null;
|
||||||
status?: string | null;
|
status?: string | null;
|
||||||
reason: string | null;
|
reason: string | null;
|
||||||
|
leaveId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileEmployeeLeave {
|
export class CreateProfileEmployeeLeave {
|
||||||
|
|
@ -136,6 +145,7 @@ export class CreateProfileEmployeeLeave {
|
||||||
totalLeave: number | null;
|
totalLeave: number | null;
|
||||||
status: string | null;
|
status: string | null;
|
||||||
reason: string | null;
|
reason: string | null;
|
||||||
|
leaveId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateProfileLeave = {
|
export type UpdateProfileLeave = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue