Enhance order service for new API
This commit is contained in:
parent
96eb3eb7f6
commit
3810900036
2 changed files with 11 additions and 10 deletions
|
@ -106,7 +106,7 @@ export class OrderComponent implements OnInit{
|
||||||
this.orderUpdate.subscribe((order) => {
|
this.orderUpdate.subscribe((order) => {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
|
||||||
console.log('this.order > ' + JSON.stringify(this.order));
|
//console.log('this.order > ' + JSON.stringify(this.order));
|
||||||
// ------------------------------------------------
|
// ------------------------------------------------
|
||||||
this.oLines = [];
|
this.oLines = [];
|
||||||
this.myLines = this.order.lines;
|
this.myLines = this.order.lines;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Subject, BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
||||||
import { Order } from './order.model';
|
import { Order } from './order.model';
|
||||||
import { UserService } from '../user.service';
|
import { UserService } from '../user.service';
|
||||||
|
@ -83,6 +83,8 @@ export class OrderService {
|
||||||
public userUpdate: Observable<User>;
|
public userUpdate: Observable<User>;
|
||||||
public ownerUpdate: Observable<Owner>;
|
public ownerUpdate: Observable<Owner>;
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
private reqParams: HttpParams;
|
||||||
|
private session: null|string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
|
@ -90,12 +92,13 @@ export class OrderService {
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
) {
|
) {
|
||||||
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
||||||
|
this.session = localStorage.getItem('s4z_token');
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
||||||
|
this.reqParams = new HttpParams().append('session', this.session!);
|
||||||
this.userUpdate = userService.userUpdate;
|
this.userUpdate = userService.userUpdate;
|
||||||
this.ownerUpdate = userService.ownerUpdate;
|
this.ownerUpdate = userService.ownerUpdate;
|
||||||
this.userUpdate.subscribe((user) => {
|
this.userUpdate.subscribe((user) => {
|
||||||
this.dataStore.user = user;
|
this.dataStore.user = user;
|
||||||
//console.log('OS: const', user);
|
|
||||||
this.getOrder();
|
this.getOrder();
|
||||||
});
|
});
|
||||||
this.ownerUpdate.subscribe((owner) => {
|
this.ownerUpdate.subscribe((owner) => {
|
||||||
|
@ -104,9 +107,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrder() {
|
getOrder() {
|
||||||
var session = this.dataStore.user.session;
|
let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/order', { headers:this.reqHeaders, params: this.reqParams, observe: 'response'});
|
||||||
const params = new HttpParams().append('session', session);
|
|
||||||
let obs = this.http.get<{message: string, order: any}>(this.beUrl+'api/order', { headers:this.reqHeaders, params:params, observe: 'response'});
|
|
||||||
|
|
||||||
obs.subscribe((OrderDataResponse) => {
|
obs.subscribe((OrderDataResponse) => {
|
||||||
if (OrderDataResponse.status == 200) {
|
if (OrderDataResponse.status == 200) {
|
||||||
|
@ -127,7 +128,7 @@ export class OrderService {
|
||||||
|
|
||||||
getAllOrders(){
|
getAllOrders(){
|
||||||
var address = this.dataStore.user.address;
|
var address = this.dataStore.user.address;
|
||||||
const params = new HttpParams().append('address', address);
|
const params = this.reqParams.append('address', address);
|
||||||
let obs = this.http.get<{message: string, orders: any}>(this.beUrl+'api/allorders', { headers:this.reqHeaders, params:params, observe: 'response'});
|
let obs = this.http.get<{message: string, orders: any}>(this.beUrl+'api/allorders', { headers:this.reqHeaders, params:params, observe: 'response'});
|
||||||
obs.subscribe((OrdersData) => {
|
obs.subscribe((OrdersData) => {
|
||||||
if (OrdersData.status == 200 ){
|
if (OrdersData.status == 200 ){
|
||||||
|
@ -145,7 +146,7 @@ export class OrderService {
|
||||||
addToOrder(lineItem: LineItem) {
|
addToOrder(lineItem: LineItem) {
|
||||||
if(this.dataStore.order._id != null) {
|
if(this.dataStore.order._id != null) {
|
||||||
this.dataStore.order.lines.push(lineItem);
|
this.dataStore.order.lines.push(lineItem);
|
||||||
let obs = this.http.post(this.beUrl+'api/order', { payload: this.dataStore.order }, { headers: this.reqHeaders });
|
let obs = this.http.post(this.beUrl+'api/order', { payload: this.dataStore.order }, { headers: this.reqHeaders, params: this.reqParams });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
this.getOrder();
|
this.getOrder();
|
||||||
});
|
});
|
||||||
|
@ -170,7 +171,7 @@ export class OrderService {
|
||||||
shortCode: '',
|
shortCode: '',
|
||||||
lines: [lineItem]
|
lines: [lineItem]
|
||||||
};
|
};
|
||||||
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {payload: order}, { headers: this.reqHeaders });
|
let obs = this.http.post<{message: string, order: Order}>(this.beUrl+'api/order', {payload: order}, { headers: this.reqHeaders, params: this.reqParams });
|
||||||
obs.subscribe((orderData) => {
|
obs.subscribe((orderData) => {
|
||||||
console.log('Created order');
|
console.log('Created order');
|
||||||
this.getOrder()
|
this.getOrder()
|
||||||
|
@ -180,7 +181,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelOrder(id: string) {
|
cancelOrder(id: string) {
|
||||||
let obs = this.http.delete<{message: string}>(this.beUrl+'api/order/'+id, { headers: this.reqHeaders });
|
let obs = this.http.delete<{message: string}>(this.beUrl+'api/order/'+id, { headers: this.reqHeaders, params: this.reqParams });
|
||||||
|
|
||||||
obs.subscribe((OrderResponse) => {
|
obs.subscribe((OrderResponse) => {
|
||||||
console.log('Order deleted');
|
console.log('Order deleted');
|
||||||
|
|
Loading…
Reference in a new issue