Skip to content

Commit

Permalink
avniproject/avni-server#663 | Throw IgnorableSyncError when we are un…
Browse files Browse the repository at this point in the history
…able to find groupOrHousehold when syncing groupSubject mapping objects
  • Loading branch information
himeshr committed Dec 12, 2023
1 parent d5a10e5 commit a410a73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
32 changes: 23 additions & 9 deletions src/GroupSubject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/error/ErrorCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

0 comments on commit a410a73

Please sign in to comment.