(params: {
chatflowid: string
chatTypes?: ChatType[]
sortOrder: string
chatId?: string
memoryType?: string
sessionId?: string
startDate?: string
endDate?: string
messageId?: string
feedbackTypes?: ChatMessageRatingType[]
page: number
pageSize: number
})
| 122 | } |
| 123 | |
| 124 | async function handleFeedbackQuery(params: { |
| 125 | chatflowid: string |
| 126 | chatTypes?: ChatType[] |
| 127 | sortOrder: string |
| 128 | chatId?: string |
| 129 | memoryType?: string |
| 130 | sessionId?: string |
| 131 | startDate?: string |
| 132 | endDate?: string |
| 133 | messageId?: string |
| 134 | feedbackTypes?: ChatMessageRatingType[] |
| 135 | page: number |
| 136 | pageSize: number |
| 137 | }): Promise<ChatMessage[]> { |
| 138 | const { |
| 139 | chatflowid, |
| 140 | chatTypes, |
| 141 | sortOrder, |
| 142 | chatId, |
| 143 | memoryType, |
| 144 | sessionId, |
| 145 | startDate, |
| 146 | endDate, |
| 147 | messageId, |
| 148 | feedbackTypes, |
| 149 | page, |
| 150 | pageSize |
| 151 | } = params |
| 152 | |
| 153 | const appServer = getRunningExpressApp() |
| 154 | |
| 155 | // For specific session/message queries, no pagination needed |
| 156 | if (sessionId || messageId) { |
| 157 | return await getMessagesWithFeedback(params, false) |
| 158 | } |
| 159 | |
| 160 | // For paginated queries, handle session-based pagination efficiently |
| 161 | if (page > -1 && pageSize > -1) { |
| 162 | // First get session IDs with pagination |
| 163 | const sessionQuery = appServer.AppDataSource.getRepository(ChatMessage) |
| 164 | .createQueryBuilder('chat_message') |
| 165 | .select('chat_message.sessionId', 'sessionId') |
| 166 | .where('chat_message.chatflowid = :chatflowid', { chatflowid }) |
| 167 | |
| 168 | // Apply basic filters |
| 169 | if (chatTypes && chatTypes.length > 0) { |
| 170 | sessionQuery.andWhere('chat_message.chatType IN (:...chatTypes)', { chatTypes }) |
| 171 | } |
| 172 | if (chatId) { |
| 173 | sessionQuery.andWhere('chat_message.chatId = :chatId', { chatId }) |
| 174 | } |
| 175 | if (memoryType) { |
| 176 | sessionQuery.andWhere('chat_message.memoryType = :memoryType', { memoryType }) |
| 177 | } |
| 178 | if (startDate && typeof startDate === 'string') { |
| 179 | sessionQuery.andWhere('chat_message.createdDate >= :startDateTime', { |
| 180 | startDateTime: new Date(startDate) |
| 181 | }) |
no test coverage detected