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, }; // Выполнение запроса