ผูก 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 { Profile } from "../entities/Profile";
import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia")
@Security("bearerAuth")
@ -124,7 +125,7 @@ export class ProfileInsigniaController extends Controller {
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const before = null;
const data = new ProfileInsignia();
const meta = {
@ -140,9 +141,10 @@ export class ProfileInsigniaController 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();
}
@ -163,7 +165,7 @@ export class ProfileInsigniaController extends Controller {
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const before = structuredClone(record);
const history = new ProfileInsigniaHistory();
Object.assign(record, body);
@ -180,7 +182,11 @@ export class ProfileInsigniaController 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();
}