// vim: set tw=80 ts=2 sw=2 sts=2 : import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Rx'; import { Schedule } from './schedule'; @Injectable() export class ScheduleService { constructor( private http: HttpClient ) {} private url(id?: number): string { if(id) { return `/api/scheduled_operation/${id}`; } return `/api/scheduled_operation`; } query(accountId: number): Observable { let params = new HttpParams().set('account_id', `${accountId}`); return this.http.get(this.url(), { params: params }); } get(accountId: number, id: number): Observable { let params = new HttpParams().set('account_id', `${accountId}`); return this.http.get(this.url(id), { params: params }); } create(schedule: Schedule): Observable { return this.http.post(this.url(), schedule); } update(schedule: Schedule): Observable { return this.http.post(this.url(schedule.id), schedule); } delete(schedule: Schedule): Observable { return this.http.delete(this.url(schedule.id)); } }