Browse Source

Place order service connected

master
kj1352 5 years ago
parent
commit
c1aa379f49
4 changed files with 50 additions and 2 deletions
  1. +2
    -0
      src/app/app.module.ts
  2. +10
    -2
      src/app/cart/cart.page.ts
  3. +12
    -0
      src/app/services/order.service.spec.ts
  4. +26
    -0
      src/app/services/order.service.ts

+ 2
- 0
src/app/app.module.ts View File

@@ -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]


+ 10
- 2
src/app/cart/cart.page.ts View File

@@ -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);
})
}

}

+ 12
- 0
src/app/services/order.service.spec.ts View File

@@ -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();
});
});

+ 26
- 0
src/app/services/order.service.ts View File

@@ -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();
}
}

Loading…
Cancel
Save