Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Macadoshis/3fe3c6260e4bc9640fd1a6d784052bbf to your computer and use it in GitHub Desktop.
Save Macadoshis/3fe3c6260e4bc9640fd1a6d784052bbf to your computer and use it in GitHub Desktop.
pour lucas
@Injectable()
export class ServiceFolderRouteResolver implements Resolve<IServiceFolder> {
constructor(private serviceFolderController: ServiceFolderController,
private serviceFolderService: ServiceFolderService,
@Inject(CURRENT_SERVICE_FOLDER) private currentServiceFolder: CurrentServiceFolder) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<IServiceFolder> {
const idServiceFolder = getIdServiceFolder(route);
return this.serviceFolderController.getServiceFolder(idServiceFolder)
.do(() => this.currentServiceFolder.currentServiceFolderId = idServiceFolder)
.catch(() => this.currentServiceFolder.currentServiceFolderId = null)
.map((item: IResponseItem<IServiceFolder>) => {
if (!item || !item.Item) {
// TODO : to be properly managed with a '404' status server-side
throw new Error('Service folder doesn\'t exist');
}
return item.Item;
}).mergeMap((serviceFolder: IServiceFolder) => {
if (serviceFolder.ChangeRequest) {
return this.serviceFolderController.getServiceFoldersCount('')
.do((result: IResponseItem<number>) => route.data['serviceFoldersList'] = result)
.map((result) => {
return serviceFolder;
});
} else {
return Observable.of(serviceFolder);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment