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

46 lines
824 B
JavaScript
Raw Normal View History

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