mirror of
https://github.com/plankanban/planka.git
synced 2025-12-17 17:23:25 +03:00
Initial commit
This commit is contained in:
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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user