1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/create-action.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
card: {
type: 'ref',
required: true
},
user: {
type: 'ref',
required: true
},
values: {
type: 'json',
required: true
}
},
fn: async function(inputs, exits) {
const action = await Action.create({
...inputs.values,
cardId: inputs.card.id,
userId: inputs.user.id
}).fetch();
sails.sockets.broadcast(`board:${inputs.card.boardId}`, 'actionCreate', {
item: action
});
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(
action.cardId,
action.userId
);
userIds.forEach(async userId => {
const notification = await Notification.create({
userId,
actionId: action.id,
cardId: action.cardId
}).fetch();
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
item: notification,
included: {
users: [inputs.user],
cards: [inputs.card],
actions: [action]
}
});
});
return exits.success(action);
}
};