(req: Request, res: Response, next: NextFunction)
| 144 | } |
| 145 | |
| 146 | const saveChatflow = async (req: Request, res: Response, next: NextFunction) => { |
| 147 | try { |
| 148 | if (!req.body) { |
| 149 | throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.saveChatflow - body not provided!`) |
| 150 | } |
| 151 | const orgId = req.user?.activeOrganizationId |
| 152 | if (!orgId) { |
| 153 | throw new InternalFlowiseError( |
| 154 | StatusCodes.NOT_FOUND, |
| 155 | `Error: chatflowsController.saveChatflow - organization ${orgId} not found!` |
| 156 | ) |
| 157 | } |
| 158 | const workspaceId = req.user?.activeWorkspaceId |
| 159 | if (!workspaceId) { |
| 160 | throw new InternalFlowiseError( |
| 161 | StatusCodes.NOT_FOUND, |
| 162 | `Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!` |
| 163 | ) |
| 164 | } |
| 165 | const subscriptionId = req.user?.activeOrganizationSubscriptionId || '' |
| 166 | const body = req.body |
| 167 | |
| 168 | const existingChatflowCount = await chatflowsService.getAllChatflowsCountByOrganization(body.type, orgId) |
| 169 | const newChatflowCount = 1 |
| 170 | await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingChatflowCount + newChatflowCount) |
| 171 | |
| 172 | const newChatFlow = new ChatFlow() |
| 173 | Object.assign(newChatFlow, stripProtectedFields(body)) |
| 174 | |
| 175 | newChatFlow.workspaceId = workspaceId |
| 176 | const apiResponse = await chatflowsService.saveChatflow( |
| 177 | newChatFlow, |
| 178 | orgId, |
| 179 | workspaceId, |
| 180 | subscriptionId, |
| 181 | getRunningExpressApp().usageCacheManager |
| 182 | ) |
| 183 | |
| 184 | return res.json(apiResponse) |
| 185 | } catch (error) { |
| 186 | next(error) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | const updateChatflow = async (req: Request, res: Response, next: NextFunction) => { |
| 191 | try { |
nothing calls this directly
no test coverage detected