I am new to an object-oriented design pattern. I just want to convert my middleware function and models to follow an object-oriented design pattern and use that throughout my code.
// sample middleware
const isActivated = async (req, res, next) => {
const { email } = req.body
try {
const user = await User.findOne({ email: email })
if (!user) {
next(new Error('No such user is found!'))
}
if (user && !user.isActivated) {
next(new Error('Please activate the account!'))
}
} catch (Error) {
return res.status(HttpStatus.BAD_REQUEST).json({ Error })
}
}
module.exports = isActivated
Aucun commentaire:
Enregistrer un commentaire