routes/address.ts
/*
* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import { type Request, type Response } from 'express'
import { AddressModel } from '../models/address'
module.exports.getAddress = function getAddress () {
return async (req: Request, res: Response) => {
const addresses = await AddressModel.findAll({ where: { UserId: req.body.UserId } })
res.status(200).json({ status: 'success', data: addresses })
}
}
module.exports.getAddressById = function getAddressById () {
return async (req: Request, res: Response) => {
const address = await AddressModel.findOne({ where: { id: req.params.id, UserId: req.body.UserId } })
if (address != null) {
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: Request, res: Response) => {
const address = await AddressModel.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.' })
}
}
}