Fixed plain object in field value for workflow (#17470)
This PR fixes a bug that arises in `formatResult` following up the recent refactor for DATE_TIME : https://github.com/twentyhq/twenty/pull/17407 In the case of workflows, we pass a plain object to `formatResult` : ```ts { before: null, after: '2026-01-27T10:59:15.525Z' } ``` So a case has been added to handle this. @Weiko are we ok with this more restrictive else-if part in this util ? We could also just put a `continue` for unknown shapes.
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
FieldMetadataType,
|
||||
compositeTypeDefinitions,
|
||||
} from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { isDefined, stringifySafely } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
DEFAULT_ARRAY_FIELD_NULL_EQUIVALENT_VALUE,
|
||||
@@ -194,7 +194,8 @@ export function formatResult<T>(
|
||||
| string
|
||||
| Date
|
||||
| null
|
||||
| undefined;
|
||||
| undefined
|
||||
| Record<string, unknown>;
|
||||
|
||||
if (!isDefined(rawUpdatedDateTime)) {
|
||||
continue;
|
||||
@@ -208,9 +209,16 @@ export function formatResult<T>(
|
||||
|
||||
// @ts-expect-error legacy noImplicitAny
|
||||
newData[dateTimeField.name] = dateIsoString;
|
||||
} else if (isPlainObject(rawUpdatedDateTime)) {
|
||||
const plainObjectValue = rawUpdatedDateTime;
|
||||
|
||||
// @ts-expect-error legacy noImplicitAny
|
||||
newData[dateTimeField.name] = plainObjectValue;
|
||||
} else {
|
||||
const stringifiedUnknownValue = stringifySafely(rawUpdatedDateTime);
|
||||
|
||||
throw new Error(
|
||||
`Invalid DATE_TIME field "${dateTimeField.name}", value: "${rawUpdatedDateTime}", it should be a string or Date instance, (current type : ${typeof rawUpdatedDateTime}).`,
|
||||
`Invalid DATE_TIME field "${dateTimeField.name}", value: "${stringifiedUnknownValue}", it should be a string, Date instance or plain object, (current type : ${typeof rawUpdatedDateTime}).`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user