accountant-ui/src/accounts/account.service.ts
Alexis Lahouze 5100d0fd0c Cleanup.
2017-07-20 22:53:22 +02:00

43 lines
907 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 { Account } from './account';
@Injectable()
export class AccountService {
constructor(
private restangular: Restangular
) {}
private all() {
return this.restangular.all('account');
}
private one(id: number) {
return this.restangular.one('account', id);
}
query(): Observable<Account[]> {
return this.all().getList();
}
get(id: number): Observable<Account> {
return this.one(id).get();
}
create(account: Account): Observable<Account> {
return this.all().post(account);
}
update(account: Account): Observable<Account> {
return this.one(account.id).post(null, account);
}
delete(account: Account): Observable<Account> {
return this.one(account.id).delete();
}
}