fix: edit form fields and update form submission logic
This commit is contained in:
@@ -4,8 +4,8 @@ import prisma from "../prisma/client.js";
|
||||
|
||||
export const getAllNews = async (req, res) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const limit = parseInt(req.query.limit) || 10;
|
||||
const page = req.query.page ? parseInt(req.query.page) : null;
|
||||
const limit = req.query.limit ? parseInt(req.query.limit) : null;
|
||||
const search = req.query.search?.trim() || "";
|
||||
|
||||
const includeImages = {
|
||||
@@ -25,7 +25,8 @@ export const getAllNews = async (req, res) => {
|
||||
...searchFilter,
|
||||
};
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
const skip = page && limit ? (page - 1) * limit : undefined;
|
||||
const take = limit ? limit : undefined;
|
||||
|
||||
const [news, total] = await Promise.all([
|
||||
prisma.newsMedia.findMany({
|
||||
@@ -33,7 +34,7 @@ export const getAllNews = async (req, res) => {
|
||||
include: includeImages,
|
||||
orderBy: { createdAt: "desc" },
|
||||
skip,
|
||||
take: limit,
|
||||
take,
|
||||
}),
|
||||
prisma.newsMedia.count({
|
||||
where: whereCondition,
|
||||
@@ -59,9 +60,9 @@ export const getAllNews = async (req, res) => {
|
||||
data: response,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
page: page || 1,
|
||||
limit: limit || total,
|
||||
totalPages: limit ? Math.ceil(total / limit) : 1,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user