ผูก 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-temp/family/couple")
@Tags("ProfileEmployeeFamilyCouple")
@Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
@Body() body: CreateProfileEmployeeFamilyCouple,
) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = null;
const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -182,10 +184,13 @@ export class ProfileFamilyCoupleEmployeeTempController 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);
}
@ -201,7 +206,8 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
profileEmployeeId: profileEmployeeId,
});
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 });
@ -219,8 +225,10 @@ export class ProfileFamilyCoupleEmployeeTempController 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();