17 lines
845 B
TypeScript
17 lines
845 B
TypeScript
import { inject, Injectable } from '@angular/core';
|
|
import { toSignal } from '@angular/core/rxjs-interop';
|
|
import { catchError, defer, map, of } from 'rxjs';
|
|
import { PacienteRiesgoEstado } from './paciente-riesgo.models';
|
|
import { PACIENTE_RIESGO_PROVIDER } from './paciente-riesgo.provider';
|
|
import { riesgoPacienteResponse } from './paciente-riesgo.validation';
|
|
|
|
@Injectable()
|
|
export class PacienteRiesgoState {
|
|
private readonly provider = inject(PACIENTE_RIESGO_PROVIDER);
|
|
readonly estado = toSignal(defer(() => this.provider.obtener()).pipe(
|
|
map((datos): PacienteRiesgoEstado => datos === null ? { tipo: 'no-disponible' }
|
|
: { tipo: 'disponible', datos: riesgoPacienteResponse(datos) }),
|
|
catchError(() => of<PacienteRiesgoEstado>({ tipo: 'error' })),
|
|
), { initialValue: { tipo: 'cargando' } as PacienteRiesgoEstado });
|
|
}
|