1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-20 05:39:43 +02:00
planka/server/api/helpers/notifications/create-one.js

30 lines
604 B
JavaScript
Raw Normal View History

module.exports = {
inputs: {
userOrId: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value),
required: true,
},
action: {
type: 'ref',
required: true,
},
},
async fn(inputs) {
const { userId = inputs.userOrId } = inputs.userOrId;
const notification = await Notification.create({
userId,
actionId: inputs.action.id,
cardId: inputs.action.cardId,
}).fetch();
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
item: notification,
});
return notification;
},
};