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/{projectId}/boards:
|
2025-09-08 16:20:27 +02:00
|
|
|
* post:
|
|
|
|
|
* summary: Create board
|
|
|
|
|
* description: Creates a board within a project. Supports importing from Trello. Requires project manager permissions.
|
|
|
|
|
* tags:
|
|
|
|
|
* - Boards
|
|
|
|
|
* parameters:
|
|
|
|
|
* - name: projectId
|
|
|
|
|
* in: path
|
|
|
|
|
* required: true
|
|
|
|
|
* description: ID of the project to create the board in
|
|
|
|
|
* schema:
|
|
|
|
|
* type: string
|
|
|
|
|
* example: 1357158568008091264
|
|
|
|
|
* requestBody:
|
|
|
|
|
* required: true
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - position
|
|
|
|
|
* - name
|
|
|
|
|
* properties:
|
|
|
|
|
* position:
|
|
|
|
|
* type: number
|
|
|
|
|
* minimum: 0
|
|
|
|
|
* description: Position of the board within the project
|
|
|
|
|
* example: 65536
|
|
|
|
|
* name:
|
|
|
|
|
* type: string
|
|
|
|
|
* maxLength: 128
|
|
|
|
|
* description: Name/title of the board
|
|
|
|
|
* example: Development Board
|
|
|
|
|
* defaultView:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum: [kanban, grid, list]
|
|
|
|
|
* default: kanban
|
|
|
|
|
* description: Default view for the board
|
|
|
|
|
* example: kanban
|
|
|
|
|
* defaultCardType:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum: [project, story]
|
|
|
|
|
* default: project
|
|
|
|
|
* description: Default card type for new cards
|
|
|
|
|
* example: project
|
|
|
|
|
* limitCardTypesToDefaultOne:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to limit card types to default one
|
|
|
|
|
* example: false
|
|
|
|
|
* alwaysDisplayCardCreator:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to always display the card creator
|
|
|
|
|
* example: false
|
|
|
|
|
* expandTaskListsByDefault:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to expand task lists by default
|
|
|
|
|
* example: false
|
|
|
|
|
* multipart/form-data:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - position
|
|
|
|
|
* - name
|
|
|
|
|
* properties:
|
|
|
|
|
* position:
|
|
|
|
|
* type: number
|
|
|
|
|
* minimum: 0
|
|
|
|
|
* description: Position of the board within the project
|
|
|
|
|
* example: 65536
|
|
|
|
|
* name:
|
|
|
|
|
* type: string
|
|
|
|
|
* maxLength: 128
|
|
|
|
|
* description: Name/title of the board
|
|
|
|
|
* example: Development Board
|
|
|
|
|
* defaultView:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum: [kanban, grid, list]
|
|
|
|
|
* default: kanban
|
|
|
|
|
* description: Default view for the board
|
|
|
|
|
* example: kanban
|
|
|
|
|
* defaultCardType:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum: [project, story]
|
|
|
|
|
* default: project
|
|
|
|
|
* description: Default card type for new cards
|
|
|
|
|
* example: project
|
|
|
|
|
* limitCardTypesToDefaultOne:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to limit card types to default one
|
|
|
|
|
* example: false
|
|
|
|
|
* alwaysDisplayCardCreator:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to always display the card creator
|
|
|
|
|
* example: false
|
|
|
|
|
* expandTaskListsByDefault:
|
|
|
|
|
* type: boolean
|
|
|
|
|
* default: false
|
|
|
|
|
* description: Whether to expand task lists by default
|
|
|
|
|
* example: false
|
|
|
|
|
* importType:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum: [trello]
|
|
|
|
|
* description: Type of import
|
|
|
|
|
* example: trello
|
|
|
|
|
* importFile:
|
|
|
|
|
* type: string
|
|
|
|
|
* format: binary
|
|
|
|
|
* description: Import file
|
|
|
|
|
* requestId:
|
|
|
|
|
* type: string
|
|
|
|
|
* maxLength: 128
|
|
|
|
|
* description: Request ID for tracking
|
|
|
|
|
* example: req_123456
|
|
|
|
|
* responses:
|
|
|
|
|
* 200:
|
|
|
|
|
* description: Board created successfully
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - item
|
|
|
|
|
* - included
|
|
|
|
|
* properties:
|
|
|
|
|
* item:
|
|
|
|
|
* $ref: '#/components/schemas/Board'
|
|
|
|
|
* included:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - boardMemberships
|
|
|
|
|
* properties:
|
|
|
|
|
* boardMemberships:
|
|
|
|
|
* type: array
|
|
|
|
|
* items:
|
|
|
|
|
* $ref: '#/components/schemas/BoardMembership'
|
|
|
|
|
* 400:
|
|
|
|
|
* $ref: '#/components/responses/ValidationError'
|
|
|
|
|
* 401:
|
|
|
|
|
* $ref: '#/components/responses/Unauthorized'
|
|
|
|
|
* 404:
|
|
|
|
|
* $ref: '#/components/responses/NotFound'
|
|
|
|
|
* 422:
|
|
|
|
|
* description: Import file upload error
|
|
|
|
|
* content:
|
|
|
|
|
* application/json:
|
|
|
|
|
* schema:
|
|
|
|
|
* type: object
|
|
|
|
|
* required:
|
|
|
|
|
* - code
|
|
|
|
|
* - message
|
|
|
|
|
* properties:
|
|
|
|
|
* code:
|
|
|
|
|
* type: string
|
|
|
|
|
* description: Error code
|
|
|
|
|
* example: E_UNPROCESSABLE_ENTITY
|
|
|
|
|
* message:
|
|
|
|
|
* type: string
|
|
|
|
|
* enum:
|
|
|
|
|
* - No import file was uploaded
|
|
|
|
|
* - Invalid import file
|
|
|
|
|
* description: Specific error message
|
|
|
|
|
* example: No import file was uploaded
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const { idInput } = require('../../../utils/inputs');
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
|
PROJECT_NOT_FOUND: {
|
2020-04-03 00:35:25 +05:00
|
|
|
projectNotFound: 'Project not found',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
NO_IMPORT_FILE_WAS_UPLOADED: {
|
|
|
|
|
noImportFileWasUploaded: 'No import file was uploaded',
|
|
|
|
|
},
|
|
|
|
|
INVALID_IMPORT_FILE: {
|
|
|
|
|
invalidImportFile: 'Invalid import file',
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
inputs: {
|
|
|
|
|
projectId: {
|
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
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
type: 'number',
|
2025-05-10 02:09:06 +02:00
|
|
|
min: 0,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
name: {
|
|
|
|
|
type: 'string',
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 128,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
importType: {
|
|
|
|
|
type: 'string',
|
|
|
|
|
isIn: Object.values(Board.ImportTypes),
|
|
|
|
|
},
|
|
|
|
|
requestId: {
|
|
|
|
|
type: 'string',
|
|
|
|
|
isNotEmptyString: true,
|
2025-05-10 02:09:06 +02:00
|
|
|
maxLength: 128,
|
2022-12-16 23:48:06 +01:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
projectNotFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
noImportFileWasUploaded: {
|
|
|
|
|
responseType: 'unprocessableEntity',
|
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
invalidImportFile: {
|
|
|
|
|
responseType: 'unprocessableEntity',
|
|
|
|
|
},
|
2022-12-16 23:48:06 +01:00
|
|
|
uploadError: {
|
|
|
|
|
responseType: 'unprocessableEntity',
|
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
2025-08-23 00:03:20 +02:00
|
|
|
async fn(inputs, exits) {
|
2021-06-24 01:05:22 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const project = await Project.qm.getOneById(inputs.projectId);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
|
if (!project) {
|
|
|
|
|
throw Errors.PROJECT_NOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
|
|
|
|
|
|
|
|
|
if (!isProjectManager) {
|
|
|
|
|
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 23:48:06 +01:00
|
|
|
let boardImport;
|
2025-05-10 02:09:06 +02:00
|
|
|
if (inputs.importType) {
|
2022-12-16 23:48:06 +01:00
|
|
|
let files;
|
|
|
|
|
try {
|
2025-08-23 00:03:20 +02:00
|
|
|
files = await sails.helpers.utils.receiveFile(this.req.file('importFile'), false);
|
2022-12-16 23:48:06 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
return exits.uploadError(error.message); // TODO: add error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (files.length === 0) {
|
|
|
|
|
throw Errors.NO_IMPORT_FILE_WAS_UPLOADED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const file = _.last(files);
|
|
|
|
|
|
|
|
|
|
if (inputs.importType === Board.ImportTypes.TRELLO) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const trelloBoard = await sails.helpers.boards
|
|
|
|
|
.processUploadedTrelloImportFile(file)
|
|
|
|
|
.intercept('invalidFile', () => Errors.INVALID_IMPORT_FILE);
|
|
|
|
|
|
2022-12-16 23:48:06 +01:00
|
|
|
boardImport = {
|
|
|
|
|
type: inputs.importType,
|
2025-05-10 02:09:06 +02:00
|
|
|
board: trelloBoard,
|
2022-12-16 23:48:06 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const values = _.pick(inputs, ['position', 'name']);
|
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
const { board, boardMembership } = await sails.helpers.boards.createOne.with({
|
|
|
|
|
values: {
|
|
|
|
|
...values,
|
|
|
|
|
project,
|
|
|
|
|
},
|
|
|
|
|
import: boardImport,
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: currentUser,
|
2022-12-26 21:10:50 +01:00
|
|
|
requestId: inputs.requestId,
|
|
|
|
|
request: this.req,
|
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-08-23 00:03:20 +02:00
|
|
|
return exits.success({
|
2019-08-31 04:07:25 +05:00
|
|
|
item: board,
|
|
|
|
|
included: {
|
2021-06-24 01:05:22 +05:00
|
|
|
boardMemberships: [boardMembership],
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2025-08-23 00:03:20 +02:00
|
|
|
});
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|