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/labels/update.js

55 lines
1 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found'
}
};
module.exports = {
inputs: {
id: {
type: 'number',
required: true
},
name: {
type: 'string',
isNotEmptyString: true
},
color: {
type: 'string',
isIn: Label.COLORS,
allowNull: true
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
fn: async function(inputs, exits) {
const { currentUser } = this.req;
let { label, project } = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.LABEL_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['name', 'color']);
label = await sails.helpers.updateLabel(label, values, this.req);
return exits.success({
item: label
});
}
};