refactor: history in database after first edit only

This commit is contained in:
Methapon2001 2024-03-12 18:00:50 +07:00
parent fd9218964e
commit 57719af5f3
4 changed files with 8 additions and 31 deletions

View file

@ -136,7 +136,6 @@ export class ProfileTrainingController extends Controller {
}
const data = new ProfileTraining();
const history = new ProfileTrainingHistory();
const meta = {
createdUserId: req.user.sub,
@ -148,11 +147,7 @@ export class ProfileTrainingController extends Controller {
Object.assign(data, { ...body, ...meta });
Object.assign(history, { ...body, ...meta });
const result = await this.trainingRepo.save(data);
history.profileTrainingId = result.id;
await this.trainingHistoryRepo.save(history);
await this.trainingRepo.save(data);
return new HttpSuccess();
}
@ -169,8 +164,8 @@ export class ProfileTrainingController extends Controller {
const history = new ProfileTrainingHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
Object.assign(history, { ...body, id: undefined });
history.profileTrainingId = trainingId;
record.lastUpdateFullName = req.user.name;
history.lastUpdateFullName = req.user.name;