-
Notifications
You must be signed in to change notification settings - Fork 1
/
NotifyController.js
35 lines (29 loc) · 1.01 KB
/
NotifyController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const Notification = require("../models/NotifyModel");
const ErrorHandler = require("../utils/errorhandler");
const catchAsyncErrors = require("../middleware/catchAsyncErrors");
// Create Notification
exports.createNotification = catchAsyncErrors(async (req, res, next) => {
const { Title, Description } = req.body;
const notify1 = await Notification.find({ Title: Title, Description: Description })
if (notify1 && Object.keys(notify1).length) {
res.status(201).json({
success: false,
message: "Notification already exists"
})
}
else {
const notification = await Notification.create(req.body);
res.status(201).json({
success: true,
notification
})
}
});
// Get All Notifications
exports.getAllNotifications = catchAsyncErrors(async (req, res) => {
const notifications = await Notification.find().sort({"PostedDate" : -1});
res.status(200).json({
success: true,
notifications
});
});