Use transaction from middleware for more database queries (#6051)
This commit is contained in:
@@ -955,6 +955,7 @@ router.post(
|
||||
const document = await Document.findByPk(id, {
|
||||
userId: user.id,
|
||||
includeState: true,
|
||||
transaction,
|
||||
});
|
||||
collection = document?.collection;
|
||||
authorize(user, "update", document);
|
||||
@@ -971,7 +972,7 @@ router.post(
|
||||
);
|
||||
collection = await Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}).findByPk(collectionId!);
|
||||
}).findByPk(collectionId!, { transaction });
|
||||
}
|
||||
authorize(user, "createDocument", collection);
|
||||
}
|
||||
@@ -1025,13 +1026,14 @@ router.post(
|
||||
|
||||
const document = await Document.findByPk(id, {
|
||||
userId: user.id,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "read", document);
|
||||
|
||||
const collection = collectionId
|
||||
? await Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}).findByPk(collectionId)
|
||||
}).findByPk(collectionId, { transaction })
|
||||
: document?.collection;
|
||||
|
||||
if (collection) {
|
||||
@@ -1041,6 +1043,7 @@ router.post(
|
||||
if (parentDocumentId) {
|
||||
const parent = await Document.findByPk(parentDocumentId, {
|
||||
userId: user.id,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "update", parent);
|
||||
|
||||
@@ -1083,17 +1086,19 @@ router.post(
|
||||
const { user } = ctx.state.auth;
|
||||
const document = await Document.findByPk(id, {
|
||||
userId: user.id,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "move", document);
|
||||
|
||||
const collection = await Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}).findByPk(collectionId);
|
||||
}).findByPk(collectionId, { transaction });
|
||||
authorize(user, "updateDocument", collection);
|
||||
|
||||
if (parentDocumentId) {
|
||||
const parent = await Document.findByPk(parentDocumentId, {
|
||||
userId: user.id,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "update", parent);
|
||||
|
||||
@@ -1293,6 +1298,7 @@ router.post(
|
||||
id: collectionId,
|
||||
teamId: user.teamId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "createDocument", collection);
|
||||
let parentDocument;
|
||||
@@ -1303,6 +1309,7 @@ router.post(
|
||||
id: parentDocumentId,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "read", parentDocument, {
|
||||
collection,
|
||||
@@ -1376,6 +1383,7 @@ router.post(
|
||||
id: collectionId,
|
||||
teamId: user.teamId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "createDocument", collection);
|
||||
}
|
||||
@@ -1399,6 +1407,7 @@ router.post(
|
||||
if (templateId) {
|
||||
templateDocument = await Document.findByPk(templateId, {
|
||||
userId: user.id,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "read", templateDocument);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user