Huzaifa1435 commited on
Commit
69956e2
·
1 Parent(s): 0d4e43d

Backend: ride map wallet notification fixes

Browse files
src/controllers/notificationController.js CHANGED
@@ -29,6 +29,34 @@ const getMyNotifications = async (req, res) => {
29
  }
30
  };
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  const markNotificationsRead = async (req, res) => {
33
  try {
34
  const snap = await db
@@ -45,4 +73,4 @@ const markNotificationsRead = async (req, res) => {
45
  }
46
  };
47
 
48
- module.exports = { sendNotification, getMyNotifications, markNotificationsRead };
 
29
  }
30
  };
31
 
32
+ const getNotificationSummary = async (req, res) => {
33
+ try {
34
+ const snap = await db
35
+ .collection('notifications')
36
+ .where('userId', '==', req.user.uid)
37
+ .where('read', '==', false)
38
+ .limit(100)
39
+ .get();
40
+ const byType = {};
41
+ const byScreen = {};
42
+ snap.docs.forEach((doc) => {
43
+ const n = doc.data() || {};
44
+ const type = (n.type || 'general').toString();
45
+ const screen = (n.data?.screen || '').toString();
46
+ byType[type] = (byType[type] || 0) + 1;
47
+ if (screen) byScreen[screen] = (byScreen[screen] || 0) + 1;
48
+ });
49
+ return res.json({
50
+ success: true,
51
+ unreadCount: snap.size,
52
+ byType,
53
+ byScreen,
54
+ });
55
+ } catch (err) {
56
+ return res.status(500).json({ success: false, error: err.message, code: 'NOTIFICATION_SUMMARY_ERROR' });
57
+ }
58
+ };
59
+
60
  const markNotificationsRead = async (req, res) => {
61
  try {
62
  const snap = await db
 
73
  }
74
  };
75
 
76
+ module.exports = { sendNotification, getMyNotifications, getNotificationSummary, markNotificationsRead };
src/routes/notifications.js CHANGED
@@ -3,9 +3,11 @@ const { verifyToken } = require('../middleware/auth');
3
  const {
4
  sendNotification,
5
  getMyNotifications,
 
6
  markNotificationsRead,
7
  } = require('../controllers/notificationController');
8
 
 
9
  router.get('/', verifyToken, getMyNotifications);
10
  router.patch('/read-all', verifyToken, markNotificationsRead);
11
  router.post('/send', verifyToken, sendNotification);
 
3
  const {
4
  sendNotification,
5
  getMyNotifications,
6
+ getNotificationSummary,
7
  markNotificationsRead,
8
  } = require('../controllers/notificationController');
9
 
10
+ router.get('/summary', verifyToken, getNotificationSummary);
11
  router.get('/', verifyToken, getMyNotifications);
12
  router.patch('/read-all', verifyToken, markNotificationsRead);
13
  router.post('/send', verifyToken, sendNotification);
src/utils/notificationHelper.js CHANGED
@@ -8,6 +8,8 @@ const HIGH_PRIORITY_TYPES = new Set([
8
  'ride_started',
9
  'ride_completed',
10
  'deal_message',
 
 
11
  'customer_request',
12
  'customer_offer',
13
  'customer_counter',
 
8
  'ride_started',
9
  'ride_completed',
10
  'deal_message',
11
+ 'new_ride',
12
+ 'passenger_boarded',
13
  'customer_request',
14
  'customer_offer',
15
  'customer_counter',