import { Injectable } from '@angular/core'; import * as global from '../../core/common'; import { Http, RequestOptions, URLSearchParams, Response } from '@angular/http'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/throw'; import { Observable, throwError } from 'rxjs' @Injectable({ providedIn: 'root' }) export class OrdersService { private GetOrders = global.serverBase + '/api/Orders/GetOrders'; private CopyOrders = global.serverBase + '/api/Orders/CopyOrder'; private DeleteOrderById = global.serverBase + '/api/Orders/DeleteOrder'; private GetAllCustomers = global.serverBase + '/api/Common/GetCustomers'; private GetAllCustomerGroups = global.serverBase + '/api/Common/GetCustomerGroups'; constructor(private http: Http) { } // Get orders GetAllOrders(companyId: number, actionType: string = "All") { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetOrders, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Copy order CopyOrder(id: number, companyId: number, actionType: string = "COPY") { const myparams = new URLSearchParams(); myparams.append('id', id.toString()); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.CopyOrders, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Delete order DeleteOrder(id: number, companyId: number, actionType: string = "DELETE") { const myparams = new URLSearchParams(); myparams.append('id', id.toString()); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.delete(this.DeleteOrderById, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Get customer groups GetCustomers(companyId: number, actionType: string = "All") { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetAllCustomers, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Get customer groups GetCustomerGroups(companyId: number, actionType: string = "All") { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); const options = myparams.toString(); return this.http.get(this.GetAllCustomerGroups, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } private handleError(error): Observable { const message = error.statusText || 'Server error'; return throwError(error); } }