feat: attachments.delete (#1714)

* feat: Add endpoint for manually deleting attachments

* mock
This commit is contained in:
Tom Moor
2020-12-10 21:40:03 -08:00
committed by GitHub
parent bc156f4cc8
commit 72189e041b
2 changed files with 79 additions and 0 deletions

View File

@@ -92,6 +92,31 @@ router.post("attachments.create", auth(), async (ctx) => {
};
});
router.post("attachments.delete", auth(), async (ctx) => {
let { id } = ctx.body;
ctx.assertPresent(id, "id is required");
const user = ctx.state.user;
const attachment = await Attachment.findByPk(id);
const document = await Document.findByPk(attachment.documentId, {
userId: user.id,
});
authorize(user, "update", document);
await attachment.destroy();
await Event.create({
name: "attachments.delete",
teamId: user.teamId,
userId: user.id,
ip: ctx.request.ip,
});
ctx.body = {
success: true,
};
});
router.post("attachments.redirect", auth(), async (ctx) => {
const { id } = ctx.body;
ctx.assertPresent(id, "id is required");