2022-07-19 13:17:22 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('send', {
|
|
|
|
description: 'Send notifications from queue',
|
2022-07-20 12:54:50 +00:00
|
|
|
accessType: 'READ',
|
2022-07-19 13:17:22 +00:00
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/send`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.send = async() => {
|
2022-07-20 12:54:50 +00:00
|
|
|
const status = 'pending';
|
2022-07-19 13:17:22 +00:00
|
|
|
|
2022-07-20 12:54:50 +00:00
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
const notificationQueue = await Self.app.models.NotificationQueue.find({
|
|
|
|
where: {code: status},
|
|
|
|
include: [{
|
|
|
|
relation: 'notificationSubscription'
|
|
|
|
}]
|
|
|
|
}, myOptions);
|
|
|
|
|
|
|
|
console.log(notificationQueue);
|
2022-07-19 13:17:22 +00:00
|
|
|
};
|
|
|
|
};
|