| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import type { VueI18n } from 'vue-i18n'
- import type ApiRequestService from './apiRequestService'
- import UrlUtils from '~/services/utils/urlUtils'
- import HydraNormalizer from '~/services/data/normalizer/hydraNormalizer'
- import type { AnyJson, Enum, EnumApiResponse } from '~/types/data.d'
- class EnumManager {
- private apiRequestService: ApiRequestService
- private i18n: VueI18n
- public constructor(apiRequestService: ApiRequestService, i18n: VueI18n) {
- this.apiRequestService = apiRequestService
- this.i18n = i18n
- }
- public async fetch(enumName: string): Promise<Enum> {
- const url = UrlUtils.join('api', 'enum', enumName)
- const response = await this.apiRequestService.get(url)
- const { data } = HydraNormalizer.denormalize(
- response as unknown as AnyJson,
- ) as {
- data: EnumApiResponse
- }
- const enum_: Enum = []
- for (const key in data.items) {
- if (Object.prototype.hasOwnProperty.call(data.items, key)) {
- enum_.push({
- value: data.items[key],
- label: this.i18n.t(data.items[key]),
- })
- }
- }
- return enum_
- }
- }
- export default EnumManager
|