Skip to content

Commit

Permalink
refactor: simplify extraction of fragments of accepte items
Browse files Browse the repository at this point in the history
  • Loading branch information
Milena-Czierlinski committed Dec 17, 2024
1 parent e1e242b commit 5d7a12e
Showing 1 changed file with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,7 @@ export function validateKeyUniquenessOfRelationshipAttributesWithinIncomingReque
);
}

const fragmentsOfAcceptedItemsOfRequest: RelationshipAttributeFragment[] = [];

for (let i = 0; i < items.length; i++) {
const item = items[i];
const decideItemParams = params[i];

if (item instanceof RequestItemGroup) {
const fragmentsOfAcceptedItemsOfGroup = extractRelationshipAttributeFragmentsFromAcceptedItemsOfGroup(item, decideItemParams as DecideRequestItemGroupParametersJSON);
if (fragmentsOfAcceptedItemsOfGroup) {
fragmentsOfAcceptedItemsOfRequest.push(...fragmentsOfAcceptedItemsOfGroup);
}
} else {
const fragmentOfAcceptedRequestItem = extractRelationshipAttributeFragmentFromAcceptedRequestItem(item, decideItemParams as DecideRequestItemParametersJSON);
if (fragmentOfAcceptedRequestItem) {
fragmentsOfAcceptedItemsOfRequest.push(fragmentOfAcceptedRequestItem);
}
}
}
const fragmentsOfAcceptedItemsOfRequest = extractRelationshipAttributeFragmentsFromAcceptedItems(items, params);

const containsAcceptedDuplicatesResult = containsDuplicateRelationshipAttributeFragments(fragmentsOfAcceptedItemsOfRequest);
if (containsAcceptedDuplicatesResult.containsDuplicates) {
Expand Down Expand Up @@ -107,36 +90,35 @@ function extractRelationshipAttributeFragmentsFromMustBeAcceptedItems(
return fragmentsOfMustBeAcceptedItemsOfGroup;
}

function extractRelationshipAttributeFragmentsFromAcceptedItemsOfGroup(
requestItemGroup: RequestItemGroup,
decideGroupParams: DecideRequestItemGroupParametersJSON
function extractRelationshipAttributeFragmentsFromAcceptedItems(
items: (RequestItem | RequestItemGroup)[],
params: (DecideRequestItemParametersJSON | DecideRequestItemGroupParametersJSON)[]
): RelationshipAttributeFragment[] | undefined {
const fragmentsOfAcceptedItemsOfGroup: RelationshipAttributeFragment[] = [];

for (let i = 0; i < requestItemGroup.items.length; i++) {
const item = requestItemGroup.items[i];
const decideItemParams = decideGroupParams.items[i];

if (item instanceof RequestItem) {
const fragment = extractRelationshipAttributeFragmentFromAcceptedRequestItem(item, decideItemParams);
if (fragment) fragmentsOfAcceptedItemsOfGroup.push(fragment);
}
}
const fragmentsOfAcceptedItemsOfRequest: RelationshipAttributeFragment[] = [];

if (fragmentsOfAcceptedItemsOfGroup.length !== 0) return fragmentsOfAcceptedItemsOfGroup;
for (let i = 0; i < items.length; i++) {
const item = items[i];
const decideItemParams = params[i];

return;
}
if (item instanceof RequestItemGroup) {
const fragmentsOfAcceptedItemsOfGroup = extractRelationshipAttributeFragmentsFromAcceptedItems(
item.items,
(decideItemParams as DecideRequestItemGroupParametersJSON).items
);
if (fragmentsOfAcceptedItemsOfGroup) {
fragmentsOfAcceptedItemsOfRequest.push(...fragmentsOfAcceptedItemsOfGroup);
}
} else {
if (!(decideItemParams as DecideRequestItemParametersJSON).accept) return;

function extractRelationshipAttributeFragmentFromAcceptedRequestItem(
requestItem: RequestItem,
decideItemParams: DecideRequestItemParametersJSON
): RelationshipAttributeFragment | undefined {
if (decideItemParams.accept) {
return extractRelationshipAttributeFragmentFromRequestItem(requestItem);
const fragmentOfAcceptedRequestItem = extractRelationshipAttributeFragmentFromRequestItem(item);
if (fragmentOfAcceptedRequestItem) {
fragmentsOfAcceptedItemsOfRequest.push(fragmentOfAcceptedRequestItem);
}
}
}

return;
return fragmentsOfAcceptedItemsOfRequest;
}

function extractRelationshipAttributeFragmentFromRequestItem(requestItem: RequestItem, recipient?: CoreAddress): RelationshipAttributeFragment | undefined {
Expand Down

0 comments on commit 5d7a12e

Please sign in to comment.