|
1 | 1 | import { ICommonObject, removeFolderFromStorage } from 'flowise-components' |
2 | 2 | import { StatusCodes } from 'http-status-codes' |
3 | | -import { In } from 'typeorm' |
| 3 | +import { Brackets, In } from 'typeorm' |
4 | 4 | import { validate as isValidUUID } from 'uuid' |
5 | 5 | import { ChatflowType, IReactFlowObject } from '../../Interface' |
6 | 6 | import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../../Interface.Metrics' |
@@ -220,16 +220,21 @@ const getAllChatflowsCount = async (type?: ChatflowType, workspaceId?: string): |
220 | 220 | } |
221 | 221 | } |
222 | 222 |
|
223 | | -const getChatflowByApiKey = async (apiKeyId: string, keyonly?: unknown): Promise<any> => { |
| 223 | +const getChatflowByApiKey = async (apiKeyId: string, workspaceId: string, keyonly?: unknown): Promise<any> => { |
224 | 224 | try { |
225 | 225 | // Here we only get chatflows that are bounded by the apikeyid and chatflows that are not bounded by any apikey |
226 | 226 | const appServer = getRunningExpressApp() |
227 | 227 | let query = appServer.AppDataSource.getRepository(ChatFlow) |
228 | 228 | .createQueryBuilder('cf') |
229 | | - .where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId }) |
230 | | - if (keyonly === undefined) { |
231 | | - query = query.orWhere('cf.apikeyid IS NULL').orWhere('cf.apikeyid = ""') |
232 | | - } |
| 229 | + .where('cf.workspaceId = :workspaceId', { workspaceId }) |
| 230 | + .andWhere( |
| 231 | + new Brackets((qb) => { |
| 232 | + qb.where('cf.apikeyid = :apikeyid', { apikeyid: apiKeyId }) |
| 233 | + if (keyonly === undefined) { |
| 234 | + qb.orWhere('cf.apikeyid IS NULL').orWhere('cf.apikeyid = ""') |
| 235 | + } |
| 236 | + }) |
| 237 | + ) |
233 | 238 |
|
234 | 239 | const dbResponse = await query.orderBy('cf.name', 'ASC').getMany() |
235 | 240 | if (dbResponse.length < 1) { |
|
0 commit comments