import Planka upstream
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await sails.helpers.lists.deleteRelated(inputs.record);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'listClear',
|
||||
{
|
||||
item: inputs.record,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_CLEAR,
|
||||
buildData: () => ({
|
||||
item: inputs.record,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const lists = await sails.helpers.boards.getKanbanListsById(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
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,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'listUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const list = await List.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.board.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listCreate',
|
||||
{
|
||||
item: list,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_CREATE,
|
||||
buildData: () => ({
|
||||
item: list,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [values.board],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
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);
|
||||
|
||||
if (list) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listDelete',
|
||||
{
|
||||
item: list,
|
||||
included: {
|
||||
cards,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
return { list, cards };
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let listIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: listIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
listIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
const cards = await Card.qm.delete({
|
||||
listId: listIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.cards.deleteRelated(cards);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const list = await List.qm.getOneById(inputs.id);
|
||||
|
||||
if (!list) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.boards
|
||||
.getPathToProjectById(list.boardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
list,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
list,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return [List.Types.ARCHIVE, List.Types.TRASH].includes(inputs.record.type);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return List.FINITE_TYPES.includes(inputs.record.type);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return List.KANBAN_TYPES.includes(inputs.record.type);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,117 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listInValuesMustBeEndless: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
// TODO: allow for finite lists?
|
||||
if (sails.helpers.lists.isFinite(values.list)) {
|
||||
throw 'listInValuesMustBeEndless';
|
||||
}
|
||||
|
||||
if (values.list.boardId !== inputs.board.id) {
|
||||
throw 'listInValuesMustBelongToBoard';
|
||||
}
|
||||
|
||||
if (inputs.record.type === List.Types.TRASH) {
|
||||
values.prevListId = null;
|
||||
} else if (sails.helpers.lists.isArchiveOrTrash(values.list)) {
|
||||
values.prevListId = inputs.record.id;
|
||||
} else if (inputs.record.type === List.Types.ARCHIVE) {
|
||||
values.prevListId = null;
|
||||
}
|
||||
|
||||
const { cards } = await Card.qm.update(
|
||||
{
|
||||
listId: inputs.record.id,
|
||||
},
|
||||
{
|
||||
...values,
|
||||
listId: values.list.id,
|
||||
position: null,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
},
|
||||
);
|
||||
|
||||
const actions = await Action.qm.create(
|
||||
cards.map((card) => ({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.record, ['id', 'type', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'type', 'name']),
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'cardsUpdate',
|
||||
{
|
||||
items: cards,
|
||||
included: {
|
||||
actions,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
cards.forEach((card) => {
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [values.list],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: create notifications
|
||||
|
||||
return { cards, actions };
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
t: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
if (inputs.record.name) {
|
||||
return inputs.record.name;
|
||||
}
|
||||
|
||||
const name = _.upperFirst(inputs.record.type);
|
||||
return inputs.t ? inputs.t(name) : name;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { POSITION_GAP } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
options: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
cannotBeSortedAsEndlessList: {},
|
||||
invalidFieldName: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { options } = inputs;
|
||||
|
||||
if (!sails.helpers.lists.isFinite(inputs.record)) {
|
||||
throw 'cannotBeSortedAsEndlessList';
|
||||
}
|
||||
|
||||
let cards = await Card.qm.getByListId(inputs.record.id);
|
||||
|
||||
switch (options.fieldName) {
|
||||
case List.SortFieldNames.NAME:
|
||||
cards.sort((card1, card2) => card1.name.localeCompare(card2.name));
|
||||
|
||||
break;
|
||||
case List.SortFieldNames.DUE_DATE:
|
||||
cards.sort((card1, card2) => {
|
||||
if (card1.dueDate === null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (card2.dueDate === null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return new Date(card1.dueDate) - new Date(card2.dueDate);
|
||||
});
|
||||
|
||||
break;
|
||||
case List.SortFieldNames.CREATED_AT:
|
||||
cards.sort((card1, card2) => new Date(card1.createdAt) - new Date(card2.createdAt));
|
||||
|
||||
break;
|
||||
default:
|
||||
throw 'invalidFieldName';
|
||||
}
|
||||
|
||||
if (options.order === List.SortOrders.DESC) {
|
||||
cards.reverse();
|
||||
}
|
||||
|
||||
cards = await Promise.all(
|
||||
cards.map(async (card, index) => {
|
||||
const { card: nextCard } = await Card.qm.updateOne(
|
||||
{
|
||||
id: card.id,
|
||||
listId: card.listId,
|
||||
},
|
||||
{
|
||||
position: POSITION_GAP * (index + 1),
|
||||
},
|
||||
);
|
||||
|
||||
return nextCard;
|
||||
}),
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'cardsUpdate',
|
||||
{
|
||||
items: cards,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
cards.forEach((card) => {
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.record],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
});
|
||||
|
||||
return cards;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,264 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
boardInValuesMustBelongToProject: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.project && values.project.id === inputs.project.id) {
|
||||
delete values.project;
|
||||
}
|
||||
|
||||
const project = values.project || inputs.project;
|
||||
|
||||
if (values.board) {
|
||||
if (values.board.projectId !== project.id) {
|
||||
throw 'boardInValuesMustBelongToProject';
|
||||
}
|
||||
|
||||
if (values.board.id === inputs.board.id) {
|
||||
delete values.board;
|
||||
} else {
|
||||
values.boardId = values.board.id;
|
||||
}
|
||||
}
|
||||
|
||||
const board = values.board || inputs.board;
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const lists = await sails.helpers.boards.getKanbanListsById(board.id, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
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,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${board.id}`, 'listUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let cardIdsByLabelId;
|
||||
let prevLabels;
|
||||
|
||||
if (values.board) {
|
||||
const cards = await Card.qm.getByListId(inputs.record.id);
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const cardLabels = await CardLabel.qm.getByCardIds(cardIds);
|
||||
|
||||
cardIdsByLabelId = cardLabels.reduce(
|
||||
(result, { cardId, labelId }) => ({
|
||||
...result,
|
||||
[labelId]: [...(result[labelId] || []), cardId],
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
prevLabels = await Label.qm.getByIds(Object.keys(cardIdsByLabelId));
|
||||
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: cardIds,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardMembership.qm.delete({
|
||||
cardId: cardIds,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
cardId: cardIds,
|
||||
});
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardIds(cardIds);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
await Task.qm.update(
|
||||
{
|
||||
taskListId: taskListIds,
|
||||
assigneeUserId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
},
|
||||
{
|
||||
assigneeUserId: null,
|
||||
},
|
||||
);
|
||||
|
||||
await sails.helpers.cards.detachCustomFields(cardIds, inputs.board.id, !!values.project);
|
||||
}
|
||||
|
||||
const { list, tasks } = await List.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (list) {
|
||||
if (values.board) {
|
||||
if (prevLabels.length > 0) {
|
||||
const labels = await Label.qm.getByBoardId(list.boardId);
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
const cardLabelsValues = (
|
||||
await Promise.all(
|
||||
prevLabels.map(async (label) => {
|
||||
let labelId;
|
||||
if (labelByName[label.name]) {
|
||||
({ id: labelId } = labelByName[label.name]);
|
||||
} else {
|
||||
({ id: labelId } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
}));
|
||||
}
|
||||
|
||||
return cardIdsByLabelId[label.id].map((cardId) => ({
|
||||
cardId,
|
||||
labelId,
|
||||
}));
|
||||
}),
|
||||
)
|
||||
).flat();
|
||||
|
||||
await CardLabel.qm.create(cardLabelsValues);
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'listUpdate',
|
||||
{
|
||||
item: {
|
||||
id: list.id,
|
||||
boardId: null,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${list.boardId}`, 'listUpdate', {
|
||||
item: list,
|
||||
});
|
||||
|
||||
// TODO: add transfer action
|
||||
} else {
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listUpdate',
|
||||
{
|
||||
item: list,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_UPDATE,
|
||||
buildData: () => ({
|
||||
item: list,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user