Skip to content

Commit

Permalink
fix: [DHIS2-18248] pass on createdAt to rules engine when editing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoakimSM committed Oct 17, 2024
1 parent fba5ecb commit 46caa2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type EventMain = {
+status?: $Values<eventStatuses>,
+occurredAt?: string,
+scheduledAt?: string,
+createdAt?: string,
};

export type EventValues = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,21 @@ const runRulesForEditSingleEvent = ({
if (program instanceof TrackerProgram) {
const { enrollment, attributeValues } = state.enrollmentDomain;

const { apiOtherEvents, apiCurrentEventOriginal } = enrollment.events.reduce((acc, apiEvent) => {
if (apiEvent.event === currentEvent.eventId) {
acc.apiCurrentEventOriginal = apiEvent;
} else {
acc.apiOtherEvents.push(apiEvent);
}
return acc;
}, { apiOtherEvents: [] });

effects = getApplicableRuleEffectsForTrackerProgram({
program,
stage,
orgUnit,
currentEvent,
otherEvents: prepareEnrollmentEventsForRulesEngine(
enrollment?.events.filter(enrollmentEvent => enrollmentEvent.event !== currentEvent.eventId),
),
currentEvent: { ...currentEvent, createdAt: apiCurrentEventOriginal.createdAt },
otherEvents: prepareEnrollmentEventsForRulesEngine(apiOtherEvents),
enrollmentData: getEnrollmentForRulesEngine(enrollment),
attributeValues: getAttributeValuesForRulesEngine(attributeValues, program.attributes),
});
Expand Down

0 comments on commit 46caa2b

Please sign in to comment.