feat: attachments.delete (#1714)
* feat: Add endpoint for manually deleting attachments * mock
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user