user and teamId check
This commit is contained in:
1 parent
c8685c4273
commit
40f879f671
1 file changed
+13
@@ -5,6 +5,19 @@ const verifyTeamAccess = (Model, paramName) => {
|
|||||||
try {
|
try {
|
||||||
const documentId = req.params[paramName];
|
const documentId = req.params[paramName];
|
||||||
const doc = await Model.findById(documentId);
|
const doc = await Model.findById(documentId);
|
||||||
|
|
||||||
|
if (!doc) {
|
||||||
|
const error = new Error("Document not found");
|
||||||
|
error.status = 404;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req?.user?.teamId || !doc.teamId) {
|
||||||
|
const error = new Error("Missing team information");
|
||||||
|
error.status = 400;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
if (req.user.teamId.toString() === doc.teamId.toString()) {
|
if (req.user.teamId.toString() === doc.teamId.toString()) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user