From c1aa379f49113a1fef6837e11ff06437b7c06fd2 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Mon, 17 Feb 2020 12:36:42 +0530 Subject: [PATCH] Place order service connected --- src/app/app.module.ts | 2 ++ src/app/cart/cart.page.ts | 12 ++++++++++-- src/app/services/order.service.spec.ts | 12 ++++++++++++ src/app/services/order.service.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/app/services/order.service.spec.ts create mode 100644 src/app/services/order.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e301fc2..0ac5a31 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,7 @@ import { HttpClientModule } from '@angular/common/http'; // Services import import { MallService } from './services/mall.service'; +import { OrderService } from './services/order.service'; import { ToastService } from './services/toast.service'; import { AppComponent } from './app.component'; @@ -36,6 +37,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx'; MallService, Geolocation, ToastService, + OrderService, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } ], bootstrap: [AppComponent] diff --git a/src/app/cart/cart.page.ts b/src/app/cart/cart.page.ts index cf7c73d..154fe7f 100644 --- a/src/app/cart/cart.page.ts +++ b/src/app/cart/cart.page.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Location } from '@angular/common'; import { MallService } from '../services/mall.service'; import { Router } from '@angular/router'; -import { ToastController } from '@ionic/angular'; +import { OrderService } from '../services/order.service'; import * as moment from 'moment'; export type ICart = { @@ -40,7 +40,7 @@ export class CartPage implements OnInit { constructor( private location: Location, private router: Router, - public toastController: ToastController, + private orderService: OrderService, private mallService: MallService ) { } @@ -236,4 +236,12 @@ export class CartPage implements OnInit { return total; } + placeOrder() { + this.orderService.createOrder(this.userCart).then((resp) => { + console.log(resp); + }, (err) => { + console.log(err); + }) + } + } diff --git a/src/app/services/order.service.spec.ts b/src/app/services/order.service.spec.ts new file mode 100644 index 0000000..4a83470 --- /dev/null +++ b/src/app/services/order.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { OrderService } from './order.service'; + +describe('OrderService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: OrderService = TestBed.get(OrderService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/order.service.ts b/src/app/services/order.service.ts new file mode 100644 index 0000000..4bd2ec9 --- /dev/null +++ b/src/app/services/order.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { TOKEN, URL } from '../mocks/url'; + +@Injectable({ + providedIn: 'root' +}) +export class OrderService { + + constructor( + private http: HttpClient + ) { } + + async createOrder(userCart) { + console.log(userCart); + const httpOptions = { + headers: new HttpHeaders({ + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json', + 'Authorization': 'Token ' + TOKEN + }) + }; + + return await this.http.post(URL + '/api/maioraservice/orders/v1/create/', userCart, httpOptions).toPromise(); + } +}