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/labels/update-one.js

106 lines
2.3 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
2023-01-09 12:17:06 +01:00
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',
required: true,
2019-08-31 04:07:25 +05:00
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
2019-08-31 04:07:25 +05:00
request: {
type: 'ref',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
2022-12-26 21:10:50 +01:00
const { values } = inputs;
2023-01-09 12:17:06 +01:00
if (!_.isUndefined(values.position)) {
const labels = await Label.qm.getByBoardId(inputs.record.boardId, {
exceptIdOrIds: inputs.record.id,
});
2023-01-09 12:17:06 +01:00
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
labels,
);
values.position = position;
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await Label.qm.updateOne(
{
id: reposition.record.id,
boardId: reposition.record.boardId,
},
{
position: reposition.position,
},
);
2023-01-09 12:17:06 +01:00
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'labelUpdate', {
item: {
id: reposition.record.id,
position: reposition.position,
2023-01-09 12:17:06 +01:00
},
});
// TODO: send webhooks
}
2023-01-09 12:17:06 +01:00
}
const label = await Label.qm.updateOne(inputs.record.id, values);
2019-08-31 04:07:25 +05:00
if (label) {
sails.sockets.broadcast(
`board:${label.boardId}`,
'labelUpdate',
{
item: label,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05:00
);
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.LABEL_UPDATE,
buildData: () => ({
item: label,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
}),
buildPrevData: () => ({
item: inputs.record,
}),
user: inputs.actorUser,
});
2019-08-31 04:07:25 +05:00
}
return label;
},
2019-08-31 04:07:25 +05:00
};