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

57 lines
1.1 KiB
JavaScript
Executable file

const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
};
module.exports = {
inputs: {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
},
beforeId: {
type: 'string',
regex: /^[0-9]+$/
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
fn: async function(inputs, exits) {
const { currentUser } = this.req;
const { project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
const actions = await sails.helpers.getActionsForCard(
inputs.cardId,
inputs.beforeId
);
const userIds = sails.helpers.mapRecords(actions, 'userId', true);
const users = await sails.helpers.getUsers(userIds);
return exits.success({
items: actions,
included: {
users
}
});
}
};