mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 05:39:43 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
52
server/api/controllers/tasks/create.js
Executable file
52
server/api/controllers/tasks/create.js
Executable file
|
@ -0,0 +1,52 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
isCompleted: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, 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 values = _.pick(inputs, ['name', 'isCompleted']);
|
||||
|
||||
const task = await sails.helpers.createTask(card, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: task
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue