diff --git a/server/controllers/representationController.js b/server/controllers/representationController.js index 2e95948..c57247d 100644 --- a/server/controllers/representationController.js +++ b/server/controllers/representationController.js @@ -283,8 +283,12 @@ module.exports.add_representation = [ data.representation_code = representation_code const representation = new Representation(data) - await representation.save() const user = await User.findById(user_id) + if(!user){ + res404(res,"آین کاربر در دیتای ما وجود ندارد") + }else{ + await representation.save() + } user.askedForRepresentation = true user.representation_code = representation_code await user.save() diff --git a/server/models/Representation.js b/server/models/Representation.js index af9ec21..c473aa8 100644 --- a/server/models/Representation.js +++ b/server/models/Representation.js @@ -11,7 +11,7 @@ FilesSchema.virtual('url').get(file) const RepresentationSchema = mongoose.Schema({ // user info - user_id: { type: mongoose.ObjectId, ref: 'User' }, + user_id: { type: String, ref: 'User' }, representation_code: String, agent_code: String, editAccess: { type: Boolean, default: false },