WS finial test

This commit is contained in:
Mr Swift
2024-09-30 12:55:01 +03:30
parent b1f792f493
commit 9fa38c8adb
6 changed files with 209 additions and 63 deletions
@@ -1,19 +1,48 @@
const Notification = require('../../models/GPS.Notif')
module.exports.getAllNotifs = async socket => {
try {
console.log('4');
module.exports.notifyGPS = async (type, gps_id) => {
const notif = await Notification.find({ userID: socket.userId, read: false }).sort({ updated_at: -1 })
console.log(notif);
socket.emit(`gps:allNotifs`, notif)
} catch (e) {
console.log(e)
}
}
module.exports.notifyGPS = async (type, userId) => {
try {
const io = global._io
const gps = io.of('/gps')
const data = { type }
if (type === 'updateGPSInbox') {
const gpsInbox = await Notification.find({ userID:gps_id, seen: false }).sort({updated_at: -1})
const gpsInbox = await Notification.find({ userID: userId, read: false }).sort({ updated_at: -1 })
data.gpsInbox = gpsInbox
}
gps.to(gps_id.toString()).emit(`GPS:notify`, data)
gps.to(userId.toString()).emit(`gps:notify`, data)
} catch (e) {
console.log(e)
}
}
}
module.exports.fetchNotifications = async (socket) => {
try {
console.log('5');
const notif = await Notification.find({ userID: socket.userId, read: false }).sort({ updated_at: -1 })
console.log(notif);
socket.emit('gps:notifications', notif)
} catch (e) {
console.log(e)
}
}