From 5698a626186e56827afea4f86df4b3d6d40ca8d8 Mon Sep 17 00:00:00 2001 From: Ilango Date: Tue, 27 Feb 2024 15:35:49 +0530 Subject: [PATCH] Fix date filters not working --- packages/server/src/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index f57f6c00..893f5054 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -1542,14 +1542,11 @@ export class App { .where('chat_message.chatflowid = :chatflowid', { chatflowid }) .andWhere(chatType ? 'chat_message.chatType = :chatType' : 'TRUE', { chatType }) .andWhere(chatId ? 'chat_message.chatId = :chatId' : 'TRUE', { chatId }) - .andWhere(memoryType ? 'chat_message.memoryType = :memoryType' : 'TRUE', { - memoryType: memoryType ?? (chatId ? IsNull() : undefined) - }) - .andWhere(sessionId ? 'chat_message.sessionId = :sessionId' : 'TRUE', { - sessionId: sessionId ?? (chatId ? IsNull() : undefined) - }) - .andWhere(fromDate && toDate ? 'chat_message.createdDate = :createdDate' : 'TRUE', { - createdDate: toDate && fromDate ? Between(fromDate, toDate) : undefined + .andWhere(memoryType ? 'chat_message.memoryType = :memoryType' : 'TRUE', { memoryType }) + .andWhere(sessionId ? 'chat_message.sessionId = :sessionId' : 'TRUE', { sessionId }) + .andWhere('chat_message.createdDate BETWEEN :fromDate AND :toDate', { + fromDate: fromDate ?? new Date().setMonth(new Date().getMonth() - 1), + toDate: toDate ?? new Date() }) .orderBy('chat_message.createdDate', sortOrder === 'DESC' ? 'DESC' : 'ASC') .getMany()