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
|
|
|
|
|
* /api/boards/{id}:
|
|
|
|
|
* delete:
|
|
|
|
|
* summary: Delete board
|
|
|
|
|
* description: Deletes a board and all its contents (lists, cards, etc.). Requires project manager permissions.
|
|
|
|
|
* tags:
|
|
|
|
|
* - Boards
|
|
|
|
|
* parameters:
|
|
|
|
|
* - name: id
|
|
|
|
|
* in: path
|
|
|
|
|
* required: true
|
|
|
|
|
* description: ID of the board to delete
|
|
|
|
|
* schema:
|
|
|
|
|
* type: string
|
|
|
|
|
* example: 1357158568008091264
|
|
|
|
|
* 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'
|
|
|
|
|
*/
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
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-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
|
|
|
boardNotFound: {
|
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) {
|
2021-08-02 17:23:56 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const pathToProject = await sails.helpers.boards
|
|
|
|
|
.getPathToProjectById(inputs.id)
|
2021-06-24 01:05:22 +05:00
|
|
|
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
let { board } = pathToProject;
|
|
|
|
|
const { project } = pathToProject;
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
|
if (!isProjectManager) {
|
|
|
|
|
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
board = await sails.helpers.boards.deleteOne.with({
|
2024-06-12 00:51:36 +02:00
|
|
|
project,
|
2022-12-26 21:10:50 +01:00
|
|
|
record: board,
|
2024-06-12 00:51:36 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2019-11-05 18:01:42 +05:00
|
|
|
item: board,
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|