2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
values: {
|
|
|
|
type: 'json',
|
2022-07-21 11:31:05 +02:00
|
|
|
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
card: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2022-07-21 11:31:05 +02:00
|
|
|
const tasks = await sails.helpers.cards.getTasks(inputs.card.id);
|
|
|
|
|
|
|
|
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
|
|
|
inputs.values.position,
|
|
|
|
tasks,
|
|
|
|
);
|
|
|
|
|
|
|
|
repositions.forEach(async ({ id, position: nextPosition }) => {
|
|
|
|
await Task.update({
|
|
|
|
id,
|
|
|
|
cardId: inputs.card.id,
|
|
|
|
}).set({
|
|
|
|
position: nextPosition,
|
|
|
|
});
|
|
|
|
|
|
|
|
sails.sockets.broadcast(`board:${inputs.card.boardId}`, 'taskUpdate', {
|
|
|
|
item: {
|
|
|
|
id,
|
|
|
|
position: nextPosition,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const task = await Task.create({
|
|
|
|
...inputs.values,
|
2022-07-21 11:31:05 +02:00
|
|
|
position,
|
2019-11-05 18:01:42 +05:00
|
|
|
cardId: inputs.card.id,
|
2019-08-31 04:07:25 +05:00
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${inputs.card.boardId}`,
|
|
|
|
'taskCreate',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: task,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return task;
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|