ผูก 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

@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/duty")
@Tags("ProfileEmployeeDuty")
@Security("bearerAuth")
@ -82,7 +83,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const before = null;
const data = new ProfileDuty();
const meta = {
@ -98,9 +99,11 @@ export class ProfileDutyEmployeeTempController extends Controller {
const history = new ProfileDutyHistory();
Object.assign(history, { ...data, id: undefined });
await this.dutyRepository.save(data);
await this.dutyRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDutyId = data.id;
await this.dutyHistoryRepository.save(history);
await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
}
@ -115,7 +118,8 @@ export class ProfileDutyEmployeeTempController extends Controller {
const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileDutyHistory();
Object.assign(record, body);
@ -132,7 +136,12 @@ export class ProfileDutyEmployeeTempController extends Controller {
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
await Promise.all([
this.dutyRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.dutyHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();
}