mirror of
https://github.com/plankanban/planka.git
synced 2025-08-10 07:55:27 +02:00
refactor: extract code from controllers to helpers
This commit is contained in:
parent
4e02efa0ee
commit
b1ad354815
8 changed files with 35 additions and 36 deletions
|
@ -1,5 +1,4 @@
|
|||
const moment = require('moment');
|
||||
const services = require('../../services/slack');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
|
@ -110,12 +109,6 @@ module.exports = {
|
|||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT);
|
||||
|
||||
const cardUrl = services.buildCardUrl(card);
|
||||
const messageText = `${cardUrl} was created by ${currentUser.name} in *${list.name}*`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
throw new Error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
|
@ -56,11 +54,6 @@ module.exports = {
|
|||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
const messageText = `*${card.name}* was deleted by ${currentUser.name}`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
throw new Error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const moment = require('moment');
|
||||
const services = require('../../services/slack');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
|
@ -176,8 +175,6 @@ module.exports = {
|
|||
'isSubscribed',
|
||||
]);
|
||||
|
||||
const cardPositionBefore = card.position;
|
||||
|
||||
card = await sails.helpers.cards.updateOne
|
||||
.with({
|
||||
board,
|
||||
|
@ -198,17 +195,6 @@ module.exports = {
|
|||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardPositionAfter = card.position;
|
||||
const cardMoved = cardPositionBefore !== cardPositionAfter;
|
||||
|
||||
if (cardMoved) {
|
||||
const cardUrl = services.buildCardUrl(card);
|
||||
const messageText = `${cardUrl} was moved by ${currentUser.name} to *${nextList.name}*`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
throw new Error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
item: card,
|
||||
};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
|
@ -66,12 +64,6 @@ module.exports = {
|
|||
request: this.req,
|
||||
});
|
||||
|
||||
const cardUrl = services.buildCardUrl(card);
|
||||
const messageText = `*${currentUser.name}* commented on ${cardUrl}:\n>${inputs.text}`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
throw new Error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
|
||||
return {
|
||||
item: action,
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
|
@ -67,6 +69,12 @@ module.exports = {
|
|||
),
|
||||
);
|
||||
|
||||
const cardUrl = services.buildCardUrl(values.card);
|
||||
const messageText = `*${inputs.values.user.name}* commented on ${cardUrl}:\n>${values.data.text}`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
sails.log.error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
|
||||
return action;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
|
@ -111,6 +113,12 @@ module.exports = {
|
|||
board: inputs.board,
|
||||
});
|
||||
|
||||
const cardUrl = services.buildCardUrl(card);
|
||||
const messageText = `${cardUrl} was created by ${values.creatorUser.name} in *${values.list.name}*`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
sails.log.error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
|
||||
return card;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -21,6 +23,11 @@ module.exports = {
|
|||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
const messageText = `*${card.name}* was deleted by ${inputs.request.name}`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
sails.log.error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
}
|
||||
|
||||
return card;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const services = require('../../services/slack');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
|
@ -269,6 +271,16 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
const cardMoved = inputs.values.list !== undefined;
|
||||
|
||||
if (cardMoved) {
|
||||
const cardUrl = services.buildCardUrl(card);
|
||||
const messageText = `${cardUrl} was moved by ${inputs.user.name} to *${inputs.list.name}*`;
|
||||
services.sendSlackMessage(messageText).catch((error) => {
|
||||
sails.log.error('Failed to send Slack message:', error.message);
|
||||
});
|
||||
}
|
||||
|
||||
return card;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue