ผูก 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 { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/mother")
@Tags("ProfileFamilyMother")
@Security("bearerAuth")
@ -158,6 +159,7 @@ export class ProfileFamilyMotherController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name;
@ -169,9 +171,11 @@ export class ProfileFamilyMotherController extends Controller {
const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined });
await this.ProfileFamilyMother.save(familyMother);
await this.ProfileFamilyMother.save(familyMother, { data: req });
setLogDataDiff(req, { before, after: familyMother });
history.profileFamilyMotherId = familyMother.id;
await this.ProfileFamilyMotherHistory.save(history);
await this.ProfileFamilyMotherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyMother.id);
}
@ -185,7 +189,8 @@ export class ProfileFamilyMotherController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyMother);
// const before_null = null;
const history = new ProfileFamilyMotherHistory();
Object.assign(familyMother, body);
Object.assign(history, { ...familyMother, id: undefined });
@ -203,8 +208,10 @@ export class ProfileFamilyMotherController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.ProfileFamilyMother.save(familyMother),
this.ProfileFamilyMotherHistory.save(history),
this.ProfileFamilyMother.save(familyMother, { data: req }),
setLogDataDiff(req, { before, after: familyMother }),
this.ProfileFamilyMotherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();