ผูก 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 {
UpdateProfileNopaid,
} from "../entities/ProfileNopaid";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/nopaid")
@Tags("ProfileNopaid")
@Security("bearerAuth")
@ -79,7 +80,7 @@ export class ProfileNopaidEmployeeController 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 ProfileNopaid();
const meta = {
@ -95,9 +96,10 @@ export class ProfileNopaidEmployeeController extends Controller {
const history = new ProfileNopaidHistory();
Object.assign(history, { ...data, id: undefined });
await this.nopaidRepository.save(data);
await this.nopaidRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history);
await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess();
}
@ -116,6 +118,7 @@ export class ProfileNopaidEmployeeController extends Controller {
record.profileEmployeeId,
);
const before = structuredClone(record);
const history = new ProfileNopaidHistory();
Object.assign(record, body);
@ -133,8 +136,9 @@ export class ProfileNopaidEmployeeController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.nopaidRepository.save(record),
this.nopaidHistoryRepository.save(history),
this.nopaidRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.nopaidHistoryRepository.save(history, { data: req }),
]);
return new HttpSuccess();