mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
Merge e822372026
into 49203e9d56
This commit is contained in:
commit
fd95709d5a
2 changed files with 59 additions and 0 deletions
57
server/api/controllers/cards/assigned.js
Normal file
57
server/api/controllers/cards/assigned.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*!
|
||||||
|
* Copyright (c) 2024 PLANKA Software GmbH
|
||||||
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
inputs: {},
|
||||||
|
|
||||||
|
async fn() {
|
||||||
|
const { currentUser } = this.req;
|
||||||
|
|
||||||
|
// Get all cards where the user is a member
|
||||||
|
const cardMemberships = await CardMembership.find({ userId: currentUser.id });
|
||||||
|
const cardIdsByMembership = cardMemberships.map((cm) => cm.cardId);
|
||||||
|
|
||||||
|
// Get all cards where the user is the author
|
||||||
|
const cardsByAuthor = await Card.find({ creatorUserId: currentUser.id });
|
||||||
|
const cardIdsByAuthor = cardsByAuthor.map((c) => c.id);
|
||||||
|
|
||||||
|
// Merge card ids
|
||||||
|
const cardIds = Array.from(new Set([...cardIdsByMembership, ...cardIdsByAuthor]));
|
||||||
|
if (cardIds.length === 0) {
|
||||||
|
return { items: [], included: {} };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get cards
|
||||||
|
const cards = await Card.qm.getByIds(cardIds);
|
||||||
|
|
||||||
|
// Collect related data
|
||||||
|
const users = await User.qm.getByIds(cards.map((c) => c.creatorUserId));
|
||||||
|
const cardMembershipsAll = await CardMembership.qm.getByCardIds(cardIds);
|
||||||
|
const cardLabels = await CardLabel.qm.getByCardIds(cardIds);
|
||||||
|
const taskLists = await TaskList.qm.getByCardIds(cardIds);
|
||||||
|
const taskListIds = taskLists.map((tl) => tl.id);
|
||||||
|
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||||
|
const attachments = await Attachment.qm.getByCardIds(cardIds);
|
||||||
|
const customFieldGroups = await CustomFieldGroup.qm.getByCardIds(cardIds);
|
||||||
|
const customFieldGroupIds = customFieldGroups.map((cfg) => cfg.id);
|
||||||
|
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||||
|
const customFieldValues = await CustomFieldValue.qm.getByCardIds(cardIds);
|
||||||
|
|
||||||
|
return {
|
||||||
|
items: cards,
|
||||||
|
included: {
|
||||||
|
cardMemberships: cardMembershipsAll,
|
||||||
|
cardLabels,
|
||||||
|
taskLists,
|
||||||
|
tasks,
|
||||||
|
customFieldGroups,
|
||||||
|
customFields,
|
||||||
|
customFieldValues,
|
||||||
|
users: sails.helpers.users.presentMany(users, currentUser),
|
||||||
|
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
|
@ -232,6 +232,8 @@ module.exports.routes = {
|
||||||
skipAssets: false,
|
skipAssets: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'GET /api/cards/assigned': 'cards/assigned',
|
||||||
|
|
||||||
'GET /*': {
|
'GET /*': {
|
||||||
view: 'index',
|
view: 'index',
|
||||||
skipAssets: true,
|
skipAssets: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue