Skip to content

Commit

Permalink
Merge pull request rairprotocol#108 from rairprotocol/107-notificatio…
Browse files Browse the repository at this point in the history
…ns-mark-all-as-read-delete-all

Optional array of IDs to mark as read/delete all
  • Loading branch information
sarora180673 authored Jul 10, 2024
2 parents 3460441 + f54b801 commit 0f9a037
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
7 changes: 6 additions & 1 deletion rair-node/bin/api/notifications/notifications.Controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const express = require('express');
const { requireUserSession, validation } = require('../../middleware');
const { markNotificationAsRead, getSingleNotification, listNotifications, deleteNotification } = require('./notifications.Service');
const {
markNotificationAsRead,
getSingleNotification,
listNotifications,
deleteNotification,
} = require('./notifications.Service');

const router = express.Router();

Expand Down
27 changes: 21 additions & 6 deletions rair-node/bin/api/notifications/notifications.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ module.exports = {
},
markNotificationAsRead: async (req, res, next) => {
try {
const { ids } = req.body;
const result = await Notification.updateMany({
_id: { $in: ids },
}, { $set: { read: true } });
const { publicAddress } = req.user;
const { ids = [] } = req.body;
const filter = {
user: publicAddress,
};
if (ids?.length) {
filter._id = { $in: ids };
}
const result = await Notification.updateMany(
filter,
{ $set: { read: true } },
);
return res.json({
success: true,
updated: result.modifiedCount,
Expand All @@ -108,8 +116,15 @@ module.exports = {
},
deleteNotification: async (req, res, next) => {
try {
const { ids } = req.body;
const result = await Notification.deleteMany({ _id: { $in: ids } });
const { publicAddress } = req.user;
const { ids = [] } = req.body;
const filter = {
user: publicAddress,
};
if (ids?.length) {
filter._id = { $in: ids };
}
const result = await Notification.deleteMany(filter);
return res.json({
success: true,
deleted: result.deletedCount,
Expand Down

0 comments on commit 0f9a037

Please sign in to comment.