From 5d5a11339a9f4f19f77c7e9e081d9c3a99bb9228 Mon Sep 17 00:00:00 2001 From: eirikhaugstulen Date: Mon, 26 Aug 2024 10:19:09 +0200 Subject: [PATCH] fix: use relevant date format --- .../validators/form/date.validator.js | 1 + .../getConvertedRelatedStageEvent.js | 14 +++++++++----- .../converters/date/stringToMomentDateFormat.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core_modules/capture-core-utils/validators/form/date.validator.js b/src/core_modules/capture-core-utils/validators/form/date.validator.js index 3c298feb88..fe14203f11 100644 --- a/src/core_modules/capture-core-utils/validators/form/date.validator.js +++ b/src/core_modules/capture-core-utils/validators/form/date.validator.js @@ -4,6 +4,7 @@ import { parseDate } from '../../parsers'; * * @export * @param {string} value + * @param {string} format * @returns {boolean} */ export function isValidDate(value: string, format: string) { diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedRelatedStageEvent/getConvertedRelatedStageEvent.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedRelatedStageEvent/getConvertedRelatedStageEvent.js index 3bae2a173c..061f7a5fe4 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedRelatedStageEvent/getConvertedRelatedStageEvent.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/getConvertedRelatedStageEvent/getConvertedRelatedStageEvent.js @@ -3,8 +3,12 @@ import log from 'loglevel'; import { generateUID } from '../../../../utils/uid/generateUID'; import { actions as RelatedStageModes } from '../../../WidgetRelatedStages/constants'; import type { ConvertedRelatedStageEventProps } from './getConvertedRelatedStageEvent.types'; -import { errorCreator } from '../../../../../capture-core-utils'; +import { errorCreator, pipe } from '../../../../../capture-core-utils'; import { type LinkedRequestEvent } from '../validated.types'; +import { convertClientToServer, convertFormToClient } from '../../../../converters'; +import { dataElementTypes } from '../../../../metaData'; + +const convertFn = pipe(convertFormToClient, convertClientToServer); const getEventDetailsByLinkMode = ({ relatedStageDataValues, @@ -47,8 +51,8 @@ const getEventDetailsByLinkMode = ({ return ({ linkedEvent: { ...baseEventDetails, - scheduledAt: linkedEventScheduledAt, - orgUnit: linkedEventOrgUnit.id, + scheduledAt: convertFn(linkedEventScheduledAt, dataElementTypes.DATE), + orgUnit: convertFn(linkedEventOrgUnit, dataElementTypes.ORGANISATION_UNIT), }, linkedEventId: baseEventDetails.event, }); @@ -56,8 +60,8 @@ const getEventDetailsByLinkMode = ({ return ({ linkedEvent: { ...baseEventDetails, - scheduledAt: clientRequestEvent.occurredAt, - orgUnit: clientRequestEvent.orgUnit, + scheduledAt: convertFn(clientRequestEvent.scheduledAt, dataElementTypes.DATE), + orgUnit: convertFn(clientRequestEvent.orgUnit, dataElementTypes.ORGANISATION_UNIT), }, linkedEventId: baseEventDetails.event, }); diff --git a/src/core_modules/capture-core/utils/converters/date/stringToMomentDateFormat.js b/src/core_modules/capture-core/utils/converters/date/stringToMomentDateFormat.js index 54ca885689..eed1df7957 100644 --- a/src/core_modules/capture-core/utils/converters/date/stringToMomentDateFormat.js +++ b/src/core_modules/capture-core/utils/converters/date/stringToMomentDateFormat.js @@ -11,6 +11,6 @@ import { systemSettingsStore } from '../../../metaDataMemoryStores'; export function convertStringToDateFormat(date: string) { if (!date || !date.length) { return ''; } const dateFormat = systemSettingsStore.get().dateFormat; - const formattedDateString = moment(date, dateFormat).format('YYYY-MM-DD'); + const formattedDateString = moment(date, dateFormat).format(dateFormat); return formattedDateString; }