mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
48
server/api/controllers/boards/create.js
Executable file
48
server/api/controllers/boards/create.js
Executable file
|
@ -0,0 +1,48 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
notFound: 'Project is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
projectId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const project = await Project.findOne(inputs.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const board = await sails.helpers.createBoard(project, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: board,
|
||||
included: {
|
||||
lists: [],
|
||||
labels: []
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
38
server/api/controllers/boards/delete.js
Executable file
38
server/api/controllers/boards/delete.js
Executable file
|
@ -0,0 +1,38 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let board = await Board.findOne(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
board = await sails.helpers.deleteBoard(board, this.req);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: board
|
||||
});
|
||||
}
|
||||
};
|
84
server/api/controllers/boards/show.js
Executable file
84
server/api/controllers/boards/show.js
Executable file
|
@ -0,0 +1,84 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
}
|
||||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getBoardToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const lists = await sails.helpers.getListsForBoard(board.id);
|
||||
const labels = await sails.helpers.getLabelsForBoard(board.id);
|
||||
|
||||
const cards = await sails.helpers.getCardsForBoard(board.id);
|
||||
const cardIds = sails.helpers.mapRecords(cards);
|
||||
|
||||
const cardSubscriptions = await sails.helpers.getSubscriptionsByUserForCard(
|
||||
cardIds,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
const cardMemberships = await sails.helpers.getMembershipsForCard(cardIds);
|
||||
const cardLabels = await sails.helpers.getCardLabelsForCard(cardIds);
|
||||
|
||||
const tasks = await sails.helpers.getTasksForCard(cardIds);
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
...result,
|
||||
[cardSubscription.cardId]: true
|
||||
}),
|
||||
{}
|
||||
);
|
||||
|
||||
cards.forEach(card => {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||
});
|
||||
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
|
||||
return exits.success({
|
||||
item: board,
|
||||
included: {
|
||||
lists,
|
||||
labels,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
tasks
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/boards/update.js
Executable file
47
server/api/controllers/boards/update.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let board = await Board.findOne(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
board = await sails.helpers.updateBoard(board, values, this.req);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: board
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue