22 lines
847 B
TypeScript
22 lines
847 B
TypeScript
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" });
|
|
}
|
|
}
|
|
} |