Fix constraining logic of stored client metadata
By the time the constraining function was called, the stored values were still of type string and were not converted to the correct type yet.
This commit is contained in:
@@ -13,28 +13,8 @@ import { APP_METADATA } from '@/modules/metadata/Metadata.constants.ts';
|
||||
export const convertValueFromMetadata = <T extends AllowedMetadataValueTypes = AllowedMetadataValueTypes>(
|
||||
key: string,
|
||||
value: string,
|
||||
): T => {
|
||||
const typeOfKey = APP_METADATA[key as AppMetadataKeys].type;
|
||||
const isAutoType = typeOfKey === 'auto';
|
||||
|
||||
if ((isAutoType && !Number.isNaN(+value)) || typeOfKey === 'number') {
|
||||
return +value as T;
|
||||
}
|
||||
|
||||
if ((isAutoType && (value === 'true' || value === 'false')) || typeOfKey === 'boolean') {
|
||||
return (value === 'true') as T;
|
||||
}
|
||||
|
||||
if (isAutoType && value === 'undefined') {
|
||||
return undefined as T;
|
||||
}
|
||||
|
||||
if (isAutoType && value === 'null') {
|
||||
return null as T;
|
||||
}
|
||||
|
||||
return value as T;
|
||||
};
|
||||
defaultValue: any,
|
||||
): T => APP_METADATA[key as AppMetadataKeys].convert(value, defaultValue);
|
||||
|
||||
export const convertFromGqlMeta = (
|
||||
gqlMetadata?: MetaType[],
|
||||
|
||||
Reference in New Issue
Block a user