user and teamId check

This commit is contained in:
Alex Holliday committed 2025-06-24 10:02:36 +08:00
1 parent c8685c4273
commit 40f879f671
1 file changed
+13
+13
View File
@@ -5,6 +5,19 @@ const verifyTeamAccess = (Model, paramName) => {
try {
const documentId = req.params[paramName];
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()) {
next();
return;