forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.js
35 lines (31 loc) · 1.18 KB
/
payment.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
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const models = require('../models/index')
module.exports.getPaymentMethods = function getPaymentMethods () {
return async (req, res, next) => {
const cards = await models.Card.findAll({ where: { UserId: req.body.UserId } })
res.status(200).json({ status: 'success', data: cards })
}
}
module.exports.getPaymentMethodById = function getPaymentMethodById () {
return async (req, res, next) => {
const card = await models.Card.findOne({ where: { id: req.params.id, UserId: req.body.UserId } })
if (card) {
res.status(200).json({ status: 'success', data: card })
} else {
res.status(400).json({ status: 'error', data: 'Malicious activity detected' })
}
}
}
module.exports.delPaymentMethodById = function delPaymentMethodById () {
return async (req, res, next) => {
const card = await models.Card.destroy({ where: { id: req.params.id, UserId: req.body.UserId } })
if (card) {
res.status(200).json({ status: 'success', data: 'Card deleted successfully.' })
} else {
res.status(400).json({ status: 'error', data: 'Malicious activity detected.' })
}
}
}