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 BulkDiscountService { private GetBulkDiscounts = global.serverBase + '/api/BulkDiscount/GetBulkDiscount'; private CopyBulkDiscountById = global.serverBase + '/api/BulkDiscount/CopyBulkDiscount'; private DeleteBulkDiscountById = global.serverBase + '/api/BulkDiscount/DeleteBulkDiscount'; private CreateCategoriesOfBulk = global.serverBase + '/api/BulkDiscount/CreateCategoriesOfBulkDiscount'; private SetUsageLimits = global.serverBase + '/api/BulkDiscount/CreateBulkDiscountUsageLimits'; private SetBulkDiscount = global.serverBase + '/api/BulkDiscount/CreateBulkDiscount'; private SetShippingDetails = global.serverBase + '/api/BulkDiscount/CreateShippingDetails'; constructor(private http: Http) { } // Get all bulk discounts GetAllBulkDiscounts(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.GetBulkDiscounts, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Copy bulk discounts CopyBulkDiscount(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.CopyBulkDiscountById, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Delete bulk discounts DeleteBulkDiscount(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.DeleteBulkDiscountById, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Create categories of bulk discount CreateCategoriesOfBulkDiscount(categoryOfBulk, 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.CreateCategoriesOfBulk, categoryOfBulk, 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); } // Save bulk discount SaveBulkDiscount(bulk, 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.SetBulkDiscount, bulk, 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); } }