ผูก 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

@ -24,6 +24,7 @@ import {
UpdateProfileOther,
} from "../entities/ProfileOther";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/other")
@Tags("ProfileOther")
@Security("bearerAuth")
@ -92,7 +93,7 @@ export class ProfileOtherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileOther();
const meta = {
@ -108,9 +109,10 @@ export class ProfileOtherEmployeeController extends Controller {
const history = new ProfileOtherHistory();
Object.assign(history, { ...data, id: undefined });
await this.otherRepository.save(data);
await this.otherRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history);
await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess();
}
@ -128,7 +130,7 @@ export class ProfileOtherEmployeeController extends Controller {
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const before = structuredClone(record);
const history = new ProfileOtherHistory();
Object.assign(record, body);
@ -146,8 +148,9 @@ export class ProfileOtherEmployeeController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.otherRepository.save(record),
this.otherHistoryRepository.save(history),
this.otherRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.otherHistoryRepository.save(history, { data: req }),
]);
return new HttpSuccess();