แก้ api เก็บประวัติแก้ทะเบียน

This commit is contained in:
kittapath 2024-08-13 17:43:30 +07:00
parent 576f6bcc0d
commit fd3f1fa515
62 changed files with 855 additions and 1471 deletions

View file

@ -82,23 +82,16 @@ export class ProfileChildrenController extends Controller {
Object.assign(data, { ...body, ...meta });
data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId));
await this.childrenRepository.save(data);
if (data) {
const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), {
profileChildrenId: data.id,
childrenCareer: data.childrenCareer,
childrenFirstName: data.childrenFirstName,
childrenLastName: data.childrenLastName,
childrenPrefix: data.childrenPrefix,
childrenLive: data.childrenLive,
childrenCitizenId: data.childrenCitizenId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await this.childrenHistoryRepository.save(history);
}
const history = new ProfileChildrenHistory();
history.profileChildrenId = data.id;
await Promise.all([
this.childrenRepository.save(data),
(history.profileChildrenId = data.id),
this.childrenHistoryRepository.save(history),
]);
return new HttpSuccess();
}
@ -113,19 +106,17 @@ export class ProfileChildrenController extends Controller {
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileChildrenHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
Object.assign(history, body);
record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId));
history.profileChildrenId = record.id;
history.childrenCareer = record.childrenCareer;
history.childrenFirstName = record.childrenFirstName;
history.childrenLastName = record.childrenLastName;
history.childrenPrefix = record.childrenPrefix;
history.childrenLive = record.childrenLive;
history.childrenCitizenId = record.childrenCitizenId;
(history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name);
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
await Promise.all([
this.childrenRepository.save(record),
this.childrenHistoryRepository.save(history),