mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 21:29:43 +02:00
70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
|
module.exports = {
|
||
|
inputs: {
|
||
|
record: {
|
||
|
type: 'ref',
|
||
|
required: true
|
||
|
},
|
||
|
values: {
|
||
|
type: 'json',
|
||
|
custom: value =>
|
||
|
_.isPlainObject(value) &&
|
||
|
(_.isUndefined(value.position) || _.isFinite(value.position)),
|
||
|
required: true
|
||
|
},
|
||
|
request: {
|
||
|
type: 'ref'
|
||
|
}
|
||
|
},
|
||
|
|
||
|
fn: async function(inputs, exits) {
|
||
|
if (!_.isUndefined(inputs.values.position)) {
|
||
|
const lists = await sails.helpers.getListsForBoard(
|
||
|
inputs.record.boardId,
|
||
|
inputs.record.id
|
||
|
);
|
||
|
|
||
|
const { position, repositions } = sails.helpers.insertToPositionables(
|
||
|
inputs.values.position,
|
||
|
lists
|
||
|
);
|
||
|
|
||
|
inputs.values.position = position;
|
||
|
|
||
|
repositions.forEach(async ({ id, position }) => {
|
||
|
await List.update({
|
||
|
id,
|
||
|
boardId: inputs.record.boardId
|
||
|
}).set({
|
||
|
position
|
||
|
});
|
||
|
|
||
|
sails.sockets.broadcast(
|
||
|
`board:${inputs.record.boardId}`,
|
||
|
'listUpdate',
|
||
|
{
|
||
|
item: {
|
||
|
id,
|
||
|
position
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const list = await List.updateOne(inputs.record.id).set(inputs.values);
|
||
|
|
||
|
if (list) {
|
||
|
sails.sockets.broadcast(
|
||
|
`board:${list.boardId}`,
|
||
|
'listUpdate',
|
||
|
{
|
||
|
item: list
|
||
|
},
|
||
|
inputs.request
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return exits.success(list);
|
||
|
}
|
||
|
};
|