mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,38 +1,18 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -45,50 +25,55 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
if (sails.helpers.lists.isFinite(values.list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (values.dueDate) {
|
||||
if (_.isNil(values.isDueDateCompleted)) {
|
||||
values.isDueDateCompleted = false;
|
||||
const cards = await Card.qm.getByListId(values.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
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 Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete values.isDueDateCompleted;
|
||||
delete values.position;
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(values.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: values.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${values.list.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
|
||||
const card = await Card.create({
|
||||
const card = await Card.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.list.boardId,
|
||||
boardId: values.board.id,
|
||||
listId: values.list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -101,22 +86,28 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
boards: [values.board],
|
||||
lists: [values.list],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
});
|
||||
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
|
@ -133,14 +124,13 @@ module.exports = {
|
|||
card,
|
||||
type: Action.Types.CREATE_CARD,
|
||||
data: {
|
||||
list: _.pick(values.list, ['id', 'name']),
|
||||
list: _.pick(values.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
board: values.board,
|
||||
list: values.list,
|
||||
request: inputs.request,
|
||||
});
|
||||
|
||||
return card;
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
const buildAndSendMarkdownMessage = async (card, actorUser, send) => {
|
||||
await send(`*${card.name}* was deleted by ${actorUser.name}`);
|
||||
};
|
||||
|
||||
const buildAndSendHtmlMessage = async (card, actorUser, send) => {
|
||||
await send(`<b>${card.name}</b> was deleted by ${actorUser.name}`);
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -34,7 +31,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const card = await Card.archiveOne(inputs.record.id);
|
||||
await sails.helpers.cards.deleteRelated(inputs.record);
|
||||
|
||||
const card = await Card.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (card) {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -48,32 +47,16 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
if (sails.config.custom.slackBotToken) {
|
||||
buildAndSendMarkdownMessage(card, inputs.actorUser, sails.helpers.utils.sendSlackMessage);
|
||||
}
|
||||
|
||||
if (sails.config.custom.googleChatWebhookUrl) {
|
||||
buildAndSendMarkdownMessage(
|
||||
card,
|
||||
inputs.actorUser,
|
||||
sails.helpers.utils.sendGoogleChatMessage,
|
||||
);
|
||||
}
|
||||
|
||||
if (sails.config.custom.telegramBotToken) {
|
||||
buildAndSendHtmlMessage(card, inputs.actorUser, sails.helpers.utils.sendTelegramMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return card;
|
||||
|
|
62
server/api/helpers/cards/delete-related.js
Normal file
62
server/api/helpers/cards/delete-related.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*!
|
||||
* 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 cardIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: cardIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
cardIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await CardMembership.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
const taskLists = await TaskList.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.taskLists.deleteRelated(taskLists);
|
||||
|
||||
const { fileReferences } = await Attachment.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
sails.helpers.attachments.removeUnreferencedFiles(fileReferences);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.customFieldGroups.deleteRelated(customFieldGroups);
|
||||
|
||||
await Comment.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await Action.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,18 +1,7 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -21,8 +10,7 @@ module.exports = {
|
|||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -37,74 +25,199 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
join: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
positionMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(inputs.record.listId);
|
||||
if (sails.helpers.lists.isFinite(inputs.list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
const cards = await Card.qm.getByListId(inputs.list.id);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: inputs.record.listId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
values.position = position;
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
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 Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
const card = await Card.create({
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let card = await Card.qm.createOne({
|
||||
..._.pick(inputs.record, [
|
||||
'boardId',
|
||||
'listId',
|
||||
'prevListId',
|
||||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'dueDate',
|
||||
'isDueDateCompleted',
|
||||
'stopwatch',
|
||||
]),
|
||||
...values,
|
||||
position,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const cardMemberships = await sails.helpers.cards.getCardMemberships(inputs.record.id);
|
||||
const cardMembershipsValues = cardMemberships.map((cardMembership) => ({
|
||||
..._.pick(cardMembership, ['userId']),
|
||||
cardId: card.id,
|
||||
}));
|
||||
const nextCardMemberships = await CardMembership.createEach(cardMembershipsValues).fetch();
|
||||
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(inputs.record.id);
|
||||
const nextCardMemberships = await CardMembership.qm.create(cardMembershipsValues);
|
||||
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const cardLabelsValues = cardLabels.map((cardLabel) => ({
|
||||
..._.pick(cardLabel, ['labelId']),
|
||||
cardId: card.id,
|
||||
}));
|
||||
const nextCardLabels = await CardLabel.createEach(cardLabelsValues).fetch();
|
||||
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.record.id);
|
||||
const tasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['position', 'name', 'isCompleted']),
|
||||
cardId: card.id,
|
||||
const nextCardLabels = await CardLabel.qm.create(cardLabelsValues);
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardId(inputs.record.id);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||
const attachments = await Attachment.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.id);
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(
|
||||
taskLists.length + attachments.length + customFieldGroups.length + customFields.length,
|
||||
);
|
||||
|
||||
const nextTaskListIdByTaskListId = {};
|
||||
const nextTaskListsValues = await taskLists.map((taskList) => {
|
||||
const id = ids.shift();
|
||||
nextTaskListIdByTaskListId[taskList.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(taskList, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
};
|
||||
});
|
||||
|
||||
const nextTaskLists = await TaskList.qm.create(nextTaskListsValues);
|
||||
|
||||
const nextTasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['assigneeUserId', 'position', 'name', 'isCompleted']),
|
||||
taskListId: nextTaskListIdByTaskListId[task.taskListId],
|
||||
}));
|
||||
const nextTasks = await Task.createEach(tasksValues).fetch();
|
||||
|
||||
const nextTasks = await Task.qm.create(nextTasksValues);
|
||||
|
||||
const nextAttachmentIdByAttachmentId = {};
|
||||
const nextAttachmentsValues = attachments.map((attachment) => {
|
||||
const id = ids.shift();
|
||||
nextAttachmentIdByAttachmentId[attachment.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(attachment, ['type', 'data', 'name']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
creatorUserId: card.creatorUserId,
|
||||
};
|
||||
});
|
||||
|
||||
const nextAttachments = await Attachment.qm.create(nextAttachmentsValues);
|
||||
|
||||
if (inputs.record.coverAttachmentId) {
|
||||
const nextCoverAttachmentId = nextAttachmentIdByAttachmentId[inputs.record.coverAttachmentId];
|
||||
|
||||
if (nextCoverAttachmentId) {
|
||||
card = await Card.qm.updateOne(card.id, {
|
||||
coverAttachmentId: nextCoverAttachmentId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = customFieldGroups.map((customFieldGroup) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customFieldGroup, ['baseCustomFieldGroupId', 'position', 'name']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFieldGroups = await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = customFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFields = await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const nextCustomFieldValuesValues = customFieldValues.map((customFieldValue) => ({
|
||||
..._.pick(customFieldValue, ['content']),
|
||||
cardId: card.id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId] ||
|
||||
customFieldValue.customFieldGroupId,
|
||||
customFieldId:
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId] ||
|
||||
customFieldValue.customFieldId,
|
||||
}));
|
||||
|
||||
const nextCustomFieldValues = await CustomFieldValue.qm.create(nextCustomFieldValuesValues);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -117,22 +230,36 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
taskLists: nextTaskLists,
|
||||
tasks: nextTasks,
|
||||
attachments: sails.helpers.attachments.presentMany(nextAttachments),
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
});
|
||||
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
|
@ -149,21 +276,25 @@ module.exports = {
|
|||
card,
|
||||
type: Action.Types.CREATE_CARD, // TODO: introduce separate type?
|
||||
data: {
|
||||
list: _.pick(inputs.list, ['id', 'name']),
|
||||
list: _.pick(inputs.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
request: inputs.request,
|
||||
});
|
||||
|
||||
return {
|
||||
card,
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
taskLists: nextTaskLists,
|
||||
tasks: nextTasks,
|
||||
attachments: nextAttachments,
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
const LIMIT = 50;
|
||||
|
||||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
beforeId: {
|
||||
type: 'string',
|
||||
},
|
||||
withDetails: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.beforeId)) {
|
||||
criteria.id = {
|
||||
'<': inputs.beforeId,
|
||||
};
|
||||
}
|
||||
|
||||
if (!inputs.withDetails) {
|
||||
criteria.type = Action.Types.COMMENT_CARD;
|
||||
}
|
||||
|
||||
return sails.helpers.actions.getMany(criteria, LIMIT);
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.attachments.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cardLabels.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cardMemberships.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptUserIdOrIds)) {
|
||||
criteria.userId = {
|
||||
'!=': inputs.exceptUserIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.cardSubscriptions.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(inputs.idOrIds);
|
||||
|
||||
return sails.helpers.utils.mapRecords(cardLabels, 'labelId', _.isArray(inputs.idOrIds));
|
||||
},
|
||||
};
|
|
@ -1,17 +1,20 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const labelIds = await sails.helpers.cards.getLabelIds(inputs.idOrIds);
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.id);
|
||||
const labelIds = sails.helpers.utils.mapRecords(cardLabels, 'labelId');
|
||||
|
||||
return sails.helpers.labels.getMany(labelIds);
|
||||
return Label.qm.getByIds(labelIds);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Card.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
39
server/api/helpers/cards/get-path-to-project-by-id.js
Normal file
39
server/api/helpers/cards/get-path-to-project-by-id.js
Normal file
|
@ -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 card = await Card.qm.getOneById(inputs.id);
|
||||
|
||||
if (!card) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.lists
|
||||
.getPathToProjectById(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
card,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const card = await Card.findOne(inputs.criteria);
|
||||
|
||||
if (!card) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers.lists
|
||||
.getProjectPath(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
card,
|
||||
...path,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,24 +1,24 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardSubscriptions = await sails.helpers.cards.getCardSubscriptions(
|
||||
inputs.idOrIds,
|
||||
inputs.exceptUserIdOrIds,
|
||||
);
|
||||
const cardSubscriptions = await CardSubscription.qm.getByCardId(inputs.id, {
|
||||
exceptUserIdOrIds: inputs.exceptUserIdOrIds,
|
||||
});
|
||||
|
||||
return sails.helpers.utils.mapRecords(cardSubscriptions, 'userId', _.isArray(inputs.idOrIds));
|
||||
return sails.helpers.utils.mapRecords(cardSubscriptions, 'userId');
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptTaskIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptTaskIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptTaskIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.tasks.getMany(criteria);
|
||||
},
|
||||
};
|
56
server/api/helpers/cards/read-notifications-for-user.js
Normal file
56
server/api/helpers/cards/read-notifications-for-user.js
Normal file
|
@ -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,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
// TODO: add actorUser as well?
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const notifications = await Notification.qm.update(
|
||||
{
|
||||
userId: inputs.user.id,
|
||||
cardId: inputs.record.id,
|
||||
isRead: false,
|
||||
},
|
||||
{
|
||||
isRead: true,
|
||||
},
|
||||
);
|
||||
|
||||
notifications.forEach((notification) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${notification.userId}`,
|
||||
'notificationUpdate',
|
||||
{
|
||||
item: notification,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationUpdate',
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
}),
|
||||
user: inputs.user,
|
||||
});
|
||||
});
|
||||
|
||||
return notifications;
|
||||
},
|
||||
};
|
|
@ -1,28 +1,9 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.board)) {
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.list) && !_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
const { POSITION_GAP } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -31,8 +12,7 @@ module.exports = {
|
|||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -61,8 +41,10 @@ module.exports = {
|
|||
boardInValuesMustBelongToProject: {},
|
||||
listMustBeInValues: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
coverAttachmentInValuesMustContainImage: {},
|
||||
},
|
||||
|
||||
// TODO: use normalizeValues and refactor
|
||||
async fn(inputs) {
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
|
@ -102,90 +84,314 @@ module.exports = {
|
|||
|
||||
const list = values.list || inputs.list;
|
||||
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const cards = await sails.helpers.lists.getCards(list.id, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
}
|
||||
|
||||
const dueDate = _.isUndefined(values.dueDate) ? inputs.record.dueDate : values.dueDate;
|
||||
|
||||
if (dueDate) {
|
||||
const isDueDateCompleted = _.isUndefined(values.isDueDateCompleted)
|
||||
? inputs.record.isDueDateCompleted
|
||||
: values.isDueDateCompleted;
|
||||
|
||||
if (_.isNull(isDueDateCompleted)) {
|
||||
values.isDueDateCompleted = false;
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
} else {
|
||||
values.isDueDateCompleted = null;
|
||||
values.position = null;
|
||||
}
|
||||
|
||||
if (values.coverAttachment) {
|
||||
if (!values.coverAttachment.data.image) {
|
||||
throw 'coverAttachmentInValuesMustContainImage';
|
||||
}
|
||||
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
}
|
||||
|
||||
let card;
|
||||
if (_.isEmpty(values)) {
|
||||
card = inputs.record;
|
||||
} else {
|
||||
let prevLabels;
|
||||
if (values.board) {
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
if (!_.isNil(values.position)) {
|
||||
const cards = await Card.qm.getByListId(list.id, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
values.position = position;
|
||||
|
||||
await CardLabel.destroy({
|
||||
cardId: inputs.record.id,
|
||||
});
|
||||
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 Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
card = await Card.updateOne(inputs.record.id).set({ ...values });
|
||||
let prevLabels;
|
||||
if (values.board) {
|
||||
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardMembership.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
});
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardId(inputs.record.id);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
await Task.qm.update(
|
||||
{
|
||||
taskListId: taskListIds,
|
||||
assigneeUserId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
},
|
||||
{
|
||||
assigneeUserId: null,
|
||||
},
|
||||
);
|
||||
|
||||
const boardCustomFieldGroups = await CustomFieldGroup.qm.getByBoardId(inputs.board.id);
|
||||
const boardCustomFieldGroupIds = sails.helpers.utils.mapRecords(boardCustomFieldGroups);
|
||||
|
||||
const boardCustomFields =
|
||||
await CustomField.qm.getByCustomFieldGroupIds(boardCustomFieldGroupIds);
|
||||
|
||||
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.id);
|
||||
|
||||
let basedCardCustomFieldGroups;
|
||||
let basedCustomFieldGroups;
|
||||
let baseCustomFieldGroupById;
|
||||
let customFieldsByBaseCustomFieldGroupId;
|
||||
|
||||
if (values.project) {
|
||||
const basedBoardCustomFieldGroups = boardCustomFieldGroups.filter(
|
||||
({ baseCustomFieldGroupId }) => baseCustomFieldGroupId,
|
||||
);
|
||||
|
||||
basedCardCustomFieldGroups = cardCustomFieldGroups.filter(
|
||||
({ baseCustomFieldGroupId }) => baseCustomFieldGroupId,
|
||||
);
|
||||
|
||||
basedCustomFieldGroups = [...basedBoardCustomFieldGroups, ...basedCardCustomFieldGroups];
|
||||
|
||||
const baseCustomFieldGroupIds = sails.helpers.utils.mapRecords(
|
||||
basedCustomFieldGroups,
|
||||
'baseCustomFieldGroupId',
|
||||
true,
|
||||
);
|
||||
|
||||
const baseCustomFieldGroups =
|
||||
await BaseCustomFieldGroup.qm.getByIds(baseCustomFieldGroupIds);
|
||||
|
||||
baseCustomFieldGroupById = _.keyBy(baseCustomFieldGroups, 'id');
|
||||
|
||||
const baseCustomFields = await CustomField.qm.getByBaseCustomFieldGroupIds(
|
||||
Object.keys(baseCustomFieldGroupById),
|
||||
);
|
||||
|
||||
customFieldsByBaseCustomFieldGroupId = _.groupBy(
|
||||
baseCustomFields,
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
}
|
||||
|
||||
let idsTotal = boardCustomFieldGroups.length + boardCustomFields.length;
|
||||
|
||||
if (values.project) {
|
||||
idsTotal += basedCustomFieldGroups.reduce((result, customFieldGroup) => {
|
||||
const customFieldsItem =
|
||||
customFieldsByBaseCustomFieldGroupId[customFieldGroup.baseCustomFieldGroupId];
|
||||
|
||||
return result + (customFieldsItem ? customFieldsItem.length : 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(idsTotal);
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = boardCustomFieldGroups.map(
|
||||
(customFieldGroup, index) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
const nextValues = {
|
||||
..._.pick(customFieldGroup, ['baseCustomFieldGroupId', 'name']),
|
||||
id,
|
||||
cardId: inputs.record.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
};
|
||||
|
||||
if (values.project && customFieldGroup.baseCustomFieldGroupId) {
|
||||
nextValues.baseCustomFieldGroupId = null;
|
||||
|
||||
if (!customFieldGroup.name) {
|
||||
nextValues.name =
|
||||
baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name;
|
||||
}
|
||||
}
|
||||
|
||||
return nextValues;
|
||||
},
|
||||
);
|
||||
|
||||
if (nextCustomFieldGroupsValues.length > 0) {
|
||||
const { position } = nextCustomFieldGroupsValues[nextCustomFieldGroupsValues.length - 1];
|
||||
|
||||
await Promise.all(
|
||||
cardCustomFieldGroups.map((customFieldGroup) =>
|
||||
CustomFieldGroup.qm.updateOne(customFieldGroup.id, {
|
||||
position: customFieldGroup.position + position,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
if (values.project) {
|
||||
await CustomFieldGroup.qm.update(
|
||||
{
|
||||
cardId: inputs.record.id,
|
||||
baseCustomFieldGroupId: {
|
||||
'!=': null,
|
||||
},
|
||||
},
|
||||
{
|
||||
baseCustomFieldGroupId: null,
|
||||
},
|
||||
);
|
||||
|
||||
const unnamedCustomFieldGroups = basedCardCustomFieldGroups.filter(({ name }) => !name);
|
||||
|
||||
await Promise.all(
|
||||
unnamedCustomFieldGroups.map((customFieldGroup) =>
|
||||
CustomFieldGroup.qm.updateOne(customFieldGroup.id, {
|
||||
name: baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = boardCustomFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
if (values.project) {
|
||||
basedCustomFieldGroups.forEach((customFieldGroup) => {
|
||||
const customFieldsItem =
|
||||
customFieldsByBaseCustomFieldGroupId[customFieldGroup.baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[`${customFieldGroup.id}:${customField.id}`] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] ||
|
||||
customFieldGroup.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const customFieldGroupIds = boardCustomFieldGroupIds;
|
||||
if (values.project) {
|
||||
customFieldGroupIds.push(...sails.helpers.utils.mapRecords(basedCardCustomFieldGroups));
|
||||
}
|
||||
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.record.id, {
|
||||
customFieldGroupIdOrIds: customFieldGroupIds,
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
customFieldValues.map((customFieldValue) => {
|
||||
const updateValues = {
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId],
|
||||
};
|
||||
|
||||
const nextCustomFieldId =
|
||||
nextCustomFieldIdByCustomFieldId[
|
||||
`${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`
|
||||
] || nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
|
||||
if (nextCustomFieldId) {
|
||||
updateValues.customFieldId = nextCustomFieldId;
|
||||
}
|
||||
|
||||
return CustomFieldValue.qm.updateOne(customFieldValue.id, updateValues);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (values.list) {
|
||||
values.listChangedAt = new Date().toISOString();
|
||||
|
||||
if (values.board || inputs.list.type === List.Types.TRASH) {
|
||||
values.prevListId = null;
|
||||
} else if (sails.helpers.lists.isArchiveOrTrash(values.list)) {
|
||||
values.prevListId = inputs.list.id;
|
||||
} else if (inputs.list.type === List.Types.ARCHIVE) {
|
||||
values.prevListId = null;
|
||||
}
|
||||
}
|
||||
|
||||
card = await Card.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (!card) {
|
||||
return card;
|
||||
}
|
||||
|
||||
if (values.board) {
|
||||
const labels = await sails.helpers.boards.getLabels(card.boardId);
|
||||
const labels = await Label.qm.getByBoardId(card.boardId);
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
const labelIds = await Promise.all(
|
||||
|
@ -197,8 +403,8 @@ module.exports = {
|
|||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId']),
|
||||
board: values.board,
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
|
@ -208,21 +414,30 @@ module.exports = {
|
|||
);
|
||||
|
||||
await Promise.all(
|
||||
labelIds.map(async (labelId) =>
|
||||
CardLabel.create({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
})
|
||||
.tolerate('E_UNIQUE')
|
||||
.fetch(),
|
||||
),
|
||||
labelIds.map((labelId) => {
|
||||
try {
|
||||
return CardLabel.qm.createOne({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}),
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.record.boardId}`,
|
||||
'cardDelete', // TODO: introduce separate event
|
||||
`board:${inputs.board.id}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: inputs.record,
|
||||
item: {
|
||||
id: card.id,
|
||||
boardId: null,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
@ -231,18 +446,7 @@ module.exports = {
|
|||
item: card,
|
||||
});
|
||||
|
||||
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(card.id);
|
||||
|
||||
subscriptionUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: card.id,
|
||||
isSubscribed: true,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
// TODO: add transfer action
|
||||
} else {
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -252,59 +456,67 @@ module.exports = {
|
|||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
if (values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'type', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: inputs.actorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: values.list,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardUpdate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [project],
|
||||
boards: [board],
|
||||
lists: [list],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
if (!values.board && values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
values: {
|
||||
card,
|
||||
user: inputs.actorUser,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
},
|
||||
request: inputs.request,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: add transfer action
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const prevIsSubscribed = await sails.helpers.users.isCardSubscriber(
|
||||
const wasSubscribed = await sails.helpers.users.isCardSubscriber(
|
||||
inputs.actorUser.id,
|
||||
card.id,
|
||||
);
|
||||
|
||||
if (isSubscribed !== prevIsSubscribed) {
|
||||
if (isSubscribed !== wasSubscribed) {
|
||||
if (isSubscribed) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await CardSubscription.destroyOne({
|
||||
await CardSubscription.qm.deleteOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue