1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 21:29:43 +02:00
planka/server/api/helpers/lists/delete-one.js

79 lines
1.5 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
*/
2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
record: {
type: 'ref',
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) {
const trashList = await List.qm.getOneTrashByBoardId(inputs.board.id);
const { cards } = await Card.qm.update(
{
listId: inputs.record.id,
},
{
listId: trashList.id,
position: null,
listChangedAt: new Date().toISOString(),
},
);
// TODO: create actions and notifications
const list = await List.qm.deleteOne(inputs.record.id);
2019-08-31 04:07:25 +05:00
if (list) {
2019-08-31 04:07:25 +05:00
sails.sockets.broadcast(
`board:${list.boardId}`,
'listDelete',
2019-08-31 04:07:25 +05:00
{
item: list,
included: {
cards,
},
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.LIST_DELETE,
buildData: () => ({
item: list,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
}),
user: inputs.actorUser,
});
2019-08-31 04:07:25 +05:00
}
return { list, cards };
},
2019-08-31 04:07:25 +05:00
};