import translates from '@/common/constants/translates/translates' import { translateEnumValue } from '@/common/utils/enum-translator.util' import { AccountStatus, AccountType, ApplicationPlatform, ApplicationPublisher, ApplicationReleaseType, BusinessRole, ComplexRole, ConsumerRole, ConsumerStatus, ConsumerType, CustomerType, GoodPricingModel, InvoiceTemplateType, PartnerRole, PartnerStatus, PaymentMethodType, POSRole, POSStatus, POSType, ProviderRole, SKUGuildType, TspProviderRequestType, TspProviderResponseStatus, TspProviderType, } from '@/generated/prisma/enums' import { Injectable } from '@nestjs/common' import { GoldKarat, TspProviderCustomerType } from 'common/enums/enums' import { ResponseMapper } from 'common/response/response-mapper' @Injectable() export class EnumsService { private prepareData( items: Record, enumName: keyof typeof translates.enums, ) { return Object.values(items).map(item => { const translated = translateEnumValue(enumName, item) return { name: translated.translate || item, value: translated.value, } }) } getAllEnums() { return { PaymentMethodType: this.prepareData(PaymentMethodType, 'PaymentMethodType'), GoldKarat: this.prepareData(GoldKarat, 'GoldKarat'), AccountStatus: this.prepareData(AccountStatus, 'AccountStatus'), POSStatus: this.prepareData(POSStatus, 'POSStatus'), POSRole: this.prepareData(POSRole, 'POSRole'), POSType: this.prepareData(POSType, 'POSType'), AccountType: this.prepareData(AccountType, 'AccountType'), PartnerRole: this.prepareData(PartnerRole, 'PartnerRole'), BusinessRole: this.prepareData(BusinessRole, 'BusinessRole'), ComplexRole: this.prepareData(ComplexRole, 'ComplexRole'), ProviderRole: this.prepareData(ProviderRole, 'ProviderRole'), GoodPricingModel: this.prepareData(GoodPricingModel, 'GoodPricingModel'), ConsumerRole: this.prepareData(ConsumerRole, 'ConsumerRole'), ConsumerStatus: this.prepareData(ConsumerStatus, 'ConsumerStatus'), ConsumerType: this.prepareData(ConsumerType, 'ConsumerType'), PartnerStatus: this.prepareData(PartnerStatus, 'PartnerStatus'), TspProviderType: this.prepareData(TspProviderType, 'TspProviderType'), ApplicationPlatform: this.prepareData(ApplicationPlatform, 'ApplicationPlatform'), ApplicationReleaseType: this.prepareData( ApplicationReleaseType, 'ApplicationReleaseType', ), ApplicationPublisher: this.prepareData( ApplicationPublisher, 'ApplicationPublisher', ), CustomerType: this.prepareData(CustomerType, 'CustomerType'), TspProviderResponseStatus: this.prepareData( TspProviderResponseStatus, 'TspProviderResponseStatus', ), TspProviderRequestType: this.prepareData( TspProviderRequestType, 'TspProviderRequestType', ), TspProviderCustomerType: this.prepareData( TspProviderCustomerType, 'TspProviderCustomerType', ), SKUGuildType: this.prepareData(SKUGuildType, 'SKUGuildType'), InvoiceTemplateType: this.prepareData(InvoiceTemplateType, 'InvoiceTemplateType'), } } getEnumValues(enumName: keyof typeof translates.enums) { const enums = this.getAllEnums() return ResponseMapper.list(enums[enumName] || []) } }