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:
schroda
2025-06-25 00:38:01 +02:00
parent 56f01efc1e
commit cb74984659
8 changed files with 146 additions and 249 deletions

View File

@@ -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[],