Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coops branch #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 68 additions & 28 deletions src/app/layout/checkout/checkout.component.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,
Expand All @@ -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;

Expand All @@ -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() {
Expand All @@ -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')
// }
/////////////////////////////////////////////////////////////////////////

}


10 changes: 6 additions & 4 deletions src/app/models/order.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 6 additions & 2 deletions src/app/services/checkout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -33,8 +35,10 @@ export class CheckoutService {
// .pipe(catchError(this.handleError<ClientMessage>('register User', undefined)));
// }

public sendGamesArray(gamesArray: Array<Object>) {
return this.http.post<ClientMessage>(`${DEALSHARK_URL}newOwnedGames`, gamesArray)
public sendGamesArray(newOwnedGames: order): Observable<ClientMessage> {

console.log("hitting sendGamesArray as well");
return this.http.post<ClientMessage>(`${DEALSHARK_URL}newOwnedGames`, newOwnedGames)
.pipe(catchError(this.handleError<ClientMessage>('New Owned Games', undefined)));
}

Expand Down