Add Operation Service.
This commit is contained in:
parent
1d35438444
commit
595fe60fc4
@ -10,7 +10,8 @@ import { RestangularModule } from 'ngx-restangular';
|
||||
|
||||
import { BalanceChartComponent } from './balanceChart.component';
|
||||
import { CategoryChartComponent } from './categoryChart.component';
|
||||
import { CategoryService } from './category.service'
|
||||
import { CategoryService } from './category.service';
|
||||
import { OperationService } from './operation.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@ -22,6 +23,7 @@ import { CategoryService } from './category.service'
|
||||
],
|
||||
providers: [
|
||||
CategoryService,
|
||||
OperationService,
|
||||
],
|
||||
declarations: [
|
||||
BalanceChartComponent,
|
||||
|
43
src/operations/operation.service.ts
Normal file
43
src/operations/operation.service.ts
Normal file
@ -0,0 +1,43 @@
|
||||
// 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();
|
||||
}
|
||||
}
|
9
src/operations/operation.ts
Normal file
9
src/operations/operation.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// vim: set tw=80 ts=2 sw=2 sts=2:
|
||||
|
||||
export class Operation {
|
||||
id: number;
|
||||
operation_date: string;
|
||||
label: string;
|
||||
value: number;
|
||||
category: string;
|
||||
}
|
Loading…
Reference in New Issue
Block a user