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 QuantityDiscountService { private GetQuantityDiscount = global.serverBase + '/api/QuantityDiscount/GetQuantityDiscount'; private CopyQuantityDisc = global.serverBase + '/api/QuantityDiscount/CopyQuantityDiscount'; private SetUsageLimits = global.serverBase + '/api/QuantityDiscount/CreateQuantityDiscountUsageLimits'; private CreateCategoriesOfQuantity = global.serverBase + '/api/QuantityDiscount/CreateCategoriesOfQuantityDiscount'; private SetQuantityDiscount = global.serverBase + '/api/QuantityDiscount/CreateQuantityDiscount'; private DeleteQuantityDiscountById = global.serverBase + '/api/QuantityDiscount/DeleteQuantiyDiscount'; private SetShippingDetails = global.serverBase + '/api/QuantityDiscount/CreateShippingDetails'; constructor(private http: Http) { } // Get all quantity discounts GetAllQuantityDiscounts(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.GetQuantityDiscount, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Copy quantity discounts CopyQuantityDiscount(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.CopyQuantityDisc, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Save usage limits SaveUsageLimits(usageLimits, companyId: number, actionType: string = "SET") { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); let options = new RequestOptions({ params: myparams }); return this.http.post(this.SetUsageLimits, usageLimits, options) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Create categories of quantity discount CreateCategoriesOfQuantityDiscount(categoryOfQuantity, companyId: number, actionType: string = "SET") { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType.toString()); let options = new RequestOptions({ params: myparams }); return this.http.post(this.CreateCategoriesOfQuantity, categoryOfQuantity, options) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Save quantity discount SaveQuantityDiscount(quantity, companyId: number, actionType: string) { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); let options = new RequestOptions({ params: myparams }); return this.http.post(this.SetQuantityDiscount, quantity, options ) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Delete quantity discounts DeleteQuantityDiscount(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.DeleteQuantityDiscountById, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Save shipping details SaveShippingDetails(shipping, companyId: number, actionType: string) { const myparams = new URLSearchParams(); myparams.append('companyId', companyId.toString()); myparams.append('actionType', actionType); let options = new RequestOptions({ params: myparams }); return this.http.post(this.SetShippingDetails, shipping, 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); } }