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
70
server/api/helpers/create-board.js
Normal file
70
server/api/helpers/create-board.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const boards = await sails.helpers.getBoardsForProject(inputs.project.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
inputs.values.position,
|
||||
boards
|
||||
);
|
||||
|
||||
const userIds = await sails.helpers.getMembershipUserIdsForProject(
|
||||
inputs.project.id
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.project.id
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const board = await Board.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
projectId: inputs.project.id
|
||||
}).fetch();
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardCreate',
|
||||
{
|
||||
item: board,
|
||||
included: {
|
||||
lists: [],
|
||||
labels: []
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
|
||||
return exits.success(board);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue