mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 21:29:43 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
52
server/api/helpers/create-action.js
Normal file
52
server/api/helpers/create-action.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
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);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue