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/comment-actions/create.js

51 lines
985 B
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
const Errors = {
CARD_NOT_FOUND: {
2020-04-03 00:35:25 +05:00
cardNotFound: 'Card not found',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
2019-08-31 04:07:25 +05:00
},
text: {
type: 'string',
required: true,
},
2019-08-31 04:07:25 +05:00
},
exits: {
2020-04-03 00:35:25 +05:00
cardNotFound: {
responseType: 'notFound',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
2019-08-31 04:07:25 +05:00
const { currentUser } = this.req;
const { card } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
2020-04-03 00:35:25 +05:00
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
2019-08-31 04:07:25 +05:00
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, card.boardId);
2019-08-31 04:07:25 +05:00
if (!isBoardMember) {
2019-08-31 04:07:25 +05:00
throw Errors.CARD_NOT_FOUND; // Forbidden
}
const values = {
type: Action.Types.COMMENT_CARD,
data: _.pick(inputs, ['text']),
2019-08-31 04:07:25 +05:00
};
const action = await sails.helpers.actions.createOne(values, currentUser, card, this.req);
2019-08-31 04:07:25 +05:00
return {
item: action,
};
},
2019-08-31 04:07:25 +05:00
};