2022-12-26 21:10:50 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
2022-12-26 21:10:50 +01:00
|
|
|
values: {
|
2021-06-24 01:05:22 +05:00
|
|
|
type: 'ref',
|
2022-12-26 21:10:50 +01:00
|
|
|
custom: valuesValidator,
|
2021-06-24 01:05:22 +05:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async fn(inputs) {
|
2022-12-26 21:10:50 +01:00
|
|
|
const { values } = inputs;
|
|
|
|
|
|
|
|
if (values.user) {
|
|
|
|
values.userId = values.user.id;
|
|
|
|
}
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
const notification = await Notification.create({
|
2022-12-26 21:10:50 +01:00
|
|
|
...values,
|
|
|
|
actionId: values.action.id,
|
|
|
|
cardId: values.action.cardId,
|
2021-06-24 01:05:22 +05:00
|
|
|
}).fetch();
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
sails.sockets.broadcast(`user:${notification.userId}`, 'notificationCreate', {
|
2021-06-24 01:05:22 +05:00
|
|
|
item: notification,
|
|
|
|
});
|
|
|
|
|
|
|
|
return notification;
|
|
|
|
},
|
|
|
|
};
|