ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -25,6 +25,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
|||
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/training")
|
||||
@Tags("ProfileEmployeeTraining")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -94,7 +95,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileTraining();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -110,9 +111,10 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
const history = new ProfileTrainingHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
|
||||
await this.trainingRepo.save(data);
|
||||
await this.trainingRepo.save(data, { data: req });
|
||||
setLogDataDiff(req, { before, after: data });
|
||||
history.profileTrainingId = data.id;
|
||||
await this.trainingHistoryRepo.save(history);
|
||||
await this.trainingHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -127,7 +129,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -144,7 +146,11 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
history.createdAt = new Date();
|
||||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||
await Promise.all([
|
||||
this.trainingRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.trainingHistoryRepo.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue