1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/server/api/controllers/actions/index.js

66 lines
1.3 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: {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
2019-08-31 04:07:25 +05:00
},
beforeId: {
type: 'string',
regex: /^[0-9]+$/,
},
withDetails: {
type: 'boolean',
},
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.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) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
2019-08-31 04:07:25 +05:00
}
const actions = await sails.helpers.cards.getActions(
card.id,
inputs.beforeId,
inputs.withDetails,
);
2019-08-31 04:07:25 +05:00
const userIds = sails.helpers.utils.mapRecords(actions, 'userId', true);
const users = await sails.helpers.users.getMany(userIds, true);
2019-08-31 04:07:25 +05:00
return {
2019-08-31 04:07:25 +05:00
items: actions,
included: {
users,
},
};
},
2019-08-31 04:07:25 +05:00
};