2023-05-09 09:34:32 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getList', {
|
|
|
|
description: 'Get list of the available and active notification subscriptions',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
description: 'User to modify',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/getList`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getList = async(id, options) => {
|
2023-11-08 13:56:47 +00:00
|
|
|
const activeNotificationsMap = new Map();
|
2023-05-09 09:34:32 +00:00
|
|
|
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2023-11-08 13:56:47 +00:00
|
|
|
const availableNotificationsMap = await Self.getAvailable(id, myOptions);
|
|
|
|
const activeNotifications = await Self.app.models.NotificationSubscription.find({
|
2023-05-15 12:34:32 +00:00
|
|
|
fields: ['id', 'notificationFk'],
|
2023-05-11 05:18:58 +00:00
|
|
|
include: {relation: 'notification'},
|
|
|
|
where: {userFk: id}
|
|
|
|
}, myOptions);
|
|
|
|
|
2023-11-08 13:56:47 +00:00
|
|
|
for (active of activeNotifications) {
|
|
|
|
activeNotificationsMap.set(active.notificationFk, {
|
|
|
|
id: active.id,
|
|
|
|
notificationFk: active.notificationFk,
|
|
|
|
name: active.notification().name,
|
|
|
|
description: active.notification().description,
|
|
|
|
active: true
|
2023-05-11 05:18:58 +00:00
|
|
|
});
|
2023-11-08 13:56:47 +00:00
|
|
|
availableNotificationsMap.delete(active.notificationFk);
|
2023-05-10 12:13:38 +00:00
|
|
|
}
|
2023-05-09 09:34:32 +00:00
|
|
|
|
2023-11-08 13:56:47 +00:00
|
|
|
return {
|
|
|
|
active: [...activeNotificationsMap.entries()],
|
|
|
|
available: [...availableNotificationsMap.entries()]
|
|
|
|
};
|
2023-05-09 09:34:32 +00:00
|
|
|
};
|
|
|
|
};
|