2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
|
*/
|
|
|
|
|
|
2025-09-08 16:20:27 +02:00
|
|
|
/**
|
|
|
|
|
* @swagger
|
2025-09-08 18:25:26 +02:00
|
|
|
* /cards/{id}:
|
2025-09-08 16:20:27 +02:00
|
|
|
* get:
|
|
|
|
|
* summary: Get card details
|
|
|
|
|
* description: Retrieves comprehensive card information, including tasks, attachments, and other related data.
|
|
|
|
|
* tags:
|
|
|
|
|
* - Cards
|
|
|
|
|
* parameters:
|
|
|
|
|
* - name: id
|
|
|
|
|
* in: path
|
|
|
|
|
* required: true
|
|
|
|
|
* description: ID of the card to retrieve
|
|
|
|
|
* schema:
|
|
|
|
|
* type: string
|
|
|
|
|
* example: 1357158568008091264
|
|
|
|
|
* responses:
|
|
|
|
|
* 200:
|
|
|
|
|
* description: Card details retrieved successfully
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - item
|
|
|
|
|
* - included
|
|
|
|
|
* properties:
|
|
|
|
|
* item:
|
|
|
|
|
* allOf:
|
|
|
|
|
* - $ref: '#/components/schemas/Card'
|
|
|
|
|
* - type: object
|
|
|
|
|
* properties:
|
|
|
|
|
* isSubscribed:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* description: Whether the current user is subscribed to the card
|
|
|
|
|
* example: true
|
|
|
|
|
* included:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - users
|
|
|
|
|
* - cardMemberships
|
|
|
|
|
* - cardLabels
|
|
|
|
|
* - taskLists
|
|
|
|
|
* - tasks
|
|
|
|
|
* - attachments
|
|
|
|
|
* - customFieldGroups
|
|
|
|
|
* - customFields
|
|
|
|
|
* - customFieldValues
|
|
|
|
|
* properties:
|
|
|
|
|
* users:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related users
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/User'
|
|
|
|
|
* cardMemberships:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related card-membership associations
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CardMembership'
|
|
|
|
|
* cardLabels:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related card-label associations
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CardLabel'
|
|
|
|
|
* taskLists:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related task lists
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/TaskList'
|
|
|
|
|
* tasks:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related tasks
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Task'
|
|
|
|
|
* attachments:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related attachments
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Attachment'
|
|
|
|
|
* customFieldGroups:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom field groups
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomFieldGroup'
|
|
|
|
|
* customFields:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom fields
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomField'
|
|
|
|
|
* customFieldValues:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom field values
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomFieldValue'
|
|
|
|
|
* 400:
|
|
|
|
|
* $ref: '#/components/responses/ValidationError'
|
|
|
|
|
* 401:
|
|
|
|
|
* $ref: '#/components/responses/Unauthorized'
|
|
|
|
|
* 404:
|
|
|
|
|
* $ref: '#/components/responses/NotFound'
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const { idInput } = require('../../../utils/inputs');
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
|
CARD_NOT_FOUND: {
|
2020-04-03 00:35:25 +05:00
|
|
|
cardNotFound: 'Card not found',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
inputs: {
|
|
|
|
|
id: {
|
2025-05-10 02:09:06 +02:00
|
|
|
...idInput,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
cardNotFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2019-08-31 04:07:25 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const { card, project } = await sails.helpers.cards
|
2025-05-10 02:09:06 +02:00
|
|
|
.getPathToProjectById(inputs.id)
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
2021-06-24 01:05:22 +05:00
|
|
|
const isProjectManager = await sails.helpers.users.isProjectManager(
|
|
|
|
|
currentUser.id,
|
|
|
|
|
project.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!isProjectManager) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
|
|
|
|
card.boardId,
|
|
|
|
|
currentUser.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!boardMembership) {
|
|
|
|
|
throw Errors.CARD_NOT_FOUND; // Forbidden
|
|
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
card.isSubscribed = await sails.helpers.users.isCardSubscriber(currentUser.id, card.id);
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const users = card.creatorUserId ? await User.qm.getByIds([card.creatorUserId]) : [];
|
|
|
|
|
const cardMemberships = await CardMembership.qm.getByCardId(card.id);
|
|
|
|
|
const cardLabels = await CardLabel.qm.getByCardId(card.id);
|
|
|
|
|
|
|
|
|
|
const taskLists = await TaskList.qm.getByCardId(card.id);
|
|
|
|
|
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
|
|
|
|
|
|
|
|
|
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
|
|
|
|
const attachments = await Attachment.qm.getByCardId(card.id);
|
|
|
|
|
|
|
|
|
|
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(card.id);
|
|
|
|
|
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
|
|
|
|
|
|
|
|
|
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
|
|
|
|
const customFieldValues = await CustomFieldValue.qm.getByCardId(card.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
return {
|
2019-11-05 18:01:42 +05:00
|
|
|
item: card,
|
2021-06-24 01:05:22 +05:00
|
|
|
included: {
|
|
|
|
|
cardMemberships,
|
|
|
|
|
cardLabels,
|
2025-05-10 02:09:06 +02:00
|
|
|
taskLists,
|
2021-06-24 01:05:22 +05:00
|
|
|
tasks,
|
2025-05-10 02:09:06 +02:00
|
|
|
customFieldGroups,
|
|
|
|
|
customFields,
|
|
|
|
|
customFieldValues,
|
|
|
|
|
users: sails.helpers.users.presentMany(users, currentUser),
|
|
|
|
|
attachments: sails.helpers.attachments.presentMany(attachments),
|
2021-06-24 01:05:22 +05:00
|
|
|
},
|
|
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|