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

111 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-12-26 21:10:50 +01:00
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
};
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',
2022-12-26 21:10:50 +01:00
custom: valuesValidator,
required: true,
2019-08-31 04:07:25 +05:00
},
project: {
type: 'ref',
required: true,
},
2019-08-31 04:07:25 +05:00
board: {
type: 'ref',
required: true,
2019-08-31 04:07:25 +05:00
},
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;
if (!_.isUndefined(values.position)) {
const tasks = await sails.helpers.cards.getTasks(inputs.record.cardId, inputs.record.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
2022-12-26 21:10:50 +01:00
values.position,
tasks,
);
2022-12-26 21:10:50 +01:00
values.position = position;
repositions.forEach(async ({ id, position: nextPosition }) => {
await Task.update({
id,
cardId: inputs.record.cardId,
}).set({
position: nextPosition,
});
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
item: {
id,
position: nextPosition,
},
});
// TODO: send webhooks
});
}
2022-12-26 21:10:50 +01:00
const task = await Task.updateOne(inputs.record.id).set({ ...values });
2019-08-31 04:07:25 +05:00
if (task) {
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'taskUpdate',
{
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: 'taskUpdate',
data: {
item: task,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [inputs.card],
},
},
user: inputs.actorUser,
});
2019-08-31 04:07:25 +05:00
}
return task;
},
2019-08-31 04:07:25 +05:00
};