ผูก 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 {
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/couple")
@Tags("ProfileFamilyCouple")
@Security("bearerAuth")
@ -165,6 +166,7 @@ export class ProfileFamilyCoupleController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name;
@ -177,11 +179,13 @@ export class ProfileFamilyCoupleController extends Controller {
const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined });
await this.profileRepo.save(profile);
await this.ProfileFamilyCouple.save(familyCouple);
await this.profileRepo.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
setLogDataDiff(req, { before, after: familyCouple });
history.profileFamilyCoupleId = familyCouple.id;
await this.ProfileFamilyCoupleHistory.save(history);
await this.ProfileFamilyCoupleHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyCouple.id);
}
@ -194,7 +198,8 @@ export class ProfileFamilyCoupleController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyCouple);
// const before_null = null;
const history = new ProfileFamilyCoupleHistory();
Object.assign(familyCouple, body);
Object.assign(history, { ...familyCouple, id: undefined });
@ -212,8 +217,10 @@ export class ProfileFamilyCoupleController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.ProfileFamilyCouple.save(familyCouple),
this.ProfileFamilyCoupleHistory.save(history),
this.ProfileFamilyCouple.save(familyCouple, { data: req }),
setLogDataDiff(req, { before, after: familyCouple }),
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();