Files
planka/server/api/controllers/boards/delete.js

97 lines
2.2 KiB
JavaScript
Raw Normal View History

/*!
* 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
* /boards/{id}:
2025-09-08 16:20:27 +02:00
* delete:
* summary: Delete board
* description: Deletes a board and all its contents (lists, cards, etc.). Requires project manager permissions.
* tags:
* - Boards
2025-09-12 12:17:01 +02:00
* operationId: deleteBoard
2025-09-08 16:20:27 +02:00
* parameters:
* - name: id
* in: path
* required: true
* description: ID of the board to delete
* schema:
* type: string
2025-09-08 19:14:31 +02:00
* example: "1357158568008091264"
2025-09-08 16:20:27 +02:00
* responses:
* 200:
* description: Board deleted successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - item
* properties:
* item:
* $ref: '#/components/schemas/Board'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 404:
* $ref: '#/components/responses/NotFound'
*/
const { idInput } = require('../../../utils/inputs');
2019-08-31 04:07:25 +05:00
const Errors = {
BOARD_NOT_FOUND: {
2020-04-03 00:35:25 +05:00
boardNotFound: 'Board not found',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
2019-08-31 04:07:25 +05:00
},
exits: {
2020-04-03 00:35:25 +05:00
boardNotFound: {
responseType: 'notFound',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
const { currentUser } = this.req;
const pathToProject = await sails.helpers.boards
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
2019-08-31 04:07:25 +05:00
let { board } = pathToProject;
const { project } = pathToProject;
2019-08-31 04:07:25 +05:00
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
2022-12-26 21:10:50 +01:00
board = await sails.helpers.boards.deleteOne.with({
project,
2022-12-26 21:10:50 +01:00
record: board,
actorUser: currentUser,
2022-12-26 21:10:50 +01:00
request: this.req,
});
2019-08-31 04:07:25 +05:00
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
return {
item: board,
};
},
2019-08-31 04:07:25 +05:00
};