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

Initial commit

This commit is contained in:
Maksim Eltyshev 2019-08-31 04:07:25 +05:00
commit 36fe34e8e1
583 changed files with 91539 additions and 0 deletions

View file

@ -0,0 +1,52 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
};
module.exports = {
inputs: {
cardId: {
type: 'number',
required: true
},
text: {
type: 'string',
required: true
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
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 values = {
type: 'commentCard',
data: _.pick(inputs, ['text'])
};
const action = await sails.helpers.createAction(card, currentUser, values);
return exits.success({
item: action
});
}
};

View file

@ -0,0 +1,56 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found'
}
};
module.exports = {
inputs: {
id: {
type: 'number',
required: true
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
fn: async function(inputs, exits) {
const { currentUser } = this.req;
const criteria = {
id: inputs.id,
type: 'commentCard'
};
if (!currentUser.isAdmin) {
criteria.userId = currentUser.id;
}
let { action, board, project } = await sails.helpers
.getActionToProjectPath(criteria)
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
action = await sails.helpers.deleteAction(action, board, this.req);
if (!action) {
throw Errors.COMMENT_ACTION_NOT_FOUND;
}
return exits.success({
item: action
});
}
};

View file

@ -0,0 +1,59 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found'
}
};
module.exports = {
inputs: {
id: {
type: 'number',
required: true
},
text: {
type: 'string',
isNotEmptyString: true
}
},
exits: {
notFound: {
responseType: 'notFound'
}
},
fn: async function(inputs, exits) {
const { currentUser } = this.req;
let { action, board, project } = await sails.helpers
.getActionToProjectPath({
id: inputs.id,
type: 'commentCard',
userId: currentUser.id
})
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
);
if (!isUserMemberForProject) {
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
}
const values = {
data: _.pick(inputs, ['text'])
};
action = await sails.helpers.updateAction(action, values, board, this.req);
if (!action) {
throw Errors.COMMENT_ACTION_NOT_FOUND;
}
return exits.success({
item: action
});
}
};