Skip to content

Commit

Permalink
fix: remove completedAt and completedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Nov 5, 2024
1 parent 51e4051 commit b799ac0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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: [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,7 +36,6 @@ import {
import { buildUrlQueryString } from '../../../utils/routing/buildUrlQueryString';
import { newEventWidgetActionTypes } from '../../WidgetEnrollmentEventNew/Validated/validated.actions';
import { enrollmentEditEventActionTypes } from '../../Pages/EnrollmentEditEvent';
import { statusTypes } from '../../../events/statusTypes';

const getDataEntryId = (event): string => (
getScopeInfo(event?.programId)?.scopeType === scopeTypes.TRACKER_PROGRAM
Expand Down Expand Up @@ -107,13 +104,6 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore,
const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, minor);

if (mainDataServerValues.status === statusTypes.COMPLETED && !prevEventMainData.completedAt) {
mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment());
}
if (mainDataServerValues.status === statusTypes.ACTIVE) {
mainDataServerValues.completedAt = null;
mainDataServerValues.completedBy = null;
}

const { eventContainer: prevEventContainer } = state.viewEventPage.loadedValues;

Expand Down Expand Up @@ -275,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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':
Expand All @@ -34,5 +38,5 @@ export function convertMainEventClientToServer(event: Object, serverMinorVersion
}

return convertedValue;
});
}, keysToSkip);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b799ac0

Please sign in to comment.