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