mirror of
https://github.com/plankanban/planka.git
synced 2025-07-21 22:29:42 +02:00
Project managers, board members, auto-update after reconnection, refactoring
This commit is contained in:
parent
d6cb1f6683
commit
b39119ace4
478 changed files with 21226 additions and 19495 deletions
78
server/api/helpers/boards/create-one.js
Normal file
78
server/api/helpers/boards/create-one.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.project.id);
|
||||
const boards = await sails.helpers.projects.getBoards(inputs.project.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.project.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
const memberUserIds = await sails.helpers.boards.getMemberUserIds(id);
|
||||
const userIds = _.union(managerUserIds, memberUserIds);
|
||||
|
||||
userIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const board = await Board.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
projectId: inputs.project.id,
|
||||
}).fetch();
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
boardId: board.id,
|
||||
userId: inputs.user.id,
|
||||
}).fetch();
|
||||
|
||||
managerUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardCreate',
|
||||
{
|
||||
item: board,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
board,
|
||||
boardMembership,
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue