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/boards/update.js
2022-12-26 21:10:50 +01:00

65 lines
1.1 KiB
JavaScript
Executable file

const Errors = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
position: {
type: 'number',
},
name: {
type: 'string',
isNotEmptyString: true,
},
},
exits: {
boardNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
let { board } = await sails.helpers.boards
.getProjectPath(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
board.projectId,
);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['position', 'name']);
board = await sails.helpers.boards.updateOne.with({
values,
record: board,
request: this.req,
});
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
return {
item: board,
};
},
};