1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/helpers/tasks/create-one.js

103 lines
2.1 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
*/
2022-12-26 21:10:50 +01:00
2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
values: {
type: 'json',
required: true,
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
list: {
type: 'ref',
required: true,
},
card: {
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;
const tasks = await Task.qm.getByTaskListId(values.taskList.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
2022-12-26 21:10:50 +01:00
values.position,
tasks,
);
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await Task.qm.updateOne(
{
id: reposition.record.id,
taskListId: reposition.record.taskListId,
},
{
position: reposition.position,
},
);
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
item: {
id: reposition.record.id,
position: reposition.position,
},
});
// TODO: send webhooks
}
const task = await Task.qm.createOne({
2022-12-26 21:10:50 +01:00
...values,
position,
taskListId: values.taskList.id,
});
2019-08-31 04:07:25 +05:00
sails.sockets.broadcast(
`board:${inputs.board.id}`,
2019-08-31 04:07:25 +05:00
'taskCreate',
{
item: task,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05:00
);
sails.helpers.utils.sendWebhooks.with({
event: 'taskCreate',
buildData: () => ({
item: task,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [inputs.card],
taskLists: [values.taskList],
},
}),
user: inputs.actorUser,
});
return task;
},
2019-08-31 04:07:25 +05:00
};