Permalink
Browse files

Add Order Dashboard tracking results

  • Loading branch information...
CaptainFreak committed Apr 17, 2018
1 parent 79368c5 commit 3797a5c3ba4c5b3cfd488d9b998ec369d23b0064
View
@@ -46,6 +46,7 @@
"BASKET_ADD_SAME_PRODUCT": "Added another {{product}} to basket.",
"BASKET_ADD_PRODUCT": "Placed {{product}} into basket.",
"LABEL_PRODUCT": "Product",
"LABEL_PRODUCT_ORDERED": "Products ordered:",
"LABEL_NAME": "Name",
"LABEL_DESCRIPTION": "Description",
"LABEL_PRICE": "Price",
@@ -6,6 +6,5 @@ angular.module('juiceShop').controller('TrackOrderController', [
$scope.save = function () {
$location.path('/track-result').search({id: $scope.orderId || ''})
console.log($scope.orderId)
}
}])
@@ -9,6 +9,10 @@ angular.module('juiceShop').controller('TrackResultController', [
$scope.orderId = $location.search().id
trackOrderService.save($scope.orderId).then(function (results) {
$scope.results = {}
$scope.results.id = $sce.trustAsHtml(results.id)
$scope.results.orderNo = $sce.trustAsHtml(results.data[0].orderNo)
$scope.results.email = results.data[0].email
$scope.results.totalPrice = results.data[0].totalPrice
$scope.results.products = results.data[0].products
$scope.results.eta = results.data[0].eta
})
}])
@@ -6,7 +6,7 @@ angular.module('juiceShop').factory('TrackOrderService', ['$http', '$q', functio
function save (params) {
var trackingInformation = $q.defer()
$http.get(host + '?id=' + params).then(function (response) {
trackingInformation.resolve(response.data.data)
trackingInformation.resolve(response.data)
}).catch(function (response) {
trackingInformation.reject(response.data)
})
View
@@ -1,5 +1,26 @@
<div class="row">
<section class="col-md-4 col-md-offset-4 col-sm-8 col-sm-offset-2">
<h3 ng-show="results.id" class="page-header page-header-sm"><span translate="TITLE_TRACK_RESULTS"></span> <span class="label label-default" ng-bind-html="results.id"></span></h3>
<h3 ng-show="results.orderNo" class="page-header page-header-sm"><span translate="TITLE_TRACK_RESULTS"></span> <span class="label label-default" ng-bind-html="results.orderNo"></span></h3>
<div>
<h4>ETA: </h4>
<span ng-bind="results.eta"></span>
</div>
<br>
<h4 translate="LABEL_PRODUCT_ORDERED"></h4>
<table class="table table-striped table-bordered table-condensed">
<tr>
<th translate="LABEL_PRODUCT"></th>
<th translate="LABEL_PRICE"></th>
<th translate="LABEL_QUANTITY"></th>
<th translate="LABEL_TOTAL_PRICE"></th>
</tr>
<tr data-ng-repeat="product in results.products">
<td>{{product.name}}</td>
<td>{{product.quantity}}</td>
<td>{{product.price}}</td>
<td>{{product.total}}</td>
</tr>
</table>
</section>
</div>
View
@@ -1,9 +1,11 @@
const MarsDB = require('marsdb')
const reviews = new MarsDB.Collection('posts')
const orders = new MarsDB.Collection('orders')
const db = {
reviews
reviews,
orders
}
module.exports = db
View
@@ -8,6 +8,7 @@ const models = require('../models/index')
const products = require('../data/datacache').products
const challenges = require('../data/datacache').challenges
const config = require('config')
const db = require('../data/mongodb')
module.exports = function placeOrder () {
return (req, res, next) => {
@@ -31,11 +32,19 @@ module.exports = function placeOrder () {
doc.moveDown()
doc.moveDown()
let totalPrice = 0
let basketProducts = []
basket.Products.forEach(({BasketItem, price, name}) => {
if (utils.notSolved(challenges.christmasSpecialChallenge) && BasketItem.ProductId === products.christmasSpecial.id) {
utils.solve(challenges.christmasSpecialChallenge)
}
const itemTotal = price * BasketItem.quantity
const product = { quantity : BasketItem.quantity,
name : name,
price : price,
total : itemTotal
}
basketProducts.push(product);
doc.text(BasketItem.quantity + 'x ' + name + ' ea. ' + price + ' = ' + itemTotal)
doc.moveDown()
totalPrice += itemTotal
@@ -60,12 +69,25 @@ module.exports = function placeOrder () {
if (utils.notSolved(challenges.negativeOrderChallenge) && totalPrice < 0) {
utils.solve(challenges.negativeOrderChallenge)
}
db.orders.insert({
orderNo: orderNo,
email: (customer ? customer.data ? customer.data.email.replace(/[aeiou]/gi, '*') : undefined : undefined),
totalPrice: totalPrice,
products: basketProducts,
eta: Math.floor((Math.random() * 10) + 1).toString() + ' days to delivery'
}).then(result => {
console.log("Successfully saved order with id:" + orderNo)
}, err => {
console.log("Error occured while saving order.")
})
fileWriter.on('finish', () => {
basket.updateAttributes({ coupon: null })
models.BasketItem.destroy({ where: { BasketId: id } })
res.json({ orderConfirmation: '/ftp/' + pdfFile })
})
} else {
next(new Error('Basket with id=' + id + ' does not exist.'))
}
View
@@ -1,13 +1,17 @@
const utils = require('../lib/utils')
const challenges = require('../data/datacache').challenges
const db = require('../data/mongodb')
module.exports = function trackOrder () {
return (req, res) => {
if (utils.notSolved(challenges.reflectedXssChallenge) && utils.contains(req.query.id, '<script>alert("XSS")</script>')) {
utils.solve(challenges.reflectedXssChallenge)
}
res.json({'id': req.query.id,
'more': 'Coming Soon.'
db.orders.find({ orderNo: req.query.id }).then(order => {
const result = utils.queryResultToJson(order);
res.json(result)
}, () => {
res.status(400).json({ error: 'Wrong Param' })
})
}
}

0 comments on commit 3797a5c

Please sign in to comment.