mirror of
https://github.com/plankanban/planka.git
synced 2025-07-22 06:39:44 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
73
server/api/helpers/update-board.js
Normal file
73
server/api/helpers/update-board.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
(_.isUndefined(value.position) || _.isFinite(value.position)),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const userIds = await sails.helpers.getMembershipUserIdsForProject(
|
||||
inputs.record.projectId
|
||||
);
|
||||
|
||||
if (!_.isUndefined(inputs.values.position)) {
|
||||
const boards = await sails.helpers.getBoardsForProject(
|
||||
inputs.record.projectId,
|
||||
inputs.record.id
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
inputs.values.position,
|
||||
boards
|
||||
);
|
||||
|
||||
inputs.values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.record.projectId
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const board = await Board.updateOne(inputs.record.id).set(inputs.values);
|
||||
|
||||
if (board) {
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardUpdate',
|
||||
{
|
||||
item: board
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return exits.success(board);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue