Add schedule service.

This commit is contained in:
Alexis Lahouze 2017-07-22 11:11:39 +02:00
parent c5f3a53347
commit c257069644

View File

@ -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<Schedule[]> {
return this.all().getList({
account_id: accountId
});
}
get(accountId: number, id: number): Observable<Schedule> {
return this.one(id).get({
account_id: accountId
});
}
create(schedule: Schedule): Observable<Schedule> {
return this.all().post(schedule);
}
update(schedule: Schedule): Observable<Schedule> {
return this.one(schedule.id).post(null, schedule);
}
delete(schedule: Schedule): Observable<Schedule> {
return this.one(schedule.id).delete();
}
}