mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 21:59:43 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
72
server/api/helpers/create-card.js
Normal file
72
server/api/helpers/create-card.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
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);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue