ผูก 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-employee/duty")
@Tags("ProfileEmployeeDuty")
@Security("bearerAuth")
@ -88,7 +89,7 @@ export class ProfileDutyEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileDuty();
const meta = {
@ -104,9 +105,11 @@ export class ProfileDutyEmployeeController 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();
}
@ -124,7 +127,8 @@ export class ProfileDutyEmployeeController extends Controller {
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
const before_null = null;
const history = new ProfileDutyHistory();
Object.assign(record, body);
@ -141,7 +145,12 @@ export class ProfileDutyEmployeeController 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, after: history }),
]);
return new HttpSuccess();
}