ผูก 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 { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/family/father")
@Tags("ProfileEmployeeFamilyFather")
@Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name;
@ -172,9 +174,11 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined });
await this.ProfileFamilyFather.save(familyFather);
await this.ProfileFamilyFather.save(familyFather, { data: req });
setLogDataDiff(req, { before, after: familyFather });
history.profileFamilyFatherId = familyFather.id;
await this.ProfileFamilyFatherHistory.save(history);
await this.ProfileFamilyFatherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyFather.id);
}
@ -190,7 +194,8 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
profileEmployeeId: profileEmployeeId,
});
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyFather);
// const before_null = null;
const history = new ProfileFamilyFatherHistory();
Object.assign(familyFather, body);
Object.assign(history, { ...familyFather, id: undefined });
@ -208,8 +213,10 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.ProfileFamilyFather.save(familyFather),
this.ProfileFamilyFatherHistory.save(history),
this.ProfileFamilyFather.save(familyFather, { data: req }),
setLogDataDiff(req, { before, after: familyFather }),
this.ProfileFamilyFatherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();