1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/create-list.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
board: {
type: 'ref',
required: true,
2019-08-31 04:07:25 +05:00
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.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
const lists = await sails.helpers.getListsForBoard(inputs.board.id);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
lists,
2019-08-31 04:07:25 +05:00
);
repositions.forEach(async ({ id, position: nextPosition }) => {
2019-08-31 04:07:25 +05:00
await List.update({
id,
boardId: inputs.board.id,
2019-08-31 04:07:25 +05:00
}).set({
position: nextPosition,
2019-08-31 04:07:25 +05:00
});
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
item: {
id,
position: nextPosition,
},
2019-08-31 04:07:25 +05:00
});
});
const list = await List.create({
...inputs.values,
position,
boardId: inputs.board.id,
2019-08-31 04:07:25 +05:00
}).fetch();
sails.sockets.broadcast(
`board:${list.boardId}`,
'listCreate',
{
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
};