2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn() {
|
2019-08-31 04:07:25 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const notifications = await sails.helpers.users.getNotifications(currentUser.id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const actionIds = sails.helpers.utils.mapRecords(notifications, 'actionId');
|
|
|
|
const actions = await sails.helpers.actions.getMany(actionIds);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const userIds = sails.helpers.utils.mapRecords(actions, 'userId', true);
|
|
|
|
const users = await sails.helpers.users.getMany(userIds, true);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const cardIds = sails.helpers.utils.mapRecords(notifications, 'cardId');
|
|
|
|
const cards = await sails.helpers.cards.getMany(cardIds);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2019-08-31 04:07:25 +05:00
|
|
|
items: notifications,
|
|
|
|
included: {
|
|
|
|
users,
|
|
|
|
cards,
|
2019-11-05 18:01:42 +05:00
|
|
|
actions,
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|