feat: extract mapping to util function

This commit is contained in:
Flo 2026-11-01 11:25:01 +01:00
parent 7e7324156e
commit 6c47d98666

View File

@ -11,13 +11,15 @@ export interface Disease {
type DiseaseResponse = Record<string, Disease[]>;
const flattenResult = (rawItems: DiseaseResponse): Disease[] => Object.values(rawItems).flat();
@Service()
export class DiseaseService {
private url = environment.resourceUrl;
private readonly resource = httpResource<DiseaseResponse>(() => this.url);
readonly diseases = computed(() =>
this.resource.hasValue() ? Object.values(this.resource.value()).flat() : [],
this.resource.hasValue() ? flattenResult(this.resource.value()) : [],
);
readonly isLoading = this.resource.isLoading;