juice-shop
48 строк · 1.5 Кб
1/*
2* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3* SPDX-License-Identifier: MIT
4*/
5
6import { type Request, type Response, type NextFunction } from 'express'7import { DeliveryModel } from '../models/delivery'8
9const security = require('../lib/insecurity')10
11module.exports.getDeliveryMethods = function getDeliveryMethods () {12return async (req: Request, res: Response, next: NextFunction) => {13const methods = await DeliveryModel.findAll()14if (methods) {15const sendMethods = []16for (const method of methods) {17sendMethods.push({18id: method.id,19name: method.name,20price: security.isDeluxe(req) ? method.deluxePrice : method.price,21eta: method.eta,22icon: method.icon23})24}25res.status(200).json({ status: 'success', data: sendMethods })26} else {27res.status(400).json({ status: 'error' })28}29}30}
31
32module.exports.getDeliveryMethod = function getDeliveryMethod () {33return async (req: Request, res: Response, next: NextFunction) => {34const method = await DeliveryModel.findOne({ where: { id: req.params.id } })35if (method != null) {36const sendMethod = {37id: method.id,38name: method.name,39price: security.isDeluxe(req) ? method.deluxePrice : method.price,40eta: method.eta,41icon: method.icon42}43res.status(200).json({ status: 'success', data: sendMethod })44} else {45res.status(400).json({ status: 'error' })46}47}48}
49