fix: edit form fields and update form submission logic #21

Merged
kailasdevdas merged 1 commits from fix/news-media-UI into dev 2026-05-05 06:44:06 +00:00
2 changed files with 22 additions and 23 deletions
Showing only changes of commit d847789564 - Show all commits
@@ -4,8 +4,8 @@ import prisma from "../prisma/client.js";
export const getAllNews = async (req, res) => { export const getAllNews = async (req, res) => {
try { try {
const page = parseInt(req.query.page) || 1; const page = req.query.page ? parseInt(req.query.page) : null;
const limit = parseInt(req.query.limit) || 10; const limit = req.query.limit ? parseInt(req.query.limit) : null;
const search = req.query.search?.trim() || ""; const search = req.query.search?.trim() || "";
const includeImages = { const includeImages = {
@@ -25,7 +25,8 @@ export const getAllNews = async (req, res) => {
...searchFilter, ...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([ const [news, total] = await Promise.all([
prisma.newsMedia.findMany({ prisma.newsMedia.findMany({
@@ -33,7 +34,7 @@ export const getAllNews = async (req, res) => {
include: includeImages, include: includeImages,
orderBy: { createdAt: "desc" }, orderBy: { createdAt: "desc" },
skip, skip,
take: limit, take,
}), }),
prisma.newsMedia.count({ prisma.newsMedia.count({
where: whereCondition, where: whereCondition,
@@ -59,9 +60,9 @@ export const getAllNews = async (req, res) => {
data: response, data: response,
meta: { meta: {
total, total,
page, page: page || 1,
limit, limit: limit || total,
totalPages: Math.ceil(total / limit), totalPages: limit ? Math.ceil(total / limit) : 1,
}, },
}); });
} catch (error) { } catch (error) {
+14 -16
View File
@@ -136,10 +136,19 @@ export default function NewsPage() {
async function handleSubmit() { async function handleSubmit() {
try { try {
const submissionData = {
...form,
firstPara: form.headline,
content:
form.secondPara.length > 100
? form.secondPara.substring(0, 100) + "..."
: form.secondPara,
};
if (editing) { if (editing) {
await updateNewsApi(editing.Id, form); await updateNewsApi(editing.Id, submissionData);
} else { } else {
await createNewsApi(form); await createNewsApi(submissionData);
} }
setOpenModal(false); setOpenModal(false);
fetchAll(); fetchAll();
@@ -411,21 +420,10 @@ export default function NewsPage() {
</div> </div>
</div> </div>
<div className="space-y-1"> <div className="space-y-1">
<label className="text-sm font-semibold">Intro Paragraph</label> <label className="text-sm font-semibold">Story Content</label>
<Textarea <Textarea
name="firstPara" name="secondPara"
value={form.firstPara} value={form.secondPara}
onChange={handleChange}
className="min-h-[100px] text-base"
/>
</div>
<div className="space-y-1">
<label className="text-sm font-semibold">
Full Story Content
</label>
<Textarea
name="content"
value={form.content}
onChange={handleChange} onChange={handleChange}
className="min-h-[200px] text-base" className="min-h-[200px] text-base"
/> />