44 lines
948 B
TypeScript
44 lines
948 B
TypeScript
|
// 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 { Operation } from './operation';
|
||
|
|
||
|
@Injectable()
|
||
|
export class OperationService {
|
||
|
constructor(
|
||
|
private restangular: Restangular
|
||
|
) {}
|
||
|
|
||
|
private all() {
|
||
|
return this.restangular.all('operation');
|
||
|
}
|
||
|
|
||
|
private one(id: number) {
|
||
|
return this.restangular.one('operation', id);
|
||
|
}
|
||
|
|
||
|
query(): Observable<Operation[]> {
|
||
|
return this.all().getList();
|
||
|
}
|
||
|
|
||
|
get(id: number): Observable<Operation> {
|
||
|
return this.one(id).get();
|
||
|
}
|
||
|
|
||
|
create(operation: Operation): Observable<Operation> {
|
||
|
return this.all().post(operation);
|
||
|
}
|
||
|
|
||
|
update(operation: Operation): Observable<Operation> {
|
||
|
return this.one(operation.id).post(null, operation);
|
||
|
}
|
||
|
|
||
|
delete(operation: Operation): Observable<Operation> {
|
||
|
return this.one(operation.id).delete();
|
||
|
}
|
||
|
}
|