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

60 lines
1.7 KiB
TypeScript

import translates from '@/common/constants/translates/translates'
import {
AccountRole,
AccountStatus,
BusinessRole,
ConsumerRole,
GoodPricingModel,
LicenseStatus,
LicenseType,
PartnerRole,
POSRole,
POSStatus,
POSType,
ProviderRole,
UnitType,
UserStatus,
UserType,
} from '@/generated/prisma/enums'
import { Injectable } from '@nestjs/common'
import { AccountType, GoldKarat, TokenType } from 'common/enums/enums'
import { ResponseMapper } from 'common/response/response-mapper'
@Injectable()
export class EnumsService {
private prepareData(items: Record<string, string>) {
return Object.values(items).map(item => ({
name: translates.enums[item] || item,
value: item,
}))
}
getAllEnums() {
return {
GoldKarat: this.prepareData(GoldKarat),
UserStatus: this.prepareData(UserStatus),
AccountRole: this.prepareData(AccountRole),
AccountStatus: this.prepareData(AccountStatus),
POSStatus: this.prepareData(POSStatus),
POSRole: this.prepareData(POSRole),
LicenseType: this.prepareData(LicenseType),
LicenseStatus: this.prepareData(LicenseStatus),
POSType: this.prepareData(POSType),
UserType: this.prepareData(UserType),
AccountType: this.prepareData(AccountType),
PartnerRole: this.prepareData(PartnerRole),
BusinessRole: this.prepareData(BusinessRole),
ProviderRole: this.prepareData(ProviderRole),
TokenType: this.prepareData(TokenType),
UnitType: this.prepareData(UnitType),
GoodPricingModel: this.prepareData(GoodPricingModel),
ConsumerRole: this.prepareData(ConsumerRole),
}
}
getEnumValues(enumName: string) {
const enums = this.getAllEnums()
return ResponseMapper.list(enums[enumName] || [])
}
}