mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
84
server/api/controllers/cards/create.js
Executable file
84
server/api/controllers/cards/create.js
Executable file
|
@ -0,0 +1,84 @@
|
|||
const moment = require('moment');
|
||||
|
||||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
notFound: 'List is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
listId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
allowNull: true
|
||||
},
|
||||
deadline: {
|
||||
type: 'string',
|
||||
custom: value => moment(value, moment.ISO_8601, true).isValid()
|
||||
},
|
||||
timer: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
_.size(value) === 2 &&
|
||||
(_.isNull(value.startedAt) ||
|
||||
moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
|
||||
_.isFinite(value.total)
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, project } = await sails.helpers
|
||||
.getListToProjectPath(inputs.listId)
|
||||
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, [
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'deadline',
|
||||
'timer'
|
||||
]);
|
||||
|
||||
const card = await sails.helpers.createCard(
|
||||
list,
|
||||
values,
|
||||
currentUser,
|
||||
this.req
|
||||
);
|
||||
|
||||
return exits.success({
|
||||
item: card
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue