(req: Request, res: Response, next: NextFunction)
| 7 | import { checkUsageLimit } from '../../utils/quotaUsage' |
| 8 | |
| 9 | const createAssistant = async (req: Request, res: Response, next: NextFunction) => { |
| 10 | try { |
| 11 | if (!req.body) { |
| 12 | throw new InternalFlowiseError( |
| 13 | StatusCodes.PRECONDITION_FAILED, |
| 14 | `Error: assistantsController.createAssistant - body not provided!` |
| 15 | ) |
| 16 | } |
| 17 | const body = req.body |
| 18 | const orgId = req.user?.activeOrganizationId |
| 19 | if (!orgId) { |
| 20 | throw new InternalFlowiseError( |
| 21 | StatusCodes.NOT_FOUND, |
| 22 | `Error: assistantsController.createAssistant - organization ${orgId} not found!` |
| 23 | ) |
| 24 | } |
| 25 | const workspaceId = req.user?.activeWorkspaceId |
| 26 | if (!workspaceId) { |
| 27 | throw new InternalFlowiseError( |
| 28 | StatusCodes.NOT_FOUND, |
| 29 | `Error: assistantsController.createAssistant - workspace ${workspaceId} not found!` |
| 30 | ) |
| 31 | } |
| 32 | const subscriptionId = req.user?.activeOrganizationSubscriptionId || '' |
| 33 | |
| 34 | const existingAssistantCount = await assistantsService.getAssistantsCountByOrganization(body.type, orgId) |
| 35 | const newAssistantCount = 1 |
| 36 | await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingAssistantCount + newAssistantCount) |
| 37 | |
| 38 | const apiResponse = await assistantsService.createAssistant(body, orgId, workspaceId) |
| 39 | |
| 40 | return res.json(apiResponse) |
| 41 | } catch (error) { |
| 42 | next(error) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | const deleteAssistant = async (req: Request, res: Response, next: NextFunction) => { |
| 47 | try { |
nothing calls this directly
no test coverage detected