ผูก 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 { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
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/certificate")
@Tags("ProfileEmployeeCertificate")
@Security("bearerAuth")
@ -87,7 +88,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const before = null;
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
@ -109,9 +110,11 @@ export class ProfileCertificateEmployeeTempController extends Controller {
const history = new ProfileCertificateHistory();
Object.assign(history, { ...data, id: undefined });
await this.certificateRepo.save(data);
await this.certificateRepo.save(data, { data: req });
setLogDataDiff( req , {before, after: data});
history.profileCertificateId = data.id;
await this.certificateHistoryRepo.save(history);
await this.certificateHistoryRepo.save(history, { data: req });
setLogDataDiff( req , {before, after: history});
return new HttpSuccess();
}
@ -126,7 +129,8 @@ export class ProfileCertificateEmployeeTempController extends Controller {
const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const before_null = null;
const history = new ProfileCertificateHistory();
Object.assign(record, body);
@ -144,10 +148,12 @@ export class ProfileCertificateEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.certificateRepo.save(record),
this.certificateHistoryRepo.save(history),
this.certificateRepo.save(record, { data: req }),
setLogDataDiff( req , {before, after: record}),
this.certificateHistoryRepo.save(history, { data: req }),
setLogDataDiff( req , {before: before_null, after: history}),
]);
return new HttpSuccess();
}