juice-shop

Форк
0
/
delivery.ts 
48 строк · 1.5 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { type Request, type Response, type NextFunction } from 'express'
7
import { DeliveryModel } from '../models/delivery'
8

9
const security = require('../lib/insecurity')
10

11
module.exports.getDeliveryMethods = function getDeliveryMethods () {
12
  return async (req: Request, res: Response, next: NextFunction) => {
13
    const methods = await DeliveryModel.findAll()
14
    if (methods) {
15
      const sendMethods = []
16
      for (const method of methods) {
17
        sendMethods.push({
18
          id: method.id,
19
          name: method.name,
20
          price: security.isDeluxe(req) ? method.deluxePrice : method.price,
21
          eta: method.eta,
22
          icon: method.icon
23
        })
24
      }
25
      res.status(200).json({ status: 'success', data: sendMethods })
26
    } else {
27
      res.status(400).json({ status: 'error' })
28
    }
29
  }
30
}
31

32
module.exports.getDeliveryMethod = function getDeliveryMethod () {
33
  return async (req: Request, res: Response, next: NextFunction) => {
34
    const method = await DeliveryModel.findOne({ where: { id: req.params.id } })
35
    if (method != null) {
36
      const sendMethod = {
37
        id: method.id,
38
        name: method.name,
39
        price: security.isDeluxe(req) ? method.deluxePrice : method.price,
40
        eta: method.eta,
41
        icon: method.icon
42
      }
43
      res.status(200).json({ status: 'success', data: sendMethod })
44
    } else {
45
      res.status(400).json({ status: 'error' })
46
    }
47
  }
48
}
49

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.