ผูก 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 { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/assessments")
@Tags("ProfileEmployeeAssessments")
@Security("bearerAuth")
@ -88,9 +89,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
}
@Get("history/{assessmentId}")
public async getProfileAssessmentsHistory(
@Path() assessmentId: string,
) {
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
const record = await this.profileAssessmentsHistoryRepository.find({
where: {
profileAssessmentId: assessmentId,
@ -119,7 +118,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const before = null;
const data = new ProfileAssessment();
const meta = {
createdUserId: req.user.sub,
@ -133,9 +132,11 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
const history = new ProfileAssessmentHistory();
Object.assign(history, { ...data, id: undefined });
await this.profileAssessmentsRepository.save(data);
await this.profileAssessmentsRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAssessmentId = data.id;
await this.profileAssessmentsHistoryRepository.save(history);
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
}
@ -149,7 +150,8 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAssessmentHistory();
Object.assign(record, body);
@ -167,8 +169,10 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.profileAssessmentsRepository.save(record),
this.profileAssessmentsHistoryRepository.save(history),
this.profileAssessmentsRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();