mirror of
https://github.com/plankanban/planka.git
synced 2025-07-22 22:59:44 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
67
server/api/controllers/card-memberships/create.js
Executable file
67
server/api/controllers/card-memberships/create.js
Executable file
|
@ -0,0 +1,67 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
},
|
||||
CARD_MEMBERSHIP_EXIST: {
|
||||
conflict: 'Card membership is already exist'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
},
|
||||
conflict: {
|
||||
responseType: 'conflict'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
let isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
inputs.userId
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardMembership = await sails.helpers
|
||||
.createCardMembership(card, inputs.userId, this.req)
|
||||
.intercept('conflict', () => Errors.CARD_MEMBERSHIP_EXIST);
|
||||
|
||||
return exits.success({
|
||||
item: cardMembership
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue