body("isbn", "ISBN must not be empty").isLength({ min: 1 }).trim().custom((value,{req}) => { return Book.findOne({isbn : value,user: req.user._id}).then(book => { if (book) { return Promise.reject("Book already exist with this ISBN no."); } }); })
router.delete('/api/me', [ apiAuthRequired, body('login') .custom((login, { req }) => req.user.login === login) .withMessage('Login is incorrect'), body('password') .custom((passwords, { req }) => { return User .findById(req.user._id) .select(['password', 'authority']) .exec() async (req, res, next) => { try { const status = await userController.removeUser(req.user._id); res.clearCookie('kot.user'); req.logout();
body("isbn", "ISBN must not be empty").isLength({ min: 1 }).trim().custom((value,{req}) => { return Book.findOne({isbn : value,user: req.user._id, _id: { "$ne": req.params.id }}).then(book => { if (book) { return Promise.reject("Book already exist with this ISBN no."); } }); })