({
chatflowid,
chatTypes,
sortOrder = 'ASC',
chatId,
memoryType,
sessionId,
startDate,
endDate,
messageId,
feedback,
feedbackTypes,
activeWorkspaceId,
page = -1,
pageSize = -1
}: GetChatMessageParams)
| 37 | } |
| 38 | |
| 39 | export const utilGetChatMessage = async ({ |
| 40 | chatflowid, |
| 41 | chatTypes, |
| 42 | sortOrder = 'ASC', |
| 43 | chatId, |
| 44 | memoryType, |
| 45 | sessionId, |
| 46 | startDate, |
| 47 | endDate, |
| 48 | messageId, |
| 49 | feedback, |
| 50 | feedbackTypes, |
| 51 | activeWorkspaceId, |
| 52 | page = -1, |
| 53 | pageSize = -1 |
| 54 | }: GetChatMessageParams): Promise<ChatMessage[]> => { |
| 55 | if (!page) page = -1 |
| 56 | if (!pageSize) pageSize = -1 |
| 57 | |
| 58 | const appServer = getRunningExpressApp() |
| 59 | |
| 60 | // Check if chatflow workspaceId is same as activeWorkspaceId |
| 61 | if (activeWorkspaceId) { |
| 62 | const chatflow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({ |
| 63 | id: chatflowid, |
| 64 | workspaceId: activeWorkspaceId |
| 65 | }) |
| 66 | if (!chatflow) { |
| 67 | throw new Error('Unauthorized access') |
| 68 | } |
| 69 | } else { |
| 70 | throw new Error('Unauthorized access') |
| 71 | } |
| 72 | |
| 73 | if (feedback) { |
| 74 | // Handle feedback queries with improved efficiency |
| 75 | return await handleFeedbackQuery({ |
| 76 | chatflowid, |
| 77 | chatTypes, |
| 78 | sortOrder, |
| 79 | chatId, |
| 80 | memoryType, |
| 81 | sessionId, |
| 82 | startDate, |
| 83 | endDate, |
| 84 | messageId, |
| 85 | feedbackTypes, |
| 86 | page, |
| 87 | pageSize |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | let createdDateQuery |
| 92 | |
| 93 | if (startDate || endDate) { |
| 94 | if (startDate && endDate) { |
| 95 | createdDateQuery = Between(new Date(startDate), new Date(endDate)) |
| 96 | } else if (startDate) { |
no test coverage detected