mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
module.exports = {
|
|
inputs: {
|
|
record: {
|
|
type: 'ref',
|
|
required: true,
|
|
},
|
|
values: {
|
|
type: 'json',
|
|
custom: (value) => {
|
|
if (!_.isPlainObject(value)) {
|
|
return false;
|
|
}
|
|
|
|
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
},
|
|
required: true,
|
|
},
|
|
board: {
|
|
type: 'ref',
|
|
required: true,
|
|
},
|
|
request: {
|
|
type: 'ref',
|
|
},
|
|
},
|
|
|
|
async fn(inputs) {
|
|
if (!_.isUndefined(inputs.values.position)) {
|
|
const tasks = await sails.helpers.cards.getTasks(inputs.record.cardId, inputs.record.id);
|
|
|
|
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
|
inputs.values.position,
|
|
tasks,
|
|
);
|
|
|
|
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
|
|
|
repositions.forEach(async ({ id, position: nextPosition }) => {
|
|
await Task.update({
|
|
id,
|
|
cardId: inputs.record.cardId,
|
|
}).set({
|
|
position: nextPosition,
|
|
});
|
|
|
|
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
|
|
item: {
|
|
id,
|
|
position: nextPosition,
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
const task = await Task.updateOne(inputs.record.id).set(inputs.values);
|
|
|
|
if (task) {
|
|
sails.sockets.broadcast(
|
|
`board:${inputs.board.id}`,
|
|
'taskUpdate',
|
|
{
|
|
item: task,
|
|
},
|
|
inputs.request,
|
|
);
|
|
}
|
|
|
|
return task;
|
|
},
|
|
};
|