mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
|
module.exports = {
|
||
|
inputs: {
|
||
|
list: {
|
||
|
type: 'ref',
|
||
|
required: true
|
||
|
},
|
||
|
values: {
|
||
|
type: 'json',
|
||
|
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
|
||
|
required: true
|
||
|
},
|
||
|
user: {
|
||
|
type: 'ref',
|
||
|
required: true
|
||
|
},
|
||
|
request: {
|
||
|
type: 'ref'
|
||
|
}
|
||
|
},
|
||
|
|
||
|
fn: async function(inputs, exits) {
|
||
|
const cards = await sails.helpers.getCardsForList(inputs.list.id);
|
||
|
|
||
|
const { position, repositions } = sails.helpers.insertToPositionables(
|
||
|
inputs.values.position,
|
||
|
cards
|
||
|
);
|
||
|
|
||
|
repositions.forEach(async ({ id, position }) => {
|
||
|
await Card.update({
|
||
|
id,
|
||
|
listId: inputs.list.id
|
||
|
}).set({
|
||
|
position
|
||
|
});
|
||
|
|
||
|
sails.sockets.broadcast(`board:${list.boardId}`, 'cardUpdate', {
|
||
|
item: {
|
||
|
id,
|
||
|
position
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
const card = await Card.create({
|
||
|
...inputs.values,
|
||
|
position,
|
||
|
listId: inputs.list.id,
|
||
|
boardId: inputs.list.boardId
|
||
|
}).fetch();
|
||
|
|
||
|
sails.sockets.broadcast(
|
||
|
`board:${card.boardId}`,
|
||
|
'cardCreate',
|
||
|
{
|
||
|
item: card
|
||
|
},
|
||
|
inputs.request
|
||
|
);
|
||
|
|
||
|
const values = {
|
||
|
type: 'createCard',
|
||
|
data: {
|
||
|
list: _.pick(inputs.list, ['id', 'name'])
|
||
|
}
|
||
|
};
|
||
|
|
||
|
await sails.helpers.createAction(card, inputs.user, values);
|
||
|
|
||
|
return exits.success(card);
|
||
|
}
|
||
|
};
|