From d8477895641d1f77dbbf017162b931270b10d5a2 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Tue, 5 May 2026 10:48:18 +0530 Subject: [PATCH] fix: edit form fields and update form submission logic --- .../src/controllers/newsMedia.controller.js | 15 +++++----- frontend/src/pages/newsMedia.tsx | 30 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/backend/src/controllers/newsMedia.controller.js b/backend/src/controllers/newsMedia.controller.js index 4bf935f..052e181 100644 --- a/backend/src/controllers/newsMedia.controller.js +++ b/backend/src/controllers/newsMedia.controller.js @@ -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) { diff --git a/frontend/src/pages/newsMedia.tsx b/frontend/src/pages/newsMedia.tsx index 3e10021..e9427bc 100644 --- a/frontend/src/pages/newsMedia.tsx +++ b/frontend/src/pages/newsMedia.tsx @@ -136,10 +136,19 @@ export default function NewsPage() { async function handleSubmit() { try { + const submissionData = { + ...form, + firstPara: form.headline, + content: + form.secondPara.length > 100 + ? form.secondPara.substring(0, 100) + "..." + : form.secondPara, + }; + if (editing) { - await updateNewsApi(editing.Id, form); + await updateNewsApi(editing.Id, submissionData); } else { - await createNewsApi(form); + await createNewsApi(submissionData); } setOpenModal(false); fetchAll(); @@ -411,21 +420,10 @@ export default function NewsPage() {
- +