From eea8e06d481240ba9bb7117b28c7eedc239da731 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 25 Oct 2021 12:49:50 -0500 Subject: [PATCH] Add order mongoose schema --- backend/models/order.js | 12 ++++++++++++ src/app/items/item-list/item-list.component.html | 2 +- src/app/items/item-list/item-list.component.ts | 4 ++++ src/app/order/order.service.ts | 13 +++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 backend/models/order.js create mode 100644 src/app/order/order.service.ts diff --git a/backend/models/order.js b/backend/models/order.js new file mode 100644 index 0000000..bfdf2b9 --- /dev/null +++ b/backend/models/order.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); + +const orderSchema = mongoose.Schema({ + address: {type: String, required: true}, + timestamp: {type: Date, required: true, default: Date.now}, + closed: { type: Boolean, required: true, default:false }, + lines: [{ + qty: {type: Number, required: true, default: 1}, + item: { type: String, required: true}, + cost: { type: Number, required: true, default: 0} + }] +}); diff --git a/src/app/items/item-list/item-list.component.html b/src/app/items/item-list/item-list.component.html index 2f0c6dc..4d0d729 100644 --- a/src/app/items/item-list/item-list.component.html +++ b/src/app/items/item-list/item-list.component.html @@ -8,7 +8,7 @@ {{item.name}}

{{item.cost | currency: 'USD'}}

-

{{priceUpdate | async}}

+

{{(item.cost/price) | number: '1.0-6'}}

diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index 0b12752..89b4332 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -18,6 +18,7 @@ import { ItemCreateComponent } from '../item-create/item-create.component'; export class ItemListComponent implements OnInit{ public items: Item[] = []; private owner: Owner = {_id: '', name: '', address: ''}; + public price: number = 1; public ownerUpdate: Observable; public itemsUpdate: Observable; public priceUpdate: Observable; @@ -38,6 +39,9 @@ export class ItemListComponent implements OnInit{ this.items = items; }); }); + this.priceUpdate.subscribe((price) => { + this.price = price; + }); } ngOnInit(){ diff --git a/src/app/order/order.service.ts b/src/app/order/order.service.ts new file mode 100644 index 0000000..5fc2422 --- /dev/null +++ b/src/app/order/order.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { Subject, BehaviorSubject, Observable } from 'rxjs'; +import { HttpClient, HttpParams } from '@angular/common/http'; + +@Injectable({providedIn: 'root'}) + +export class OrderService { + //TODO implement the Order interface + private dataStore: { order: string } = { order: ''}; + + constructor(private http: HttpClient) { + } +}