diff --git a/src/app/layout/checkout/checkout.component.ts b/src/app/layout/checkout/checkout.component.ts index 17dbddf..9530f4d 100644 --- a/src/app/layout/checkout/checkout.component.ts +++ b/src/app/layout/checkout/checkout.component.ts @@ -1,13 +1,14 @@ +import { orderUser } from './../../models/orderUser'; import { ClientMessage } from './../../models/client-message.model'; import { User } from 'src/app/models/user.model'; import { order } from './../../models/order'; -import { orderUser } from '../../models/orderUser'; + import { CheckoutService } from './../../services/checkout.service'; import { Component, OnInit } from '@angular/core'; import { environment } from "../../../environments/environment" import { BrowserModule } from '@angular/platform-browser' -import { IGameInfo } from 'src/app/models/gameModel'; +import { IGameInfo, IGameDeal } from 'src/app/models/gameModel'; @Component({ @@ -19,10 +20,24 @@ export class CheckoutComponent implements OnInit { totalPrice=0; + gameId=0; + gamePrice=0; + quantity=0; + + orderArray: IGameInfo[] = []; + arr = []; + + newOwnedGames: order = { + gameId: 0, + gamePrice: 5, + quantity: 0, + orderUser: { orderUserId : 0} + } + newOrder: orderUser = { totalPrice: 0, @@ -31,8 +46,13 @@ export class CheckoutComponent implements OnInit { currentUser = JSON.parse(sessionStorage.getItem('currentUser')); + + + constructor(private checkoutService: CheckoutService) { } + orderUser?: orderUser; + ngOnInit(): void { this.orderArray = Boolean(sessionStorage.getItem(environment.sessionNameForCart))== true ? JSON.parse(sessionStorage.getItem(environment.sessionNameForCart)) : null; @@ -47,6 +67,7 @@ viewSessionStorage() { console.log("Here is session length" + session.length); console.log(session[0].salePrice) console.log('Here is the current users id: ' + this.currentUser.id); + } purchaseGames() { @@ -58,43 +79,62 @@ purchaseGames() { //Creating an array of order objects using the list of games in the cart (orderArray) - /* for(let i = 0; i < this.orderArray.length; i++) { - let theOrder: order = {gameId: 0, gamePrice: 0, quantity: 1, orderUserId: 0} - theOrder.gameId = this.orderArray[i].gameID; - theOrder.gamePrice = this.orderArray[i].salePrice; - theOrder.orderUserId = this.currentUser.id; - //this.orderArray.push(theOrder); - }*/ + // for(let i = 0; i < this.orderArray.length; i++) { + // let theOrder: order = {gameId: 0, gamePrice: 0, quantity: 1, orderUserId: 0} + // theOrder.gameId = this.orderArray[i].gameID; + // theOrder.gamePrice = this.orderArray[i].salePrice; + // theOrder.orderUserId = this.currentUser.id; + // // this.orderArray.push(theOrder); + // } - console.log("here is the orderArray" + JSON.stringify(this.orderArray)); + for(let i = 0; i < this.orderArray.length; i++) { + + // this.orderArray.push(theOrder); + } + + // console.log("here is the orderArray" + JSON.stringify(this.orderArray)); + + this.arr.push(this.orderArray[0].gameID); + this.arr.push(this.orderArray[0].salePrice); + this.arr.push(1); + this.arr.push(this.currentUser.id); + console.log("this is the arr " + this.arr); this.newOrder.totalPrice = this.totalPrice; this.newOrder.user = {"id" : ""+ this.currentUser.id + ""}; + + sessionStorage.setItem('currentSale', JSON.stringify(this.orderUser)); + + + const currentSale = JSON.parse(sessionStorage.getItem('orderUser')); + console.log("this is the current sale " + currentSale); + + + + + + + this.newOwnedGames.gameId = this.orderArray[0].gameID; + this.newOwnedGames.gamePrice = this.totalPrice; + this.newOwnedGames.quantity = 1; + this.newOwnedGames.orderUser = {"orderUserId" : ""+ this.currentUser.id + ""}; + + + + + console.log("here is the new order: " + JSON.stringify(this.newOrder)); + console.log("here is the orderArray" + JSON.stringify(this.orderArray[0].gameID)); + console.log("this is new owned games object " + JSON.stringify(this.newOwnedGames)); + console.log("this is the new owned games object without stringify " + this.newOwnedGames); console.log(this.orderArray) this.checkoutService.sendOrderUser(this.newOrder).subscribe(data => this.clientMessage = data, error => this.clientMessage.message = "something went wrong in checkout.ts"); - // this.checkoutService.sendGamesArray(this.orderArray); + this.checkoutService.sendGamesArray(this.newOwnedGames).subscribe(data => this.clientMessage = data, error => this.clientMessage.message = "something went wrong in checkout.ts 2"); } - ///////////////////////////////////////////////////// - - // this.heroService.registerHero(this.hero).subscribe(data => this.clientMessage = data, error => this.clientMessage.message = 'SOMETHING WENT WRONG IN register.ts'); - // } - -//////////////////////////////////////////////////// - // public registerUserFromService(): void { - // this.userService.registerUser(this.user).subscribe(data => { - // this.clientMessage = data - // if (data != null){ - // console.log(data) - // this.message = "You have successfully create an account. Please click here to log in" - // }else - // this.errMessage = "Something had gone wrong at the backend or you have been disconnect to our server" - // }, error => this.clientMessage.message = 'SOMETHING WENT WRONG IN REGISTER.TS') - // } - ///////////////////////////////////////////////////////////////////////// + } diff --git a/src/app/models/order.ts b/src/app/models/order.ts index 8a06908..94d6057 100644 --- a/src/app/models/order.ts +++ b/src/app/models/order.ts @@ -1,6 +1,8 @@ +import { orderUser } from './orderUser'; export interface order { - gameId?: number; - gamePrice?: number; - quantity?: number; - orderUserId?: number; + orderid?: Number, + gameId?: Number; + gamePrice?: Number; + quantity?: Number; + orderUser: Object; } \ No newline at end of file diff --git a/src/app/services/checkout.service.ts b/src/app/services/checkout.service.ts index 8e78d2f..274e969 100644 --- a/src/app/services/checkout.service.ts +++ b/src/app/services/checkout.service.ts @@ -6,6 +6,8 @@ import { Observable, of } from 'rxjs'; import { User } from './../models/user.model'; import { ClientMessage } from './../models/client-message.model'; import { Injectable } from '@angular/core'; +import { order } from '../models/order'; + @Injectable({ @@ -33,8 +35,10 @@ export class CheckoutService { // .pipe(catchError(this.handleError('register User', undefined))); // } -public sendGamesArray(gamesArray: Array) { - return this.http.post(`${DEALSHARK_URL}newOwnedGames`, gamesArray) +public sendGamesArray(newOwnedGames: order): Observable { + + console.log("hitting sendGamesArray as well"); + return this.http.post(`${DEALSHARK_URL}newOwnedGames`, newOwnedGames) .pipe(catchError(this.handleError('New Owned Games', undefined))); }