Migrate to HttpClient in Schedule module.

This commit is contained in:
Alexis Lahouze 2017-07-31 13:15:45 +02:00
parent d71656412a
commit dc30f38662
2 changed files with 19 additions and 23 deletions

View File

@ -3,9 +3,8 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { RestangularModule } from 'ngx-restangular';
import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ToastrModule } from 'ngx-toastr';
@ -24,11 +23,10 @@ export function accountIdServiceFactory(i: any) {
@NgModule({
imports: [
HttpModule,
HttpClientModule,
CommonModule,
FormsModule,
NgLoggerModule,
RestangularModule,
ToastrModule,
NgbModule,
TextMaskModule

View File

@ -1,49 +1,47 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Restangular } from "ngx-restangular";
import { Observable } from 'rxjs/Rx';
import { Schedule } from './schedule';
@Injectable()
export class ScheduleService {
constructor(
private restangular: Restangular
private http: HttpClient
) {}
private all() {
//return this.accountService.one(accountId).all('scheduled_operation');
return this.restangular.all('scheduled_operation');
private url(id?: number): string {
if(id) {
return `/api/scheduled_operation/${id}`;
}
private one(id: number) {
//return this.accountService.one(accountId).one('scheduled_operation', id);
return this.restangular.one('scheduled_operation', id);
return `/api/scheduled_operation`;
}
query(accountId: number): Observable<Schedule[]> {
return this.all().getList({
account_id: accountId
});
let params = new HttpParams().set('account_id', `${accountId}`);
return this.http.get<Schedule[]>(this.url(), { params: params });
}
get(accountId: number, id: number): Observable<Schedule> {
return this.one(id).get({
account_id: accountId
});
let params = new HttpParams().set('account_id', `${accountId}`);
return this.http.get<Schedule>(this.url(id), { params: params });
}
create(schedule: Schedule): Observable<Schedule> {
return this.all().post(schedule);
return this.http.post<Schedule>(this.url(), schedule);
}
update(schedule: Schedule): Observable<Schedule> {
return this.one(schedule.id).post(null, schedule);
return this.http.post<Schedule>(this.url(schedule.id), schedule);
}
delete(schedule: Schedule): Observable<Schedule> {
return this.one(schedule.id).remove();
return this.http.delete<Schedule>(this.url(schedule.id));
}
}