fix: profile family endpoint behaviour
This commit is contained in:
parent
86b5221d24
commit
6ae3bc6be9
1 changed files with 13 additions and 16 deletions
|
|
@ -94,11 +94,11 @@ export class ProfileFamilyHistoryController extends Controller {
|
|||
public async getFamilyHistory(@Path() profileId: string) {
|
||||
const family = await this.familyHistoryRepo.find({
|
||||
take: 1,
|
||||
order: { createdAt: "DESC" },
|
||||
order: { lastUpdatedAt: "DESC" },
|
||||
where: { profileId },
|
||||
});
|
||||
const children = await this.childrenRepo.find({
|
||||
order: { createdAt: "DESC" },
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileId },
|
||||
});
|
||||
return new HttpSuccess(
|
||||
|
|
@ -227,7 +227,7 @@ export class ProfileFamilyHistoryController extends Controller {
|
|||
where: { profileId },
|
||||
});
|
||||
|
||||
family.pop();
|
||||
family.shift();
|
||||
|
||||
const record = await Promise.all(
|
||||
family.map(async (v) => ({
|
||||
|
|
@ -317,38 +317,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,
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue