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
|
|
|
* /projects/{id}:
|
2025-09-08 16:20:27 +02:00
|
|
|
* get:
|
|
|
|
|
* summary: Get project details
|
|
|
|
|
* description: Retrieves comprehensive project information, including boards, board memberships, and other related data.
|
|
|
|
|
* tags:
|
|
|
|
|
* - Projects
|
2025-09-12 12:17:01 +02:00
|
|
|
* operationId: getProject
|
2025-09-08 16:20:27 +02:00
|
|
|
* parameters:
|
|
|
|
|
* - name: id
|
|
|
|
|
* in: path
|
|
|
|
|
* required: true
|
|
|
|
|
* description: ID of the project to retrieve
|
|
|
|
|
* schema:
|
|
|
|
|
* type: string
|
2025-09-08 19:14:31 +02:00
|
|
|
* example: "1357158568008091264"
|
2025-09-08 16:20:27 +02:00
|
|
|
* responses:
|
|
|
|
|
* 200:
|
|
|
|
|
* description: Project details retrieved successfully
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - item
|
|
|
|
|
* - included
|
|
|
|
|
* properties:
|
|
|
|
|
* item:
|
|
|
|
|
* allOf:
|
|
|
|
|
* - $ref: '#/components/schemas/Project'
|
|
|
|
|
* - type: object
|
|
|
|
|
* properties:
|
|
|
|
|
* isFavorite:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* description: Whether the project is marked as favorite by the current user
|
|
|
|
|
* example: true
|
|
|
|
|
* included:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - users
|
|
|
|
|
* - projectManagers
|
|
|
|
|
* - backgroundImages
|
|
|
|
|
* - baseCustomFieldGroups
|
|
|
|
|
* - boards
|
|
|
|
|
* - boardMemberships
|
|
|
|
|
* - customFields
|
|
|
|
|
* - notificationServices
|
|
|
|
|
* properties:
|
|
|
|
|
* users:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related users
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/User'
|
|
|
|
|
* projectManagers:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related project managers
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/ProjectManager'
|
|
|
|
|
* backgroundImages:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related background images
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/BackgroundImage'
|
|
|
|
|
* baseCustomFieldGroups:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related base custom field groups
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/BaseCustomFieldGroup'
|
|
|
|
|
* boards:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related boards
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/Board'
|
|
|
|
|
* boardMemberships:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related board memberships (for current user)
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/BoardMembership'
|
|
|
|
|
* customFields:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related custom fields
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/CustomField'
|
|
|
|
|
* notificationServices:
|
|
|
|
|
* type: array
|
|
|
|
|
* description: Related notification services (for managed projects)
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/NotificationService'
|
|
|
|
|
* 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');
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const Errors = {
|
|
|
|
|
PROJECT_NOT_FOUND: {
|
|
|
|
|
projectNotFound: 'Project not found',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
inputs: {
|
|
|
|
|
id: {
|
2025-05-10 02:09:06 +02:00
|
|
|
...idInput,
|
2021-06-24 01:05:22 +05:00
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exits: {
|
|
|
|
|
projectNotFound: {
|
|
|
|
|
responseType: 'notFound',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async fn(inputs) {
|
|
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const project = await Project.qm.getOneById(inputs.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
if (!project) {
|
|
|
|
|
throw Errors.PROJECT_NOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const boardMemberships = await BoardMembership.qm.getByProjectIdAndUserId(
|
|
|
|
|
project.id,
|
|
|
|
|
currentUser.id,
|
|
|
|
|
);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
let boards;
|
|
|
|
|
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
|
|
|
|
if (!isProjectManager) {
|
|
|
|
|
if (boardMemberships.length === 0) {
|
|
|
|
|
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
|
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const boardIds = sails.helpers.utils.mapRecords(boardMemberships, 'boardId');
|
|
|
|
|
boards = await Board.qm.getByIds(boardIds);
|
2021-06-24 01:05:22 +05:00
|
|
|
}
|
2025-05-10 02:09:06 +02:00
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
if (!boards) {
|
|
|
|
|
boards = await Board.qm.getByProjectId(project.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
}
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
project.isFavorite = await sails.helpers.users.isProjectFavorite(currentUser.id, project.id);
|
|
|
|
|
|
|
|
|
|
const projectManagers = await ProjectManager.qm.getByProjectId(project.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
const userIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
|
2025-05-10 02:09:06 +02:00
|
|
|
const users = await User.qm.getByIds(userIds);
|
|
|
|
|
|
|
|
|
|
const backgroundImages = await BackgroundImage.qm.getByProjectId(project.id);
|
|
|
|
|
|
|
|
|
|
const baseCustomFieldGroups = await BaseCustomFieldGroup.qm.getByProjectId(project.id);
|
|
|
|
|
const baseCustomFieldGroupsIds = sails.helpers.utils.mapRecords(baseCustomFieldGroups);
|
|
|
|
|
|
|
|
|
|
const customFields =
|
|
|
|
|
await CustomField.qm.getByBaseCustomFieldGroupIds(baseCustomFieldGroupsIds);
|
|
|
|
|
|
|
|
|
|
let notificationServices = [];
|
|
|
|
|
if (isProjectManager) {
|
|
|
|
|
boardIds = sails.helpers.utils.mapRecords(boards);
|
|
|
|
|
notificationServices = await NotificationService.qm.getByBoardIds(boardIds);
|
|
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
item: project,
|
|
|
|
|
included: {
|
|
|
|
|
projectManagers,
|
2025-05-10 02:09:06 +02:00
|
|
|
baseCustomFieldGroups,
|
2021-06-24 01:05:22 +05:00
|
|
|
boards,
|
|
|
|
|
boardMemberships,
|
2025-05-10 02:09:06 +02:00
|
|
|
customFields,
|
|
|
|
|
notificationServices,
|
|
|
|
|
users: sails.helpers.users.presentMany(users, currentUser),
|
|
|
|
|
backgroundImages: sails.helpers.backgroundImages.presentMany(backgroundImages),
|
2021-06-24 01:05:22 +05:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|