Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions routes/productCost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/

import * as models from '../models/index'
import { type Request, type Response, type NextFunction } from 'express'

// Product cost lookup for the merchant dashboard. Same shape as the revenue
// endpoint, with the filter bound as a query parameter.
module.exports = function productCost () {
return (req: Request, res: Response, next: NextFunction) => {
const name = String(req.query.name ?? '')
models.sequelize.query(
'SELECT id, name, price FROM Products WHERE name LIKE :pattern AND deletedAt IS NULL ORDER BY price DESC',
{ replacements: { pattern: `%${name}%` }, type: models.sequelize.QueryTypes.SELECT }
).then((rows: any) => {
res.json({ name, rows })
}).catch((error: Error) => {
next(error)
})
}
}
2 changes: 2 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const resetPassword = require('./routes/resetPassword')
const securityQuestion = require('./routes/securityQuestion')
const search = require('./routes/search')
const coupon = require('./routes/coupon')
const productCost = require('./routes/productCost')
const basket = require('./routes/basket')
const order = require('./routes/order')
const verify = require('./routes/verify')
Expand Down Expand Up @@ -568,6 +569,7 @@ restoreOverwrittenFilesWithOriginals().then(() => {
app.get('/rest/user/whoami', security.updateAuthenticatedUsers(), currentUser())
app.get('/rest/user/authentication-details', authenticatedUsers())
app.get('/rest/products/search', search())
app.get('/rest/products/cost', productCost())
app.get('/rest/basket/:id', basket())
app.post('/rest/basket/:id/checkout', order())
app.put('/rest/basket/:id/coupon/:coupon', coupon())
Expand Down