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

@ -123,7 +123,6 @@ export class ProfileCertificateController extends Controller {
}
const data = new ProfileCertificate();
const history = new ProfileCertificateHistory();
const meta = {
createdUserId: req.user.sub,
@ -133,13 +132,8 @@ export class ProfileCertificateController extends Controller {
};
Object.assign(data, { ...body, ...meta });
Object.assign(history, { ...body, ...meta });
const result = await this.certificateRepo.save(data);
history.profileCertificateId = result.id;
await this.certificateHistoryRepo.save(history);
await this.certificateRepo.save(data);
return new HttpSuccess();
}
@ -156,8 +150,8 @@ export class ProfileCertificateController extends Controller {
const history = new ProfileCertificateHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
Object.assign(history, { ...body, id: undefined });
history.profileCertificateId = certificateId;
record.lastUpdateFullName = req.user.name;
history.lastUpdateFullName = req.user.name;