forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasket.js
31 lines (29 loc) · 1.1 KB
/
basket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const utils = require('../lib/utils')
const insecurity = require('../lib/insecurity')
const models = require('../models/index')
const challenges = require('../data/datacache').challenges
module.exports = function retrieveBasket () {
return (req, res, next) => {
const id = req.params.id
models.Basket.findOne({ where: { id }, include: [{ model: models.Product, paranoid: false }] })
.then(basket => {
/* jshint eqeqeq:false */
utils.solveIf(challenges.basketAccessChallenge, () => {
const user = insecurity.authenticatedUsers.from(req)
return user && id && id !== 'undefined' && id !== 'null' && user.bid != id // eslint-disable-line eqeqeq
})
if (basket && basket.Products && basket.Products.length > 0) {
for (let i = 0; i < basket.Products.length; i++) {
basket.Products[i].name = req.__(basket.Products[i].name)
}
}
res.json(utils.queryResultToJson(basket))
}).catch(error => {
next(error)
})
}
}