1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/controllers/labels/create.js

52 lines
1 KiB
JavaScript
Executable file

const Errors = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
},
};
module.exports = {
inputs: {
boardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
name: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
color: {
type: 'string',
isIn: Label.COLORS,
required: true,
},
},
exits: {
boardNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { board } = await sails.helpers.boards
.getProjectPath(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
if (!isBoardMember) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['name', 'color']);
const label = await sails.helpers.labels.createOne(values, board, this.req);
return {
item: label,
};
},
};