datasurvey/src/main/webapp/app/entities/e-pregunta-cerrada/route/e-pregunta-cerrada-routing-...

31 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-07-03 21:48:27 +00:00
import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, Router } from '@angular/router';
import { Observable, of, EMPTY } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { IEPreguntaCerrada, EPreguntaCerrada } from '../e-pregunta-cerrada.model';
import { EPreguntaCerradaService } from '../service/e-pregunta-cerrada.service';
@Injectable({ providedIn: 'root' })
export class EPreguntaCerradaRoutingResolveService implements Resolve<IEPreguntaCerrada> {
constructor(protected service: EPreguntaCerradaService, protected router: Router) {}
resolve(route: ActivatedRouteSnapshot): Observable<IEPreguntaCerrada> | Observable<never> {
const id = route.params['id'];
if (id) {
return this.service.find(id).pipe(
mergeMap((ePreguntaCerrada: HttpResponse<EPreguntaCerrada>) => {
if (ePreguntaCerrada.body) {
return of(ePreguntaCerrada.body);
} else {
this.router.navigate(['404']);
return EMPTY;
}
})
);
}
return of(new EPreguntaCerrada());
}
}