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

@ -24,6 +24,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/ability")
@Tags("ProfileAbilityEmployee")
@Security("bearerAuth")
@ -88,9 +89,7 @@ export class ProfileAbilityEmployeeController extends Controller {
}
@Get("history/{abilityId}")
public async getProfileAbilityHistory(
@Path() abilityId: string,
) {
public async getProfileAbilityHistory(@Path() abilityId: string) {
const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId },
order: { createdAt: "DESC" },
@ -115,7 +114,7 @@ export class ProfileAbilityEmployeeController 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 ProfileAbility();
const meta = {
createdUserId: req.user.sub,
@ -130,9 +129,11 @@ export class ProfileAbilityEmployeeController extends Controller {
const history = new ProfileAbilityHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileAbilityRepo.save(data);
await this.profileAbilityRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAbilityId = data.id;
await this.profileAbilityHistoryRepo.save(history);
await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
}
@ -150,7 +151,8 @@ export class ProfileAbilityEmployeeController extends Controller {
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAbilityHistory();
Object.assign(record, body);
@ -168,8 +170,10 @@ export class ProfileAbilityEmployeeController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileAbilityRepo.save(record),
this.profileAbilityHistoryRepo.save(history),
this.profileAbilityRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileAbilityHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();