ผูก 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 { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/insignia")
@Tags("ProfileEmployeeInsignia")
@Security("bearerAuth")
@ -122,7 +123,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const before = null;
const data = new ProfileInsignia();
const meta = {
@ -138,9 +139,10 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
const history = new ProfileInsigniaHistory();
Object.assign(history, { ...data, id: undefined });
await this.insigniaRepo.save(data);
await this.insigniaRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history);
await this.insigniaHistoryRepo.save(history, { data:req });
return new HttpSuccess();
}
@ -162,7 +164,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const before = structuredClone(record);
const history = new ProfileInsigniaHistory();
Object.assign(record, body);
@ -179,7 +181,11 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
await Promise.all([
this.insigniaRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.insigniaHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess();
}