backend/middlewares/validateAccountID.js

23 lines
519 B
JavaScript
Raw Normal View History

const Account = require('../api/models/accountModel');
async function validateAccountID(req, res, next) {
const { id } = req.params;
try {
const account = await Account.getAccountById(id);
if (typeof account == 'undefined') {
return res.status(404).json({
message: `Account with id ${id} doesn't exist.`,
});
} else {
next();
}
} catch (error) {
res.status(500).json({
message: `Failed to fetch account with id ${id}.`,
error,
});
}
}
exports.validateAccountID = validateAccountID;