Notif system
This commit is contained in:
@@ -7,6 +7,8 @@ const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
const UserGPS = require('../models/GPS.User')
|
||||
const { generateRandomDigits
|
||||
} = require('../plugins/controllersHelperFunctions')
|
||||
const Notification = require('../models/GPS.Notif')
|
||||
|
||||
module.exports.login_with_pass = [
|
||||
[
|
||||
body('username')
|
||||
@@ -55,6 +57,10 @@ module.exports.login_with_pass = [
|
||||
})
|
||||
user.token = token
|
||||
await user.save()
|
||||
await Notification.create({
|
||||
userID:user._id,
|
||||
content:"test"
|
||||
})
|
||||
return res.status(200).json({ token })
|
||||
} catch (err) {
|
||||
return res.status(422).json({
|
||||
@@ -90,6 +96,10 @@ module.exports.login_with_otp = [
|
||||
})
|
||||
user.otp = generateRandomDigits(6)
|
||||
user.save()
|
||||
await Notification.create({
|
||||
userID:user._id,
|
||||
content:"test"
|
||||
})
|
||||
return res.status(200).json({ token })
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const { param, validationResult } = require('express-validator')
|
||||
const { _sr } = require('../plugins/serverResponses')
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
const Notification = require('../models/GPS.Notif')
|
||||
|
||||
|
||||
module.exports.setSeen = [
|
||||
[
|
||||
param('id').notEmpty().isMongoId().withMessage('ایدی را وارد یا تصحیح کنید')
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const notif = await Notification.findById(req.params.id)
|
||||
if (!notif || notif.userID !== req.userID) {
|
||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||
} else {
|
||||
notif.read = true;
|
||||
notif.save()
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.setSeenAll = [
|
||||
async (req, res) => {
|
||||
await Notification.updateMany(
|
||||
{ userID: req.userID },
|
||||
{ seen: true }
|
||||
)
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user