You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
planka_custom/server/api/helpers/notifications/create-one.js

46 lines
824 B
JavaScript

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