@@ -7,7 +7,7 @@ import { Credential } from '../../database/entities/Credential'
7
7
import { decryptCredentialData , getAppVersion } from '../../utils'
8
8
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
9
9
import { getErrorMessage } from '../../errors/utils'
10
- import { DeleteResult } from 'typeorm'
10
+ import { DeleteResult , QueryRunner } from 'typeorm'
11
11
import { FLOWISE_METRIC_COUNTERS , FLOWISE_COUNTER_STATUS } from '../../Interface.Metrics'
12
12
13
13
const createAssistant = async ( requestBody : any ) : Promise < Assistant > => {
@@ -291,9 +291,10 @@ const updateAssistant = async (assistantId: string, requestBody: any): Promise<A
291
291
}
292
292
}
293
293
294
- const importAssistants = async ( newAssistants : Partial < Assistant > [ ] ) : Promise < any > => {
294
+ const importAssistants = async ( newAssistants : Partial < Assistant > [ ] , queryRunner ?: QueryRunner ) : Promise < any > => {
295
295
try {
296
296
const appServer = getRunningExpressApp ( )
297
+ const repository = queryRunner ? queryRunner . manager . getRepository ( Assistant ) : appServer . AppDataSource . getRepository ( Assistant )
297
298
298
299
// step 1 - check whether array is zero
299
300
if ( newAssistants . length == 0 ) return
@@ -309,7 +310,7 @@ const importAssistants = async (newAssistants: Partial<Assistant>[]): Promise<an
309
310
count += 1
310
311
} )
311
312
312
- const selectResponse = await appServer . AppDataSource . getRepository ( Assistant )
313
+ const selectResponse = await repository
313
314
. createQueryBuilder ( 'assistant' )
314
315
. select ( 'assistant.id' )
315
316
. where ( `assistant.id IN ${ ids } ` )
@@ -329,7 +330,7 @@ const importAssistants = async (newAssistants: Partial<Assistant>[]): Promise<an
329
330
} )
330
331
331
332
// step 4 - transactional insert array of entities
332
- const insertResponse = await appServer . AppDataSource . getRepository ( Assistant ) . insert ( prepVariables )
333
+ const insertResponse = await repository . insert ( prepVariables )
333
334
334
335
return insertResponse
335
336
} catch ( error ) {
0 commit comments