diff --git a/server/controllers/representationController.js b/server/controllers/representationController.js index c57247d..f0ef12b 100644 --- a/server/controllers/representationController.js +++ b/server/controllers/representationController.js @@ -284,9 +284,9 @@ module.exports.add_representation = [ const representation = new Representation(data) const user = await User.findById(user_id) - if(!user){ - res404(res,"آین کاربر در دیتای ما وجود ندارد") - }else{ + if (!user) { + res404(res, 'آین کاربر در دیتای ما وجود ندارد') + } else { await representation.save() } user.askedForRepresentation = true @@ -1114,8 +1114,11 @@ module.exports.revoke_representation_by_admin = [ try { const { user_id } = req if (!user_id) return res406(res, 'invalid user id') - const representation = await Representation.findByIdAndUpdate(req.params?.id) - const agentAccount = await User.findById(representation.user_id) + const representation = await Representation.findOne({ _id: req.params?.id }).populate('user_id') + if (!representation) return res404(res, 'Representation not found') + + const agentAccount = await User.findOne({ _id: representation.user_id }) + if (!agentAccount) return res404(res, 'Agent account not found') representation._revoked = true representation._revokedBy = user_id