From a410a73a2767e96b48506d53c235b3ee620020cb Mon Sep 17 00:00:00 2001 From: himeshr Date: Tue, 12 Dec 2023 17:10:45 +0530 Subject: [PATCH] avniproject/avni-server#663 | Throw IgnorableSyncError when we are unable to find groupOrHousehold when syncing groupSubject mapping objects --- src/GroupSubject.js | 32 +++++++++++++++++++++++--------- src/error/ErrorCodes.js | 3 ++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/GroupSubject.js b/src/GroupSubject.js index 01692ed0..2c818b97 100644 --- a/src/GroupSubject.js +++ b/src/GroupSubject.js @@ -5,7 +5,9 @@ import ResourceUtil from "./utility/ResourceUtil"; import General from "./utility/General"; import GroupRole from "./GroupRole"; + class GroupSubject extends BaseEntity { + static EXPLICIT_ERROR_CODE_KEY_FOR_MISSING_GROUP = 'GroupSubjectMapping-GroupSubject-Association'; static schema = { name: "GroupSubject", primaryKey: "uuid", @@ -102,15 +104,27 @@ class GroupSubject extends BaseEntity { } static fromResource(resource, entityService) { - const groupSubject = entityService.findByKey( - "uuid", - ResourceUtil.getUUIDFor(resource, "groupSubjectUUID"), - Individual.schema.name + const childResource = resource; + const childEntityClass = GroupSubject; + const parentSchema = Individual.schema.name; + const groupSubjectParentIdField = "groupSubjectUUID"; + const memberSubjectParentIdField = "memberSubjectUUID"; + + const groupOrHouseholdSubject = BaseEntity.getParentEntity( + entityService, + childEntityClass, + childResource, + groupSubjectParentIdField, + parentSchema, + true, + GroupSubject.EXPLICIT_ERROR_CODE_KEY_FOR_MISSING_GROUP ); - const memberSubject = entityService.findByKey( - "uuid", - ResourceUtil.getUUIDFor(resource, "memberSubjectUUID"), - Individual.schema.name + const memberSubject = BaseEntity.getParentEntity( + entityService, + childEntityClass, + childResource, + memberSubjectParentIdField, + parentSchema ); const groupRole = entityService.findByKey( "uuid", @@ -123,7 +137,7 @@ class GroupSubject extends BaseEntity { ["uuid", "voided"], ["membershipStartDate", "membershipEndDate"] ); - groupSubjectEntity.groupSubject = groupSubject; + groupSubjectEntity.groupSubject = groupOrHouseholdSubject; groupSubjectEntity.memberSubject = memberSubject; groupSubjectEntity.groupRole = groupRole; return groupSubjectEntity; diff --git a/src/error/ErrorCodes.js b/src/error/ErrorCodes.js index bff5df0c..bf40fce8 100644 --- a/src/error/ErrorCodes.js +++ b/src/error/ErrorCodes.js @@ -12,5 +12,6 @@ export const ErrorCodes = Object.freeze({ 'Checklist-ProgramEnrolment-Association': 'Association error 11', 'ChecklistItem-Checklist-Association': 'Association error 12', 'VideoTelemetric-Video-Association': 'Association error 13', - 'NoCatchmentFound': 'NoCatchmentFoundErrorMessage' + 'NoCatchmentFound': 'NoCatchmentFoundErrorMessage', + 'GroupSubjectMapping-GroupSubject-Association' : 'Ignorable Association error 01', });