Merge branch 'dev/methapon' into develop

This commit is contained in:
Methapon2001 2024-03-21 16:21:44 +07:00
commit 0df596e7fb

View file

@ -221,7 +221,7 @@ export class ProfileFamilyHistoryController extends Controller {
where: { profileId },
});
family.pop();
family.shift();
const record = await Promise.all(
family.map(async (v) => ({
@ -312,38 +312,35 @@ export class ProfileFamilyHistoryController extends Controller {
const newChild: CreateChildren[] = [];
for (let child of children) {
let match = childrenRecord.find((v) => v.id === child.id);
if (match) Object.assign(match, child);
else {
let newProfileChild = new ProfileChildren();
Object.assign(newProfileChild, {
newChild.push(
Object.assign(new ProfileChildren(), {
...child,
profileId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
id: undefined,
});
newChild.push(newProfileChild);
}
id: !childrenRecord.find((v) => v.id === child.id) ? undefined : child.id,
}),
);
}
await Promise.all([
this.familyHistoryRepo.save(historyData),
this.familyHistoryRepo.save({ ...historyData, lastUpdatedAt: undefined }),
...newChild.map(async (v) => {
return await this.childrenRepo.save(v);
}),
...childrenRecord.map(async (v) => {
return await this.childrenRepo.save(v);
if (!children.find((x) => x.id === v.id)) {
return await this.childrenRepo.delete({ id: v.id });
}
}),
...childrenRecord.map(async (v) => {
return await this.childrenHistoryRepo.save(
this.childrenHistoryRepo.create({
...v,
profileFamilyHistoryId: familyRecord.id,
profileChildrenId: v.id,
profileChildrenId: children.find((x) => x.id === v.id) ? v.id : undefined,
id: undefined,
}),
);