ผูก 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 { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/honor")
@Tags("ProfileEmployeeHonor")
@Security("bearerAuth")
@ -112,7 +113,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const before = null;
const data = new ProfileHonor();
const meta = {
@ -128,9 +129,10 @@ export class ProfileHonorEmployeeTempController extends Controller {
const history = new ProfileHonorHistory();
Object.assign(history, { ...data, id: undefined });
await this.honorRepo.save(data);
await this.honorRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history);
await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess();
}
@ -145,7 +147,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileHonorHistory();
Object.assign(record, body);
@ -162,7 +164,11 @@ export class ProfileHonorEmployeeTempController extends Controller {
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
await Promise.all([
this.honorRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.honorHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess();
}