1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-25 08:09:44 +02:00

Initial commit

This commit is contained in:
Maksim Eltyshev 2019-08-31 04:07:25 +05:00
commit 5ffef61fe7
613 changed files with 91659 additions and 0 deletions

View file

@ -0,0 +1,67 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
},
LABEL_NOT_FOUND: {
notFound: 'Label is not found'
},
CARD_LABEL_EXIST: {
conflict: 'Card label is already exist'
}
};
module.exports = {
inputs: {
cardId: {
type: 'number',
required: true
},
labelId: {
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);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
const label = await Label.findOne({
id: inputs.labelId,
boardId: card.boardId
});
if (!label) {
throw Errors.LABEL_NOT_FOUND;
}
const cardLabel = await sails.helpers
.createCardLabel(card, label, this.req)
.intercept('conflict', () => Errors.CARD_LABEL_EXIST);
return exits.success({
item: cardLabel
});
}
};

View file

@ -0,0 +1,63 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
},
CARD_LABEL_NOT_FOUND: {
notFound: 'Card label is not found'
}
};
module.exports = {
inputs: {
cardId: {
type: 'number',
required: true
},
labelId: {
type: 'number',
required: true
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
fn: async function(inputs, exits) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
let cardLabel = await CardLabel.findOne({
cardId: inputs.cardId,
labelId: inputs.labelId
});
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
}
cardLabel = await sails.helpers.deleteCardLabel(cardLabel, board, this.req);
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
}
return exits.success({
item: cardLabel
});
}
};