Files
psp_api/src/common/utils/enum-translator.util.ts
T

30 lines
665 B
TypeScript
Raw Normal View History

import translates from '@/common/constants/translates/translates'
type EnumTranslateMap = Record<string, string>
type EnumsRegistry = Record<string, EnumTranslateMap>
export interface EnumTranslatedValue {
value: string | null | undefined
translate: string | null
}
export function translateEnumValue(
enumKey: keyof typeof translates.enums,
value: string | null | undefined,
): EnumTranslatedValue {
const enumsRegistry = translates.enums as EnumsRegistry
const enumMap = enumsRegistry[String(enumKey)]
if (!value) {
return {
value,
translate: null,
}
}
return {
value,
translate: enumMap?.[value] ?? null,
}
}