ผูก 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 { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/educations")
@Tags("ProfileEducationsEmployee")
@Security("bearerAuth")
@ -83,9 +84,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
}
@Get("history/{educationId}")
public async getProfileEducationHistory(
@Path() educationId: string,
) {
public async getProfileEducationHistory(@Path() educationId: string) {
const record = await this.profileEducationHistoryRepo.find({
where: {
profileEducationId: educationId,
@ -112,7 +111,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const before = null;
const data = new ProfileEducation();
const meta = {
createdUserId: req.user.sub,
@ -127,10 +126,11 @@ export class ProfileEducationsEmployeeTempController extends Controller {
const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileEducationRepo.save(data);
await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history);
await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
}
@ -143,7 +143,8 @@ export class ProfileEducationsEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory();
Object.assign(record, body);
@ -161,8 +162,10 @@ export class ProfileEducationsEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileEducationRepo.save(record),
this.profileEducationHistoryRepo.save(history),
this.profileEducationRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileEducationHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();