From c25706964489f502dd67dcb14a955183bb931179 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 22 Jul 2017 11:11:39 +0200 Subject: [PATCH] Add schedule service. --- src/scheduler/schedule.service.ts | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/scheduler/schedule.service.ts diff --git a/src/scheduler/schedule.service.ts b/src/scheduler/schedule.service.ts new file mode 100644 index 0000000..fb0d8f1 --- /dev/null +++ b/src/scheduler/schedule.service.ts @@ -0,0 +1,49 @@ +// vim: set tw=80 ts=2 sw=2 sts=2 : + +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Rx'; + +import { Restangular } from "ngx-restangular"; + +import { Schedule } from './schedule'; + +@Injectable() +export class ScheduleService { + constructor( + private restangular: Restangular + ) {} + + private all() { + //return this.accountService.one(accountId).all('scheduled_operation'); + return this.restangular.all('scheduled_operation'); + } + + private one(id: number) { + //return this.accountService.one(accountId).one('scheduled_operation', id); + return this.restangular.one('scheduled_operation', id); + } + + query(accountId: number): Observable { + return this.all().getList({ + account_id: accountId + }); + } + + get(accountId: number, id: number): Observable { + return this.one(id).get({ + account_id: accountId + }); + } + + create(schedule: Schedule): Observable { + return this.all().post(schedule); + } + + update(schedule: Schedule): Observable { + return this.one(schedule.id).post(null, schedule); + } + + delete(schedule: Schedule): Observable { + return this.one(schedule.id).delete(); + } +}