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