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/cards/show.js

60 lines
1.4 KiB
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: {
id: {
type: 'string',
regex: /^[0-9]+$/,
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, project } = await sails.helpers.cards
.getProjectPath(inputs.id)
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) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
2019-08-31 04:07:25 +05:00
}
card.isSubscribed = await sails.helpers.users.isCardSubscriber(currentUser.id, card.id);
const cardMemberships = await sails.helpers.cards.getCardMemberships(card.id);
const cardLabels = await sails.helpers.cards.getCardLabels(card.id);
const tasks = await sails.helpers.cards.getTasks(card.id);
const attachments = await sails.helpers.cards.getAttachments(card.id);
return {
item: card,
included: {
cardMemberships,
cardLabels,
tasks,
attachments,
},
};
},
2019-08-31 04:07:25 +05:00
};