1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/update-board.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
2019-08-31 04:07:25 +05:00
},
values: {
type: 'json',
custom: (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
},
required: true,
2019-08-31 04:07:25 +05:00
},
request: {
type: 'ref',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs, exits) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(inputs.record.projectId);
2019-08-31 04:07:25 +05:00
if (!_.isUndefined(inputs.values.position)) {
const boards = await sails.helpers.getBoardsForProject(
inputs.record.projectId,
inputs.record.id,
2019-08-31 04:07:25 +05:00
);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
boards,
2019-08-31 04:07:25 +05:00
);
inputs.values.position = position; // eslint-disable-line no-param-reassign
2019-08-31 04:07:25 +05:00
repositions.forEach(async ({ id, position: nextPosition }) => {
2019-08-31 04:07:25 +05:00
await Board.update({
id,
projectId: inputs.record.projectId,
2019-08-31 04:07:25 +05:00
}).set({
position: nextPosition,
2019-08-31 04:07:25 +05:00
});
2020-04-03 00:35:25 +05:00
userIds.forEach((userId) => {
2019-08-31 04:07:25 +05:00
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
position: nextPosition,
},
2019-08-31 04:07:25 +05:00
});
});
});
}
const board = await Board.updateOne(inputs.record.id).set(inputs.values);
if (board) {
2020-04-03 00:35:25 +05:00
userIds.forEach((userId) => {
2019-08-31 04:07:25 +05:00
sails.sockets.broadcast(
`user:${userId}`,
'boardUpdate',
{
item: board,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05:00
);
});
}
return exits.success(board);
},
2019-08-31 04:07:25 +05:00
};