mirror of
https://github.com/plankanban/planka.git
synced 2025-12-26 01:11:58 +03:00
feat: Add ability to copy/cut cards with shortcut support
This commit is contained in:
@@ -26,18 +26,25 @@
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - position
|
||||
* - name
|
||||
* properties:
|
||||
* boardId:
|
||||
* type: string
|
||||
* description: ID of the board to duplicate the card to
|
||||
* example: "1357158568008091265"
|
||||
* listId:
|
||||
* type: string
|
||||
* description: ID of the list to duplicate the card to
|
||||
* example: "1357158568008091266"
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* nullable: true
|
||||
* description: Position for the duplicated card within the list
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 1024
|
||||
* nullable: true
|
||||
* description: Name/title for the duplicated card
|
||||
* example: Implement user authentication (copy)
|
||||
* responses:
|
||||
@@ -113,6 +120,8 @@
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* $ref: '#/components/responses/UnprocessableEntity'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
@@ -124,6 +133,18 @@ const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
LIST_MUST_BE_PRESENT: {
|
||||
listMustBePresent: 'List must be present',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@@ -132,15 +153,17 @@ module.exports = {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
boardId: idInput,
|
||||
listId: idInput,
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
required: true,
|
||||
allowNull: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 1024,
|
||||
required: true,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -151,6 +174,18 @@ module.exports = {
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
@@ -160,24 +195,60 @@ module.exports = {
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
if (!isProjectManager) {
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: allow for endless lists?
|
||||
if (!sails.helpers.lists.isFinite(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
let nextProject;
|
||||
let nextBoard;
|
||||
|
||||
if (!_.isUndefined(inputs.boardId)) {
|
||||
({ board: nextBoard, project: nextProject } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND));
|
||||
|
||||
boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
nextBoard.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let nextList;
|
||||
if (!_.isUndefined(inputs.listId)) {
|
||||
nextList = await List.qm.getOneById(inputs.listId, {
|
||||
boardId: (nextBoard || board).id,
|
||||
});
|
||||
|
||||
if (!nextList) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const {
|
||||
@@ -190,17 +261,23 @@ module.exports = {
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
} = await sails.helpers.cards.duplicateOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
} = await sails.helpers.cards.duplicateOne
|
||||
.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
project: nextProject,
|
||||
board: nextBoard,
|
||||
list: nextList,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)
|
||||
.intercept('listMustBeInValues', () => Errors.LIST_MUST_BE_PRESENT);
|
||||
|
||||
return {
|
||||
item: nextCard,
|
||||
|
||||
185
server/api/helpers/cards/copy-custom-fields.js
Normal file
185
server/api/helpers/cards/copy-custom-fields.js
Normal file
@@ -0,0 +1,185 @@
|
||||
/*!
|
||||
* 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: {
|
||||
fromRecord: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
toRecord: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
detachBoardCustomFieldGroups: {
|
||||
type: 'boolean',
|
||||
defaultsTo: true,
|
||||
},
|
||||
detachBaseCustomFieldGroups: {
|
||||
type: 'boolean',
|
||||
defaultsTo: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardCustomFieldGroups = inputs.detachBoardCustomFieldGroups
|
||||
? await CustomFieldGroup.qm.getByBoardId(inputs.fromRecord.boardId)
|
||||
: [];
|
||||
|
||||
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.fromRecord.id);
|
||||
|
||||
const customFieldGroups = [...boardCustomFieldGroups, ...cardCustomFieldGroups];
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
|
||||
let customFieldGroupsByBaseCustomFieldGroupId;
|
||||
let baseCustomFieldGroupById;
|
||||
let customFieldsByBaseCustomFieldGroupId;
|
||||
let nextCustomFieldsTotal = customFields.length;
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
customFieldGroupsByBaseCustomFieldGroupId = _.groupBy(
|
||||
customFieldGroups.filter(({ baseCustomFieldGroupId }) => baseCustomFieldGroupId),
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
|
||||
const baseCustomFieldGroupIds = Object.keys(customFieldGroupsByBaseCustomFieldGroupId);
|
||||
|
||||
if (baseCustomFieldGroupIds.length > 0) {
|
||||
const baseCustomFieldGroups =
|
||||
await BaseCustomFieldGroup.qm.getByIds(baseCustomFieldGroupIds);
|
||||
|
||||
baseCustomFieldGroupById = _.keyBy(baseCustomFieldGroups, 'id');
|
||||
|
||||
const baseCustomFields = await CustomField.qm.getByBaseCustomFieldGroupIds(
|
||||
Object.keys(baseCustomFieldGroupById),
|
||||
);
|
||||
|
||||
customFieldsByBaseCustomFieldGroupId = _.groupBy(
|
||||
baseCustomFields,
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
|
||||
nextCustomFieldsTotal += Object.entries(customFieldGroupsByBaseCustomFieldGroupId).reduce(
|
||||
(result, [baseCustomFieldGroupId, customFieldGroupsItem]) => {
|
||||
const customFieldsItem = customFieldsByBaseCustomFieldGroupId[baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result + customFieldsItem.length * customFieldGroupsItem.length;
|
||||
},
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.fromRecord.id);
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(
|
||||
customFieldGroups.length + nextCustomFieldsTotal,
|
||||
);
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = customFieldGroups.map((customFieldGroup, index) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
const values = {
|
||||
..._.pick(customFieldGroup, ['position']),
|
||||
id,
|
||||
cardId: inputs.toRecord.id,
|
||||
position: customFieldGroup.boardId
|
||||
? POSITION_GAP * (index + 1)
|
||||
: customFieldGroup.position + POSITION_GAP * boardCustomFieldGroups.length,
|
||||
};
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
values.name =
|
||||
customFieldGroup.name ||
|
||||
baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name;
|
||||
} else {
|
||||
Object.assign(values, {
|
||||
name: customFieldGroup.name,
|
||||
baseCustomFieldGroupId: customFieldGroup.baseCustomFieldGroupId,
|
||||
});
|
||||
}
|
||||
|
||||
return values;
|
||||
});
|
||||
|
||||
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],
|
||||
};
|
||||
});
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
Object.entries(customFieldGroupsByBaseCustomFieldGroupId).forEach(
|
||||
([baseCustomFieldGroupId, customFieldGroupsItem]) => {
|
||||
const customFieldsItem = customFieldsByBaseCustomFieldGroupId[baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
customFieldGroupsItem.forEach((customFieldGroup) => {
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId: nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id],
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const nextCustomFields = await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const nextCustomFieldValuesValues = customFieldValues.map((customFieldValue) => {
|
||||
const groupedId = `${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`;
|
||||
|
||||
return {
|
||||
..._.pick(customFieldValue, ['content']),
|
||||
cardId: inputs.toRecord.id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId] ||
|
||||
customFieldValue.customFieldGroupId,
|
||||
customFieldId:
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] ||
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId] ||
|
||||
customFieldValue.customFieldId,
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFieldValues = await CustomFieldValue.qm.create(nextCustomFieldValuesValues);
|
||||
|
||||
return {
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -198,11 +198,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[cardId][
|
||||
`${customFieldGroup.id}:${customField.id}`
|
||||
] = id;
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[cardId][groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
@@ -223,11 +222,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldGroup.cardId][
|
||||
`${customFieldGroup.id}:${customField.id}`
|
||||
] = id;
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldGroup.cardId][groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
@@ -262,10 +260,11 @@ module.exports = {
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldValue.cardId];
|
||||
|
||||
if (nextCustomFieldIdByCustomFieldId) {
|
||||
const groupedId = `${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`;
|
||||
|
||||
const nextCustomFieldId =
|
||||
nextCustomFieldIdByCustomFieldId[
|
||||
`${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`
|
||||
] || nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] ||
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
|
||||
if (nextCustomFieldId) {
|
||||
updateValues.customFieldId = nextCustomFieldId;
|
||||
|
||||
@@ -25,10 +25,6 @@ module.exports = {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
join: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
@@ -36,25 +32,58 @@ module.exports = {
|
||||
|
||||
exits: {
|
||||
positionMustBeInValues: {},
|
||||
boardInValuesMustBelongToProject: {},
|
||||
listMustBeInValues: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.list) {
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
if (values.project && values.project.id === inputs.project.id) {
|
||||
delete values.project;
|
||||
}
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
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 (values.list) {
|
||||
if (values.list.boardId !== board.id) {
|
||||
throw 'listInValuesMustBelongToBoard';
|
||||
}
|
||||
|
||||
if (values.list.id === inputs.list.id) {
|
||||
delete values.list;
|
||||
} else {
|
||||
values.listId = values.list.id;
|
||||
}
|
||||
} else if (values.board) {
|
||||
throw 'listMustBeInValues';
|
||||
}
|
||||
|
||||
const list = values.list || inputs.list;
|
||||
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
} else {
|
||||
values.position = null;
|
||||
}
|
||||
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
@@ -95,9 +124,54 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
let labelIds;
|
||||
if (values.board) {
|
||||
const prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
|
||||
const labels = await Label.qm.getByBoardId(values.board.id);
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
labelIds = await Promise.all(
|
||||
prevLabels.map(async (label) => {
|
||||
if (labelByName[label.name]) {
|
||||
return labelByName[label.name].id;
|
||||
}
|
||||
|
||||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
},
|
||||
actorUser: values.creatorUser,
|
||||
});
|
||||
|
||||
return id;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (values.list) {
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!values.name) {
|
||||
const t = sails.helpers.utils.makeTranslator(values.creatorUser.language);
|
||||
values.name = `${inputs.record.name} (${t('copy')})`;
|
||||
}
|
||||
|
||||
let card = await Card.qm.createOne({
|
||||
..._.pick(inputs.record, [
|
||||
'boardId',
|
||||
'listId',
|
||||
'prevListId',
|
||||
'type',
|
||||
'name',
|
||||
@@ -108,12 +182,16 @@ module.exports = {
|
||||
'isClosed',
|
||||
]),
|
||||
...values,
|
||||
listId: list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id);
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(card.boardId);
|
||||
const boardMemberUserIdsSet = new Set(boardMemberUserIds);
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id, {
|
||||
userIdOrIds: boardMemberUserIds,
|
||||
});
|
||||
|
||||
const cardMembershipsValues = cardMemberships.map((cardMembership) => ({
|
||||
..._.pick(cardMembership, ['userId']),
|
||||
@@ -122,10 +200,13 @@ module.exports = {
|
||||
|
||||
const nextCardMemberships = await CardMembership.qm.create(cardMembershipsValues);
|
||||
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
if (!values.board) {
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
labelIds = sails.helpers.utils.mapRecords(cardLabels, 'labelId');
|
||||
}
|
||||
|
||||
const cardLabelsValues = cardLabels.map((cardLabel) => ({
|
||||
..._.pick(cardLabel, ['labelId']),
|
||||
const cardLabelsValues = labelIds.map((labelId) => ({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
}));
|
||||
|
||||
@@ -137,15 +218,7 @@ module.exports = {
|
||||
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 ids = await sails.helpers.utils.generateIds(taskLists.length + attachments.length);
|
||||
|
||||
const nextTaskListIdByTaskListId = {};
|
||||
const nextTaskListsValues = await taskLists.map((taskList) => {
|
||||
@@ -162,8 +235,9 @@ module.exports = {
|
||||
const nextTaskLists = await TaskList.qm.create(nextTaskListsValues);
|
||||
|
||||
const nextTasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['linkedCardId', 'assigneeUserId', 'position', 'name', 'isCompleted']),
|
||||
..._.pick(task, ['linkedCardId', 'position', 'name', 'isCompleted']),
|
||||
taskListId: nextTaskListIdByTaskListId[task.taskListId],
|
||||
assigneeUserId: boardMemberUserIdsSet.has(task.assigneeUserId) ? task.assigneeUserId : null,
|
||||
}));
|
||||
|
||||
const nextTasks = await Task.qm.create(nextTasksValues);
|
||||
@@ -193,47 +267,16 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
const {
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
} = await sails.helpers.cards.copyCustomFields(
|
||||
inputs.record,
|
||||
card,
|
||||
!!values.board,
|
||||
!!values.project,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
@@ -252,8 +295,8 @@ module.exports = {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
projects: [project],
|
||||
boards: [board],
|
||||
lists: [list],
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
@@ -291,6 +334,8 @@ module.exports = {
|
||||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
webhooks,
|
||||
values: {
|
||||
@@ -302,8 +347,6 @@ module.exports = {
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -98,7 +98,11 @@ module.exports = {
|
||||
throw 'coverAttachmentInValuesMustContainImage';
|
||||
}
|
||||
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
if (values.coverAttachment.id === inputs.record.coverAttachmentId) {
|
||||
delete values.coverAttachment;
|
||||
} else {
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
}
|
||||
}
|
||||
|
||||
const dueDate = _.isUndefined(values.dueDate) ? inputs.record.dueDate : values.dueDate;
|
||||
@@ -289,9 +293,14 @@ module.exports = {
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${card.boardId}`, 'cardUpdate', {
|
||||
item: card,
|
||||
});
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: card,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: add transfer action
|
||||
} else {
|
||||
|
||||
@@ -13,10 +13,16 @@ const createOne = (values) => CardMembership.create({ ...values }).fetch();
|
||||
|
||||
const getByIds = (ids) => defaultFind(ids);
|
||||
|
||||
const getByCardId = (cardId) =>
|
||||
defaultFind({
|
||||
const getByCardId = (cardId, { userIdOrIds } = {}) => {
|
||||
const criteria = {
|
||||
cardId,
|
||||
});
|
||||
};
|
||||
if (userIdOrIds) {
|
||||
criteria.userId = userIdOrIds;
|
||||
}
|
||||
|
||||
return defaultFind(criteria);
|
||||
};
|
||||
|
||||
const getByCardIds = (cardIds) =>
|
||||
defaultFind({
|
||||
|
||||
Reference in New Issue
Block a user