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,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
|
|
|
attachmentNotFound: {
|
|
|
|
responseType: 'notFound',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2020-04-21 05:04:34 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const path = await sails.helpers.attachments
|
|
|
|
.getProjectPath(inputs.id)
|
2020-04-21 05:04:34 +05:00
|
|
|
.intercept('pathNotFound', () => Errors.ATTACHMENT_NOT_FOUND);
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
let { attachment } = path;
|
|
|
|
const { board } = path;
|
2020-04-21 05:04:34 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
|
2020-04-21 05:04:34 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
if (!isBoardMember) {
|
2020-04-21 05:04:34 +05:00
|
|
|
throw Errors.ATTACHMENT_NOT_FOUND; // Forbidden
|
|
|
|
}
|
|
|
|
|
|
|
|
const values = _.pick(inputs, ['name']);
|
2021-06-24 01:05:22 +05:00
|
|
|
attachment = await sails.helpers.attachments.updateOne(attachment, values, board, this.req);
|
2020-04-21 05:04:34 +05:00
|
|
|
|
|
|
|
if (!attachment) {
|
|
|
|
throw Errors.ATTACHMENT_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2020-04-21 05:04:34 +05:00
|
|
|
item: attachment,
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
};
|