From d9ab710be482e1fad449cd32c8c29118c1fa96c2 Mon Sep 17 00:00:00 2001 From: anibilag Date: Tue, 17 Jun 2025 23:27:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=20=D0=BF=D0=BE=20=D0=B4=D0=B0=D1=82=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/articles/controllers/search.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/routes/articles/controllers/search.ts b/src/routes/articles/controllers/search.ts index e6ee337..6f915c1 100644 --- a/src/routes/articles/controllers/search.ts +++ b/src/routes/articles/controllers/search.ts @@ -4,9 +4,24 @@ import { AuthorRole, Prisma } from '@prisma/client'; export async function searchArticles(req: Request, res: Response) { try { - const { q, author, role, page = 1, limit = 9 } = req.query; + const { q, author, role, date, page = 1, limit = 9 } = req.query; const skip = ((Number(page) || 1) - 1) * (Number(limit) || 9); + // Подготовка условия по дате + let dateCondition: Prisma.ArticleWhereInput = {}; + if (typeof date === 'string' && date.trim()) { + const selectedDate = new Date(date); + const nextDate = new Date(selectedDate); + nextDate.setDate(selectedDate.getDate() + 1); + + dateCondition = { + publishedAt: { + gte: selectedDate, + lt: nextDate, + }, + }; + } + // Формируем where-условие const where: Prisma.ArticleWhereInput = { ...(typeof q === 'string' && q.trim() @@ -30,6 +45,7 @@ export async function searchArticles(req: Request, res: Response) { }, } : {}), + ...dateCondition, }; // Выполнение запроса