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

@ -26,6 +26,7 @@ import { Profile } from "../entities/Profile";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/educations")
@Tags("ProfileEducations")
@Security("bearerAuth")
@ -85,9 +86,7 @@ export class ProfileEducationsController 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,
@ -114,7 +113,7 @@ export class ProfileEducationsController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileEducation();
const meta = {
createdUserId: req.user.sub,
@ -129,9 +128,11 @@ export class ProfileEducationsController 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();
}
@ -145,7 +146,8 @@ export class ProfileEducationsController extends Controller {
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory();
Object.assign(record, body);
@ -163,8 +165,10 @@ export class ProfileEducationsController 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();