Files
psp_api/src/modules/enums/enums.service.ts
T

114 lines
3.9 KiB
TypeScript
Raw Normal View History

import translates from '@/common/constants/translates/translates'
import { translateEnumValue } from '@/common/utils/enum-translator.util'
import {
AccountRole,
AccountStatus,
AccountType,
ApplicationPlatform,
ApplicationPublisher,
ApplicationReleaseType,
BusinessRole,
ComplexRole,
ConsumerRole,
ConsumerStatus,
ConsumerType,
CustomerType,
GoodPricingModel,
LicenseStatus,
LicenseType,
PartnerRole,
PartnerStatus,
PaymentMethodType,
POSRole,
POSStatus,
POSType,
ProviderRole,
ProviderStatus,
SKUGuildType,
TokenType,
TspProviderCustomerType,
TspProviderRequestType,
TspProviderResponseStatus,
TspProviderType,
UnitType,
UserStatus,
UserType,
} from '@/generated/prisma/enums'
import { Injectable } from '@nestjs/common'
import { GoldKarat } from 'common/enums/enums'
import { ResponseMapper } from 'common/response/response-mapper'
@Injectable()
export class EnumsService {
private prepareData(
items: Record<string, string>,
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'),
UserStatus: this.prepareData(UserStatus, 'UserStatus'),
AccountRole: this.prepareData(AccountRole, 'AccountRole'),
AccountStatus: this.prepareData(AccountStatus, 'AccountStatus'),
POSStatus: this.prepareData(POSStatus, 'POSStatus'),
POSRole: this.prepareData(POSRole, 'POSRole'),
LicenseType: this.prepareData(LicenseType, 'LicenseType'),
LicenseStatus: this.prepareData(LicenseStatus, 'LicenseStatus'),
POSType: this.prepareData(POSType, 'POSType'),
UserType: this.prepareData(UserType, 'UserType'),
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'),
ProviderStatus: this.prepareData(ProviderStatus, 'ProviderStatus'),
TokenType: this.prepareData(TokenType, 'TokenType'),
UnitType: this.prepareData(UnitType, 'UnitType'),
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'),
}
}
getEnumValues(enumName: string) {
const enums = this.getAllEnums()
return ResponseMapper.list(enums[enumName] || [])
}
}