diff --git a/cypress/e2e/EnrollmentAddEventPage/EnrollmentAddEventPageForm/EnrollmentAddEventPageForm.js b/cypress/e2e/EnrollmentAddEventPage/EnrollmentAddEventPageForm/EnrollmentAddEventPageForm.js index f5369a15cf..ca8d21ed03 100644 --- a/cypress/e2e/EnrollmentAddEventPage/EnrollmentAddEventPageForm/EnrollmentAddEventPageForm.js +++ b/cypress/e2e/EnrollmentAddEventPage/EnrollmentAddEventPageForm/EnrollmentAddEventPageForm.js @@ -11,7 +11,7 @@ const changeEnrollmentAndEventsStatus = () => ( const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'FZAa7j0muDj'); const eventToDelete = enrollment.events.find(e => e.programStage === 'eHvTba5ijAh'); const { events, ...rest } = enrollment; - const enrollmentToUpdate = { ...rest, status: 'ACTIVE' }; + const enrollmentToUpdate = { ...rest, status: 'ACTIVE', completedAt: null, completedBy: null }; return cy .buildApiUrl('tracker?async=false&importStrategy=UPDATE') diff --git a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js index bd8c7855fc..70468a3a93 100644 --- a/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js +++ b/cypress/e2e/EnrollmentEditEventPage/EnrollmentEditEventPageForm/EnrollmentEditEventPageForm.js @@ -13,7 +13,9 @@ const changeEnrollmentAndEventsStatus = () => ( const enrollmentToUpdate = { ...enrollment, status: 'ACTIVE', - events: [{ ...eventToUpdate, status: 'ACTIVE' }], + completedAt: null, + completedBy: null, + events: [{ ...eventToUpdate, status: 'ACTIVE', completedAt: null, completedBy: null }], }; return cy diff --git a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js index fb01545e49..5303500a8d 100644 --- a/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js +++ b/cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js @@ -13,8 +13,19 @@ const changeEnrollmentAndEventsStatus = () => ( .then(url => cy.request(url)) .then(({ body }) => { const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'qyx7tscVpVB'); - const eventsToUpdate = enrollment.events.map(e => ({ ...e, status: 'ACTIVE' })); - const enrollmentToUpdate = { ...enrollment, status: 'ACTIVE', events: eventsToUpdate }; + const eventsToUpdate = enrollment.events.map(e => ({ + ...e, + status: 'ACTIVE', + completedAt: null, + completedBy: null, + })); + const enrollmentToUpdate = { + ...enrollment, + status: 'ACTIVE', + completedAt: null, + completedBy: null, + events: eventsToUpdate, + }; return cy .buildApiUrl('tracker?async=false&importStrategy=UPDATE') diff --git a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/getConvertedNewSingleEvent.js b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/getConvertedNewSingleEvent.js index 2ea63a18e5..d15ed0cf2e 100644 --- a/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/getConvertedNewSingleEvent.js +++ b/src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/epics/getConvertedNewSingleEvent.js @@ -1,6 +1,4 @@ // @flow -import moment from 'moment'; -import { getFormattedStringFromMomentUsingEuropeanGlyphs } from 'capture-core-utils/date'; import { convertDataEntryToClientValues } from '../../../../../DataEntry/common/convertDataEntryToClientValues'; import { convertValue as convertToServerValue } from '../../../../../../converters/clientToServer'; import { convertMainEventClientToServer } from '../../../../../../events/mainConverters'; @@ -27,10 +25,6 @@ export const getNewEventServerData = (state: ReduxState, formFoundation: RenderF const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue); const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, serverMinorVersion); - if (mainDataServerValues.status === 'COMPLETED') { - mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment()); - } - return { events: [{ ...mainDataServerValues, @@ -64,9 +58,6 @@ export const getAddEventEnrollmentServerData = (state: ReduxState, if (!mainDataServerValues.status) { mainDataServerValues.status = completed ? 'ACTIVE' : 'COMPLETED'; } - if (mainDataServerValues.status === 'COMPLETED') { - mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment()); - } return { events: [ diff --git a/src/core_modules/capture-core/components/DataEntry/common/convertEventToServerValues.js b/src/core_modules/capture-core/components/DataEntry/common/convertEventToServerValues.js deleted file mode 100644 index 0a1b842db5..0000000000 --- a/src/core_modules/capture-core/components/DataEntry/common/convertEventToServerValues.js +++ /dev/null @@ -1,32 +0,0 @@ -// @flow -import { convertValue } from '../../../converters/clientToServer'; -import { dataElementTypes } from '../../../metaData'; - -const mapEventClientKeyToServerKey = { - eventId: 'event', - programId: 'program', - programStageId: 'programStage', - orgUnitId: 'orgUnit', - trackedEntityInstanceId: 'trackedEntityInstance', - enrollmentId: 'enrollment', -}; - -export function getServerValuesToSaveFromMainEvent(event: CaptureClientEvent) { - return Object - .keys(event) - .reduce((accServerEvent, inputKey) => { - const valueToConvert = event[inputKey]; - let convertedValue; - if (inputKey === 'occurredAt' || inputKey === 'scheduledAt' || inputKey === 'completedAt') { - convertedValue = convertValue(valueToConvert, dataElementTypes.DATE); - } else { - convertedValue = valueToConvert; - } - - - // $FlowFixMe[prop-missing] automated comment - const outputKey = mapEventClientKeyToServerKey[inputKey] || inputKey; - accServerEvent[outputKey] = convertedValue; - return accServerEvent; - }, {}); -} diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedAddEvent.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedAddEvent.js index c46469a709..bbfb66046c 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedAddEvent.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedAddEvent.js @@ -1,6 +1,5 @@ // @flow import moment from 'moment'; -import { getFormattedStringFromMomentUsingEuropeanGlyphs } from 'capture-core-utils/date'; import { convertDataEntryToClientValues } from '../../DataEntry/common/convertDataEntryToClientValues'; import { convertValue as convertToServerValue } from '../../../converters/clientToServer'; import { convertMainEventClientToServer } from '../../../events/mainConverters'; @@ -44,9 +43,6 @@ export const getAddEventEnrollmentServerData = ({ if (!mainDataServerValues.status) { mainDataServerValues.status = completed ? 'COMPLETED' : 'ACTIVE'; } - if (mainDataServerValues.status === 'COMPLETED') { - mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment()); - } return { ...mainDataServerValues, diff --git a/src/core_modules/capture-core/components/WidgetEventEdit/EditEventDataEntry/editEventDataEntry.epics.js b/src/core_modules/capture-core/components/WidgetEventEdit/EditEventDataEntry/editEventDataEntry.epics.js index 217e656bf4..de9c392677 100644 --- a/src/core_modules/capture-core/components/WidgetEventEdit/EditEventDataEntry/editEventDataEntry.epics.js +++ b/src/core_modules/capture-core/components/WidgetEventEdit/EditEventDataEntry/editEventDataEntry.epics.js @@ -3,9 +3,7 @@ import { ofType } from 'redux-observable'; import { map, filter, flatMap } from 'rxjs/operators'; import { batchActions } from 'redux-batched-actions'; import { dataEntryKeys, dataEntryIds } from 'capture-core/constants'; -import moment from 'moment'; import { EMPTY } from 'rxjs'; -import { getFormattedStringFromMomentUsingEuropeanGlyphs } from 'capture-core-utils/date'; import { convertCategoryOptionsToServer, convertValue as convertToServerValue } from '../../../converters/clientToServer'; import { getProgramAndStageFromEvent, scopeTypes, getScopeInfo } from '../../../metaData'; import { openEventForEditInDataEntry } from '../DataEntry/editEventDataEntry.actions'; @@ -106,9 +104,6 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore, const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue); const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, minor); - if (mainDataServerValues.status === 'COMPLETED' && !prevEventMainData.completedAt) { - mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment()); - } const { eventContainer: prevEventContainer } = state.viewEventPage.loadedValues; @@ -270,10 +265,6 @@ export const saveEventAndCompleteEnrollmentEpic = (action$: InputObservable, sto const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue); const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, minor); - if (!prevEventMainData.completedAt) { - mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment()); - } - const editEvent = { ...mainDataServerValues, attributeOptionCombo: undefined, diff --git a/src/core_modules/capture-core/events/mainConverters/mainEventClientToServerConverter.js b/src/core_modules/capture-core/events/mainConverters/mainEventClientToServerConverter.js index ada4476c31..25d5042c43 100644 --- a/src/core_modules/capture-core/events/mainConverters/mainEventClientToServerConverter.js +++ b/src/core_modules/capture-core/events/mainConverters/mainEventClientToServerConverter.js @@ -4,6 +4,11 @@ import { convertMainEvent } from './mainEventConverter'; import { dataElementTypes } from '../../metaData'; import { convertEventAttributeOptions } from '../convertEventAttributeOptions'; +const keysToSkip = { + completedAt: 'completedAt', + completedBy: 'completedBy', +}; + export function convertMainEventClientToServer(event: Object, serverMinorVersion: number) { const mapClientKeyToServerKey = { eventId: 'event', @@ -22,7 +27,6 @@ export function convertMainEventClientToServer(event: Object, serverMinorVersion switch (key) { case 'occurredAt': case 'scheduledAt': - case 'completedAt': convertedValue = convertClientToServer(value, dataElementTypes.DATE); break; case 'assignee': @@ -34,5 +38,5 @@ export function convertMainEventClientToServer(event: Object, serverMinorVersion } return convertedValue; - }); + }, keysToSkip); } diff --git a/src/core_modules/capture-core/events/mainConverters/mainEventConverter.js b/src/core_modules/capture-core/events/mainConverters/mainEventConverter.js index 17ca9513b5..1db2149b83 100644 --- a/src/core_modules/capture-core/events/mainConverters/mainEventConverter.js +++ b/src/core_modules/capture-core/events/mainConverters/mainEventConverter.js @@ -3,10 +3,14 @@ export function convertMainEvent( event: Object, keyMap: Object = {}, onConvert: (key: string, value: any) => any, + keysToSkip?: {[keyId: string]: string}, ) { return Object .keys(event) .reduce((accConvertedEvent, key) => { + if (keysToSkip && keysToSkip[key]) { + return accConvertedEvent; + } const convertedValue = onConvert(key, event[key]); const outputKey = keyMap[key] || key; accConvertedEvent[outputKey] = convertedValue;