1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/controllers/tasks/delete.js
2022-08-19 14:00:40 +02:00

61 lines
1.1 KiB
JavaScript
Executable file

const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
TASK_NOT_FOUND: {
taskNotFound: 'Task not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
taskNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const path = await sails.helpers.tasks
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = path;
const { board } = path;
const boardMembership = await BoardMembership.findOne({
boardId: board.id,
userId: currentUser.id,
});
if (!boardMembership) {
throw Errors.TASK_NOT_FOUND; // Forbidden
}
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
task = await sails.helpers.tasks.deleteOne(task, board, this.req);
if (!task) {
throw Errors.TASK_NOT_FOUND;
}
return {
item: task,
};
},
};