1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/helpers/update-list.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
2019-08-31 04:07:25 +05:00
},
values: {
type: 'json',
// eslint-disable-next-line max-len
custom: (value) => _.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
2019-08-31 04:07:25 +05:00
},
request: {
type: 'ref',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs, exits) {
2019-08-31 04:07:25 +05:00
if (!_.isUndefined(inputs.values.position)) {
const lists = await sails.helpers.getListsForBoard(inputs.record.boardId, inputs.record.id);
2019-08-31 04:07:25 +05:00
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
lists,
2019-08-31 04:07:25 +05:00
);
inputs.values.position = position;
repositions.forEach(async ({ id, position: nextPosition }) => {
2019-08-31 04:07:25 +05:00
await List.update({
id,
boardId: inputs.record.boardId,
2019-08-31 04:07:25 +05:00
}).set({
position: nextPosition,
2019-08-31 04:07:25 +05:00
});
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'listUpdate', {
item: {
id,
position: nextPosition,
},
});
2019-08-31 04:07:25 +05:00
});
}
const list = await List.updateOne(inputs.record.id).set(inputs.values);
if (list) {
sails.sockets.broadcast(
`board:${list.boardId}`,
'listUpdate',
{
item: list,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05:00
);
}
return exits.success(list);
},
2019-08-31 04:07:25 +05:00
};