ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/assessments")
|
||||
@Tags("ProfileAssessments")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -123,7 +124,7 @@ export class ProfileAssessmentsController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAssessment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -137,9 +138,11 @@ export class ProfileAssessmentsController 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();
|
||||
}
|
||||
|
|
@ -153,7 +156,8 @@ export class ProfileAssessmentsController extends Controller {
|
|||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
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 ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -171,8 +175,10 @@ export class ProfileAssessmentsController 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, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue