Closes #4295 Note: for the sake of an easier code review, I did not rename/move some files and added "todo" comments instead so Github is able to match those files with their previous version.
23 lines
932 B
TypeScript
23 lines
932 B
TypeScript
import { CurrencyCode } from '@/object-record/record-field/types/CurrencyCode';
|
|
import { FieldCurrencyValue } from '@/object-record/record-field/types/FieldMetadata';
|
|
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
|
|
export const getDefaultValueForBackend = (
|
|
defaultValue: any,
|
|
fieldMetadataType: FieldMetadataType,
|
|
) => {
|
|
if (fieldMetadataType === FieldMetadataType.Currency) {
|
|
const currencyDefaultValue = defaultValue as FieldCurrencyValue;
|
|
return {
|
|
amountMicros: currencyDefaultValue.amountMicros,
|
|
currencyCode: `'${currencyDefaultValue.currencyCode}'` as CurrencyCode,
|
|
} satisfies FieldCurrencyValue;
|
|
} else if (fieldMetadataType === FieldMetadataType.Select) {
|
|
return defaultValue ? `'${defaultValue}'` : null;
|
|
} else if (fieldMetadataType === FieldMetadataType.MultiSelect) {
|
|
return defaultValue.map((value: string) => `'${value}'`);
|
|
}
|
|
|
|
return defaultValue;
|
|
};
|