WS finial test
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user