| @@ -10,6 +10,7 @@ import { HttpClientModule } from '@angular/common/http'; | |||||
| // Services import | // Services import | ||||
| import { MallService } from './services/mall.service'; | import { MallService } from './services/mall.service'; | ||||
| import { OrderService } from './services/order.service'; | |||||
| import { ToastService } from './services/toast.service'; | import { ToastService } from './services/toast.service'; | ||||
| import { AppComponent } from './app.component'; | import { AppComponent } from './app.component'; | ||||
| @@ -36,6 +37,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx'; | |||||
| MallService, | MallService, | ||||
| Geolocation, | Geolocation, | ||||
| ToastService, | ToastService, | ||||
| OrderService, | |||||
| { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } | ||||
| ], | ], | ||||
| bootstrap: [AppComponent] | bootstrap: [AppComponent] | ||||
| @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; | |||||
| import { Location } from '@angular/common'; | import { Location } from '@angular/common'; | ||||
| import { MallService } from '../services/mall.service'; | import { MallService } from '../services/mall.service'; | ||||
| import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | ||||
| import { ToastController } from '@ionic/angular'; | |||||
| import { OrderService } from '../services/order.service'; | |||||
| import * as moment from 'moment'; | import * as moment from 'moment'; | ||||
| export type ICart = { | export type ICart = { | ||||
| @@ -40,7 +40,7 @@ export class CartPage implements OnInit { | |||||
| constructor( | constructor( | ||||
| private location: Location, | private location: Location, | ||||
| private router: Router, | private router: Router, | ||||
| public toastController: ToastController, | |||||
| private orderService: OrderService, | |||||
| private mallService: MallService | private mallService: MallService | ||||
| ) { } | ) { } | ||||
| @@ -236,4 +236,12 @@ export class CartPage implements OnInit { | |||||
| return total; | return total; | ||||
| } | } | ||||
| placeOrder() { | |||||
| this.orderService.createOrder(this.userCart).then((resp) => { | |||||
| console.log(resp); | |||||
| }, (err) => { | |||||
| console.log(err); | |||||
| }) | |||||
| } | |||||
| } | } | ||||
| @@ -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(); | |||||
| }); | |||||
| }); | |||||
| @@ -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(); | |||||
| } | |||||
| } | |||||