Use transaction from middleware for more database queries (#6051)

This commit is contained in:
jannschu
2023-10-21 23:31:14 +02:00
committed by GitHub
parent 5df48b3204
commit 0518cdc6d9
7 changed files with 29 additions and 11 deletions

View File

@@ -165,7 +165,9 @@ router.post(
const { user } = ctx.state.auth;
authorize(user, "importCollection", user.team);
const attachment = await Attachment.findByPk(attachmentId);
const attachment = await Attachment.findByPk(attachmentId, {
transaction,
});
authorize(user, "read", attachment);
const fileOperation = await FileOperation.create(
@@ -373,7 +375,7 @@ router.post(
const collection = await Collection.scope({
method: ["withMembership", actor.id],
}).findByPk(id);
}).findByPk(id, { transaction });
authorize(actor, "update", collection);
const user = await User.findByPk(userId);
@@ -443,10 +445,10 @@ router.post(
const collection = await Collection.scope({
method: ["withMembership", actor.id],
}).findByPk(id);
}).findByPk(id, { transaction });
authorize(actor, "update", collection);
const user = await User.findByPk(userId);
const user = await User.findByPk(userId, { transaction });
authorize(actor, "read", user);
await collection.$remove("user", user, { transaction });
@@ -545,12 +547,12 @@ router.post(
const { id, format, includeAttachments } = ctx.input.body;
const { user } = ctx.state.auth;
const team = await Team.findByPk(user.teamId);
const team = await Team.findByPk(user.teamId, { transaction });
authorize(user, "createExport", team);
const collection = await Collection.scope({
method: ["withMembership", user.id],
}).findByPk(id);
}).findByPk(id, { transaction });
authorize(user, "export", collection);
const fileOperation = await collectionExporter({
@@ -582,7 +584,7 @@ router.post(
const { transaction } = ctx.state;
const { format, includeAttachments } = ctx.input.body;
const { user } = ctx.state.auth;
const team = await Team.findByPk(user.teamId);
const team = await Team.findByPk(user.teamId, { transaction });
authorize(user, "createExport", team);
const fileOperation = await collectionExporter({