ผูก log เมนูทะเบียนประวัติ

This commit is contained in:
AdisakKanthawilang 2024-10-03 15:57:44 +07:00
parent 5643cc67c4
commit 6539804937
76 changed files with 909 additions and 431 deletions

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { LeaveType } from "../entities/LeaveType";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/leave")
@Tags("ProfileLeave")
@Security("bearerAuth")
@ -188,7 +189,7 @@ export class ProfileLeaveController extends Controller {
if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
}
const before = null;
const data = new ProfileLeave();
const meta = {
@ -204,9 +205,10 @@ export class ProfileLeaveController extends Controller {
const history = new ProfileLeaveHistory();
Object.assign(history, { ...data, id: undefined });
await this.leaveRepo.save(data);
await this.leaveRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data });
history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history);
await this.leaveHistoryRepo.save(history, { data: req });
return new HttpSuccess();
}
@ -227,7 +229,7 @@ export class ProfileLeaveController extends Controller {
if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
}
const before = structuredClone(record);
const history = new ProfileLeaveHistory();
Object.assign(record, body);
@ -244,7 +246,11 @@ export class ProfileLeaveController extends Controller {
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
await Promise.all([
this.leaveRepo.save(record, { data: req }),
setLogDataDiff( req, { before, after: record }),
this.leaveHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess();
}