From d543bf7f74f6cfde063c709a9504e9fbe3a2a48e Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:27:53 +0700 Subject: [PATCH] refactor: remove associated history on delete --- .../ProfileFamilyHistoryController.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 9dd58088..45727cb0 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -336,14 +336,16 @@ export class ProfileFamilyHistoryController extends Controller { } }), ...childrenRecord.map(async (v) => { - return await this.childrenHistoryRepo.save( - this.childrenHistoryRepo.create({ - ...v, - profileFamilyHistoryId: familyRecord.id, - profileChildrenId: children.find((x) => x.id === v.id) ? v.id : undefined, - id: undefined, - }), - ); + if (!children.find((x) => x.id === v.id)) { + return await this.childrenHistoryRepo.save( + this.childrenHistoryRepo.create({ + ...v, + profileFamilyHistoryId: familyRecord.id, + profileChildrenId: v.id, + id: undefined, + }), + ); + } }), ]);