2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
PROJECT_NOT_FOUND: {
|
2020-04-03 00:35:25 +05:00
|
|
|
projectNotFound: 'Project not found',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
projectId: {
|
2019-10-10 02:51:54 +05:00
|
|
|
type: 'string',
|
|
|
|
regex: /^[0-9]+$/,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
position: {
|
|
|
|
type: 'number',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
projectNotFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2020-04-24 21:44:54 +05:00
|
|
|
// TODO: allow over HTTP without subscription
|
|
|
|
if (!this.req.isSocket) {
|
|
|
|
return this.res.badRequest();
|
|
|
|
}
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const project = await Project.findOne(inputs.projectId);
|
|
|
|
|
|
|
|
if (!project) {
|
|
|
|
throw Errors.PROJECT_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
const values = _.pick(inputs, ['position', 'name']);
|
|
|
|
|
|
|
|
const board = await sails.helpers.createBoard(project, values, this.req);
|
|
|
|
|
2020-04-24 21:44:54 +05:00
|
|
|
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
return exits.success({
|
|
|
|
item: board,
|
|
|
|
included: {
|
|
|
|
lists: [],
|
2019-11-05 18:01:42 +05:00
|
|
|
labels: [],
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|