1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-20 13:49:43 +02:00
planka/server/api/controllers/boards/delete.js

60 lines
1.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
*/
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
};