import { EntitySchemaDatatype } from "../../entity/schema/entity-schema-datatype" ; import { CONFIGURABLE_ENUM_CONFIG_PREFIX , ConfigurableEnumConfig , ConfigurableEnumValue , } from "../configurable-enum.interface" ; import { ConfigService } from "../../config/config.service" ; import { EntitySchemaField } from "../../entity/schema/entity-schema-field" ; export class ConfigurableEnumDatatype implements EntitySchemaDatatype < ConfigurableEnumValue > { public readonly name = "configurable-enum" ; public readonly viewComponent = "DisplayConfigurableEnum" ; public readonly editComponent = "EditConfigurableEnum" ; constructor ( private configService ) { } param value public transformToDatabaseFormat ( value ) { return value . id ; } param value param schemaField public transformToObjectFormat ( value , schemaField ) { let enumId = schemaField . innerDataType ; if ( ! enumId . startsWith ( CONFIGURABLE_ENUM_CONFIG_PREFIX ) ) { enumId = CONFIGURABLE_ENUM_CONFIG_PREFIX + enumId ; } return this . configService . getConfig < ConfigurableEnumConfig > ( enumId ) ?. find ( ( option ) => option . id === value ) ; } }