Skip to content

Commit

Permalink
Allow no array
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsm412 committed Jul 10, 2024
1 parent e5beb92 commit e1b9cd0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 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
23 changes: 19 additions & 4 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 { publicAddress } = req.user;
const { ids } = req.body;
const result = await Notification.updateMany({
_id: { $in: ids },
}, { $set: { read: true } });
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 { publicAddress } = req.user;
const { ids } = req.body;
const result = await Notification.deleteMany({ _id: { $in: ids } });
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 e1b9cd0

Please sign in to comment.