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

52 lines
1.1 KiB
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, exits) {
const { currentUser } = this.req;
const attachmentToProjectPath = await sails.helpers
.getAttachmentToProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);
let { attachment } = attachmentToProjectPath;
2020-04-23 03:02:53 +05:00
const { card, board, project } = attachmentToProjectPath;
2020-04-21 05:04:34 +05:00
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id,
);
if (!isUserMemberForProject) {
throw Errors.ATTACHMENT_NOT_FOUND; // Forbidden
}
2020-04-23 03:02:53 +05:00
attachment = await sails.helpers.deleteAttachment(attachment, card, board, this.req);
2020-04-21 05:04:34 +05:00
if (!attachment) {
throw Errors.ATTACHMENT_NOT_FOUND;
}
return exits.success({
item: attachment,
});
},
};