forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelivery.js
44 lines (41 loc) · 1.27 KB
/
delivery.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
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const models = require('../models/index')
const insecurity = require('../lib/insecurity')
module.exports.getDeliveryMethods = function getDeliveryMethods () {
return async (req, res, next) => {
const methods = await models.Delivery.findAll()
if (methods) {
const sendMethods = []
for (const method of methods) {
sendMethods.push({
id: method.id,
name: method.name,
price: insecurity.isDeluxe(req) ? method.deluxePrice : method.price,
eta: method.eta
})
}
res.status(200).json({ status: 'success', data: sendMethods })
} else {
res.status(400).json({ status: 'error' })
}
}
}
module.exports.getDeliveryMethod = function getDeliveryMethod () {
return async (req, res, next) => {
const method = await models.Delivery.findOne({ where: { id: req.params.id } })
if (method) {
const sendMethod = {
id: method.id,
name: method.name,
price: insecurity.isDeluxe(req) ? method.deluxePrice : method.price,
eta: method.eta
}
res.status(200).json({ status: 'success', data: sendMethod })
} else {
res.status(400).json({ status: 'error' })
}
}
}