mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue