1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/server/api/controllers/labels/delete.js
2020-04-03 00:35:25 +05:00

51 lines
997 B
JavaScript
Executable file

const Errors = {
LABEL_NOT_FOUND: {
labelNotFound: 'Label not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
},
exits: {
labelNotFound: {
responseType: 'notFound',
},
},
async fn(inputs, exits) {
const { currentUser } = this.req;
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id,
);
if (!isUserMemberForProject) {
throw Errors.LABEL_NOT_FOUND; // Forbidden
}
label = await sails.helpers.deleteLabel(label, this.req);
if (!label) {
throw Errors.LABEL_NOT_FOUND;
}
return exits.success({
item: label,
});
},
};