refactor: history in database after first edit only
This commit is contained in:
parent
fd9218964e
commit
57719af5f3
4 changed files with 8 additions and 31 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,6 @@ export class ProfileHonorController extends Controller {
|
|||
}
|
||||
|
||||
const data = new ProfileHonor();
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -127,13 +126,8 @@ export class ProfileHonorController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
Object.assign(history, { ...body, ...meta });
|
||||
|
||||
const result = await this.honorRepo.save(data);
|
||||
|
||||
history.profileHonorId = result.id;
|
||||
|
||||
await this.honorHistoryRepo.save(history);
|
||||
await this.honorRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -150,8 +144,8 @@ export class ProfileHonorController extends Controller {
|
|||
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...body, id: undefined });
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ export class ProfileInsigniaController extends Controller {
|
|||
}
|
||||
|
||||
const data = new ProfileInsignia();
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -154,13 +153,8 @@ export class ProfileInsigniaController extends Controller {
|
|||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
Object.assign(history, { ...body, ...meta });
|
||||
|
||||
const result = await this.insigniaRepo.save(data);
|
||||
|
||||
history.profileInsigniaId = result.id;
|
||||
|
||||
await this.insigniaHistoryRepo.save(history);
|
||||
await this.insigniaRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -177,8 +171,8 @@ export class ProfileInsigniaController extends Controller {
|
|||
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...body, id: undefined });
|
||||
history.profileInsigniaId = insigniaId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue