Skip to content

Commit

Permalink
feat: business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Nov 4, 2023
1 parent 07b2023 commit e9ae4bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,34 @@ const getEventDetailsByReferralMode = ({
const { scheduledAt: referralScheduledAt, orgUnit: referralOrgUnit } = referralDataValues;

return ({
...baseEventDetails,
scheduledAt: referralScheduledAt,
orgUnit: referralOrgUnit?.id,
referralEvent: {
...baseEventDetails,
scheduledAt: referralScheduledAt,
orgUnit: referralOrgUnit?.id,
},
linkedEventId: baseEventDetails.event,
});
} else if (referralMode === ReferralModes.ENTER_DATA) {
return ({
...baseEventDetails,
scheduledAt: clientRequestEvent.occurredAt,
orgUnit: clientRequestEvent.orgUnit,
referralEvent: {
...baseEventDetails,
scheduledAt: clientRequestEvent.occurredAt,
orgUnit: clientRequestEvent.orgUnit,
},
linkedEventId: baseEventDetails.event,
});
} else if (referralMode === ReferralModes.LINK_EXISTING_RESPONSE) {
const { linkedEventId } = referralDataValues;
return {
referralEvent: null,
linkedEventId,
};
}

log.error(errorCreator(`Referral mode ${referralMode} is not supported`)());
return {
...baseEventDetails,
orgUnit: '',
referralEvent: null,
linkedEventId: null,
};
};

Expand All @@ -62,7 +74,7 @@ export const getConvertedReferralEvent = ({
}: ConvertedReferralEventProps) => {
const requestEventIsFromConstraint = referralType.fromConstraint.programStage.id === currentProgramStageId;

const referralEvent = getEventDetailsByReferralMode({
const { referralEvent, linkedEventId } = getEventDetailsByReferralMode({
referralDataValues,
requestEventIsFromConstraint,
referralMode,
Expand All @@ -77,12 +89,12 @@ export const getConvertedReferralEvent = ({
relationshipType: referralType.id,
from: {
event: {
event: requestEventIsFromConstraint ? clientRequestEvent.event : referralEvent.event,
event: requestEventIsFromConstraint ? clientRequestEvent.event : linkedEventId,
},
},
to: {
event: {
event: requestEventIsFromConstraint ? referralEvent.event : clientRequestEvent.event,
event: requestEventIsFromConstraint ? linkedEventId : clientRequestEvent.event,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const useAvailableReferralEvents = ({
query,
{
enabled: !!stageId && enabled,
cacheTime: 0,
staleTime: 0,
select: (response: any) => {
const events = response?.instances;
if (events.length === 0) return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const useApiDataQuery = <TResultData>(
[ReactQueryAppNamespace, ...queryKey],
queryFn,
{
...queryOptions,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
staleTime: 2 * 60 * 1000,
cacheTime: 5 * 60 * 1000,
...queryOptions,
});
};

0 comments on commit e9ae4bd

Please sign in to comment.