1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 13:14:06 +01:00

🐛 fix findOne exists query

This commit is contained in:
Flam3rboy 2021-07-19 22:42:07 +02:00
parent 89b5f6963a
commit 11ace49d8c

View File

@ -52,10 +52,17 @@ mongoose.plugin((schema: Schema, opts: any) => {
}); });
}, },
}); });
schema.post("findOne", (doc, next) => { schema.post("findOne", function (doc, next) {
if (!doc) return next(new HTTPError("Not found", 404)); try {
// @ts-ignore
const isExistsQuery = JSON.stringify(this._userProvidedFields) === JSON.stringify({ _id: 1 });
if (!doc && !isExistsQuery) return next(new HTTPError("Not found", 404));
// @ts-ignore // @ts-ignore
return next(); return next();
} catch (error) {
// @ts-ignore
next();
}
}); });
}); });