forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.js
35 lines (31 loc) · 1.18 KB
/
address.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.getAddress = function getAddress () {
return async (req, res, next) => {
const addresses = await models.Address.findAll({ where: { UserId: req.body.UserId } })
res.status(200).json({ status: 'success', data: addresses })
}
}
module.exports.getAddressById = function getAddressById () {
return async (req, res, next) => {
const address = await models.Address.findOne({ where: { id: req.params.id, UserId: req.body.UserId } })
if (address) {
res.status(200).json({ status: 'success', data: address })
} else {
res.status(400).json({ status: 'error', data: 'Malicious activity detected.' })
}
}
}
module.exports.delAddressById = function delAddressById () {
return async (req, res, next) => {
const address = await models.Address.destroy({ where: { id: req.params.id, UserId: req.body.UserId } })
if (address) {
res.status(200).json({ status: 'success', data: 'Address deleted successfully.' })
} else {
res.status(400).json({ status: 'error', data: 'Malicious activity detected.' })
}
}
}