ผูก 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-employee/family/mother")
@Tags("ProfileEmployeeFamilyMother")
@Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name;
@ -172,10 +174,11 @@ export class ProfileFamilyMotherEmployeeController 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);
}
@ -194,7 +197,8 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
const history = new ProfileFamilyMotherHistory();
Object.assign(familyMother, body);
Object.assign(history, { ...familyMother, id: undefined });
const before = structuredClone(familyMother);
// const before_null = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
history.profileFamilyMotherId = familyMother.id;
familyMother.lastUpdateUserId = req.user.sub;
@ -208,8 +212,10 @@ export class ProfileFamilyMotherEmployeeController 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();