1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/controllers/attachments/delete.js

49 lines
983 B
JavaScript
Raw Normal View History

2020-04-21 05:04:34 +05:00
const Errors = {
ATTACHMENT_NOT_FOUND: {
attachmentNotFound: 'Attachment not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
},
exits: {
attachmentNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
2020-04-21 05:04:34 +05:00
const { currentUser } = this.req;
const path = await sails.helpers.attachments
.getProjectPath(inputs.id)
2020-04-21 05:04:34 +05:00
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);
let { attachment } = path;
const { card, board } = path;
2020-04-21 05:04:34 +05:00
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
2020-04-21 05:04:34 +05:00
if (!isBoardMember) {
2020-04-21 05:04:34 +05:00
throw Errors.ATTACHMENT_NOT_FOUND; // Forbidden
}
attachment = await sails.helpers.attachments.deleteOne(attachment, board, card, this.req);
2020-04-21 05:04:34 +05:00
if (!attachment) {
throw Errors.ATTACHMENT_NOT_FOUND;
}
return {
2020-04-21 05:04:34 +05:00
item: attachment,
};
2020-04-21 05:04:34 +05:00
},
};