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

58 lines
1.2 KiB
JavaScript
Executable file

const Errors = {
CARD_NOT_FOUND: {
cardNotFound: 'Card not found',
},
};
module.exports = {
inputs: {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
beforeId: {
type: 'string',
regex: /^[0-9]+$/,
},
},
exits: {
cardNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers.cards
.getProjectPath(inputs.cardId)
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, card.boardId);
if (!isBoardMember) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
}
const actions = await sails.helpers.cards.getActions(card.id, inputs.beforeId);
const userIds = sails.helpers.utils.mapRecords(actions, 'userId', true);
const users = await sails.helpers.users.getMany(userIds, true);
return {
items: actions,
included: {
users,
},
};
},
};