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

@ -22,6 +22,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/salary")
@Tags("ProfileSalary")
@Security("bearerAuth")
@ -105,7 +106,7 @@ export class ProfileSalaryController extends Controller {
where: { profileId: body.profileId },
order: { order: "DESC" },
});
const before = null;
const data = new ProfileSalary();
const meta = {
@ -122,9 +123,10 @@ export class ProfileSalaryController extends Controller {
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data);
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history);
await this.salaryHistoryRepo.save(history, { data: req });
return new HttpSuccess();
}
@ -138,7 +140,7 @@ export class ProfileSalaryController extends Controller {
const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileSalaryHistory();
Object.assign(record, body);
@ -155,7 +157,11 @@ export class ProfileSalaryController extends Controller {
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
await Promise.all([
this.salaryRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.salaryHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess();
}