Skip to content

Commit

Permalink
Refactoring: Extract an Order Model
Browse files Browse the repository at this point in the history
  • Loading branch information
mosh-hamedani committed Aug 25, 2017
1 parent 20d53fc commit 98692d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/app/check-out/check-out.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Subscription } from 'rxjs/Subscription';
import { ShoppingCart } from './../models/shopping-cart';
import { ShoppingCartService } from './../shopping-cart.service';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Order } from "../models/order";

@Component({
selector: 'app-check-out',
Expand Down Expand Up @@ -34,23 +35,7 @@ export class CheckOutComponent implements OnInit, OnDestroy {
}

placeOrder() {
let order = {
userId: this.userId,
datePlaced: new Date().getTime(),
shipping: this.shipping,
items: this.cart.items.map(i => {
return {
product: {
title: i.title,
imageUrl: i.imageUrl,
price: i.price
},
quantity: i.quantity,
totalPrice: i.totalPrice
}
})
};

let order = new Order(this.userId, this.shipping, this.cart);
this.orderService.storeOrder(order);
}
}
22 changes: 22 additions & 0 deletions src/app/models/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ShoppingCart } from './shopping-cart';

export class Order {
datePlaced: number;
items: any[];

constructor(public userId: string, public shipping: any, shoppingCart: ShoppingCart) {
this.datePlaced = new Date().getTime();

this.items = shoppingCart.items.map(i => {
return {
product: {
title: i.title,
imageUrl: i.imageUrl,
price: i.price
},
quantity: i.quantity,
totalPrice: i.totalPrice
}
})
}
}

0 comments on commit 98692d6

Please sign in to comment.