(chatflowId: string, workspaceId?: string)
| 278 | } |
| 279 | |
| 280 | const getChatflowById = async (chatflowId: string, workspaceId?: string): Promise<any> => { |
| 281 | try { |
| 282 | if (!isValidUUID(chatflowId)) { |
| 283 | throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, ChatflowErrorMessage.INVALID_CHATFLOW_ID) |
| 284 | } |
| 285 | const appServer = getRunningExpressApp() |
| 286 | const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).findOne({ |
| 287 | where: { |
| 288 | id: chatflowId, |
| 289 | ...(workspaceId ? { workspaceId } : {}) |
| 290 | } |
| 291 | }) |
| 292 | if (!dbResponse) { |
| 293 | throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} not found in the database!`) |
| 294 | } |
| 295 | return dbResponse |
| 296 | } catch (error) { |
| 297 | if (error instanceof InternalFlowiseError) { |
| 298 | throw error |
| 299 | } |
| 300 | throw new InternalFlowiseError( |
| 301 | StatusCodes.INTERNAL_SERVER_ERROR, |
| 302 | `Error: chatflowsService.getChatflowById - ${getErrorMessage(error)}` |
| 303 | ) |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** Resolves a chatflow only if it belongs to the given workspace; rejects when workspaceId is missing (prevents unscoped lookup). */ |
| 308 | const getChatflowByIdForWorkspace = async (chatflowId: string, workspaceId: string | undefined): Promise<any> => { |
no test coverage detected