ผูก 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 HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/ability")
@Tags("ProfileAbility")
@Security("bearerAuth")
@ -66,10 +67,10 @@ export class ProfileAbilityController extends Controller {
@Path() abilityId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId },
@ -83,9 +84,7 @@ export class ProfileAbilityController 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" },
@ -111,7 +110,7 @@ export class ProfileAbilityController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileAbility();
const meta = {
createdUserId: req.user.sub,
@ -126,10 +125,11 @@ export class ProfileAbilityController 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();
}
@ -144,7 +144,8 @@ export class ProfileAbilityController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileAbilityHistory();
const before = structuredClone(record);
// const before_null = null;
Object.assign(record, body);
Object.assign(history, { ...record, id: undefined });
@ -160,8 +161,10 @@ export class ProfileAbilityController 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();