Commit 19ad45b3 authored by Egor Kremnev's avatar Egor Kremnev

fix unique self ignore

parent b6377a90
......@@ -15,7 +15,8 @@ const UserSchema = new Schema({
validate: {
validator: async function (username) {
const user = await User.findOne({username});
return !user || user._id !== this._id;
return !user || user._id.toString() === this._id.toString();
},
message: "This user is already exists"
}
......@@ -28,7 +29,7 @@ const UserSchema = new Schema({
if (!token) return true;
const user = await User.findOne({token});
return !user || user._id !== this._id;
return !user || user._id.toString() === this._id.toString();
},
message: "Token duplicated"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment