Notification system enhanced
- Base for notifcation center - Show text in map if no data is available
This commit is contained in:
22
backend/endpoints/notification.ts
Normal file
22
backend/endpoints/notification.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Response } from "express";
|
||||
import { LivebeatRequest } from "../lib/request";
|
||||
import { Notification } from "../models/notifications/notification.model";
|
||||
|
||||
export async function getNotification(req: LivebeatRequest, res: Response) {
|
||||
let limit = req.query.limit;
|
||||
let skip = req.query.skip;
|
||||
|
||||
if (limit === undefined) { limit = '100' };
|
||||
if (skip === undefined) { skip = '0' };
|
||||
|
||||
try {
|
||||
const notifications = await Notification.find({ user: req.user?._id }).limit(Number(limit)).sort({ _id: -1 });
|
||||
res.status(200).send(notifications);
|
||||
} catch(error: any) {
|
||||
if (error instanceof TypeError) {
|
||||
res.status(400).send({ message: "'Limit' has to be a number" });
|
||||
} else {
|
||||
res.status(500).send({ message: "An error occured while processing your request" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user