UNPKG

loop-modules

Version:

Shared modules for the Loop product suite.

36 lines (30 loc) 1.06 kB
// angular import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; // libs import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { Observable } from 'rxjs/Observable'; import { Store } from '@ngrx/store'; // app import { APIDispatcher } from '../utils/index'; import { SubordinatesAction } from '../actions/employee.action'; import { LoopUser } from '../interfaces/loop-user.interface'; @Injectable() export class EmployeeService extends APIDispatcher { constructor(public http: Http, public store: Store<any>) { super(http, store); } subordinates() { return Observable.create((observer: any) => { this.http.get('ma_loop/api/v1/assignments/employees') .catch(this.handleError) .map(res => (<Response>res).json()) .subscribe((users: LoopUser[]) => { this.store.dispatch(new SubordinatesAction(users)); observer.next(users); observer.complete(); }); }); } }