feat: add page newMedia

This commit is contained in:
ARJUN S THAMPI
2026-03-26 11:20:03 +05:30
parent 24a8bc4113
commit 2ed1bee149
5 changed files with 448 additions and 3 deletions
@@ -4,9 +4,19 @@ import prisma from "../prisma/client.js";
export const getAllNews = async (req, res) => {
try {
const news = await prisma.newsMedia.findMany({
orderBy: { createdAt: "desc" },
});
const page = parseInt(req.query.page) || 1;
const limit = parseInt(req.query.limit) || 10;
const skip = (page - 1) * limit;
const [news, total] = await Promise.all([
prisma.newsMedia.findMany({
orderBy: { createdAt: "desc" },
skip,
take: limit,
}),
prisma.newsMedia.count(),
]);
const response = news.map((n) => ({
Id: n.id.toString(),
@@ -21,6 +31,12 @@ export const getAllNews = async (req, res) => {
return res.status(200).json({
success: true,
data: response,
meta: {
total,
page,
limit,
totalPages: Math.ceil(total / limit),
},
});
} catch (error) {
console.error(error);