1.0.2 #22

Merged
ashir merged 4 commits from dev into main 2026-05-05 12:29:11 +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) => {
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) {
+14 -16
View File
@@ -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() {
</div>
</div>
<div className="space-y-1">
<label className="text-sm font-semibold">Intro Paragraph</label>
<label className="text-sm font-semibold">Story Content</label>
<Textarea
name="firstPara"
value={form.firstPara}
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}
name="secondPara"
value={form.secondPara}
onChange={handleChange}
className="min-h-[200px] text-base"
/>