2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
*/
|
2022-12-26 21:10:50 +01:00
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
values: {
|
|
|
|
type: 'json',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-06 20:22:14 +02:00
|
|
|
board: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2022-12-26 21:10:50 +01:00
|
|
|
const { values } = inputs;
|
|
|
|
|
|
|
|
if (!_.isUndefined(values.position)) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const lists = await sails.helpers.boards.getFiniteListsById(
|
|
|
|
inputs.board.id,
|
|
|
|
inputs.record.id,
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
2022-12-26 21:10:50 +01:00
|
|
|
values.position,
|
2019-11-05 18:01:42 +05:00
|
|
|
lists,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
values.position = position;
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
if (repositions.length > 0) {
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
for (const reposition of repositions) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await List.qm.updateOne(
|
|
|
|
{
|
|
|
|
id: reposition.record.id,
|
|
|
|
boardId: reposition.record.boardId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
position: reposition.position,
|
|
|
|
},
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
|
|
|
|
item: {
|
|
|
|
id: reposition.record.id,
|
|
|
|
position: reposition.position,
|
|
|
|
},
|
|
|
|
});
|
2024-06-12 00:51:36 +02:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
// TODO: send webhooks
|
|
|
|
}
|
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
2025-07-11 01:04:02 +02:00
|
|
|
const { list, tasks } = await List.qm.updateOne(inputs.record.id, values);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
if (list) {
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${list.boardId}`,
|
|
|
|
'listUpdate',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: list,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
2024-06-06 20:22:14 +02:00
|
|
|
|
2025-07-11 01:04:02 +02:00
|
|
|
if (tasks) {
|
|
|
|
const taskListIds = sails.helpers.utils.mapRecords(tasks, 'taskListId', true);
|
|
|
|
const taskLists = await TaskList.qm.getByIds(taskListIds);
|
|
|
|
const taskListById = _.keyBy(taskLists, 'id');
|
|
|
|
|
|
|
|
const cardIds = sails.helpers.utils.mapRecords(taskLists, 'cardId', true);
|
|
|
|
const cards = await Card.qm.getByIds(cardIds);
|
|
|
|
const cardById = _.keyBy(cards, 'id');
|
|
|
|
|
|
|
|
const boardIdByTaskId = tasks.reduce(
|
|
|
|
(result, task) => ({
|
|
|
|
...result,
|
|
|
|
[task.id]: cardById[taskListById[task.taskListId].cardId].boardId,
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
|
|
|
tasks.forEach((task) => {
|
|
|
|
sails.sockets.broadcast(`board:${boardIdByTaskId[task.id]}`, 'taskUpdate', {
|
|
|
|
item: task,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: send webhooks
|
|
|
|
}
|
|
|
|
|
2025-07-04 22:04:11 +02:00
|
|
|
const webhooks = await Webhook.qm.getAll();
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
2025-07-04 22:04:11 +02:00
|
|
|
webhooks,
|
|
|
|
event: Webhook.Events.LIST_UPDATE,
|
2025-05-10 02:09:06 +02:00
|
|
|
buildData: () => ({
|
2024-06-12 00:51:36 +02:00
|
|
|
item: list,
|
|
|
|
included: {
|
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
}),
|
|
|
|
buildPrevData: () => ({
|
2024-10-31 00:48:49 +01:00
|
|
|
item: inputs.record,
|
2025-05-10 02:09:06 +02:00
|
|
|
}),
|
2024-06-12 00:51:36 +02:00
|
|
|
user: inputs.actorUser,
|
2024-06-06 20:22:14 +02:00
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return list;
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|