@@ -18,7 +18,7 @@ import {
18
18
import { ConnectionRepository } from './connection.repository' ;
19
19
import { ResponseMessages } from '@credebl/common/response-messages' ;
20
20
import { IUserRequest } from '@credebl/user-request/user-request.interface' ;
21
- import { OrgAgentType , ConnectionProcessState } from '@credebl/enum/enum' ;
21
+ import { ConnectionProcessState } from '@credebl/enum/enum' ;
22
22
import { Cache } from 'cache-manager' ;
23
23
import { CACHE_MANAGER } from '@nestjs/cache-manager' ;
24
24
import {
@@ -188,23 +188,13 @@ export class ConnectionService {
188
188
try {
189
189
const { alias, myDid, outOfBandId, state, theirDid, theirLabel } = connectionSearchCriteria ;
190
190
const agentDetails = await this . connectionRepository . getAgentEndPoint ( orgId ) ;
191
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
192
191
const { agentEndPoint } = agentDetails ;
193
192
if ( ! agentDetails ) {
194
193
throw new NotFoundException ( ResponseMessages . issuance . error . agentEndPointNotFound ) ;
195
194
}
196
195
197
196
let url : string ;
198
- if ( orgAgentType === OrgAgentType . DEDICATED ) {
199
- url = `${ agentEndPoint } ${ CommonConstants . URL_CONN_GET_CONNECTIONS } ` ;
200
- } else if ( orgAgentType === OrgAgentType . SHARED ) {
201
- url = `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_GET_CREATEED_INVITATIONS } ` . replace (
202
- '#' ,
203
- agentDetails . tenantId
204
- ) ;
205
- } else {
206
- throw new NotFoundException ( ResponseMessages . connection . error . agentUrlNotFound ) ;
207
- }
197
+ url = `${ agentEndPoint } ${ CommonConstants . URL_CONN_GET_CONNECTIONS } ` ;
208
198
209
199
//Create the dynamic URL for Search Criteria
210
200
const criteriaParams = [ ] ;
@@ -263,24 +253,11 @@ export class ConnectionService {
263
253
async getConnectionsById ( user : IUserRequest , connectionId : string , orgId : string ) : Promise < IConnectionDetailsById > {
264
254
try {
265
255
const agentDetails = await this . connectionRepository . getAgentEndPoint ( orgId ) ;
266
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
267
-
268
256
const { agentEndPoint } = agentDetails ;
269
257
if ( ! agentDetails ) {
270
258
throw new NotFoundException ( ResponseMessages . issuance . error . agentEndPointNotFound ) ;
271
259
}
272
-
273
- let url ;
274
- if ( orgAgentType === OrgAgentType . DEDICATED ) {
275
- url = `${ agentEndPoint } ${ CommonConstants . URL_CONN_GET_CONNECTION_BY_ID } ` . replace ( '#' , connectionId ) ;
276
- } else if ( orgAgentType === OrgAgentType . SHARED ) {
277
- url = `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_GET_CREATEED_INVITATION_BY_CONNECTIONID } `
278
- . replace ( '#' , connectionId )
279
- . replace ( '@' , agentDetails . tenantId ) ;
280
- } else {
281
- throw new NotFoundException ( ResponseMessages . connection . error . agentUrlNotFound ) ;
282
- }
283
-
260
+ const url = `${ agentEndPoint } ${ CommonConstants . URL_CONN_GET_CONNECTION_BY_ID } ` . replace ( '#' , connectionId ) ;
284
261
const createConnectionInvitation = await this . _getConnectionsByConnectionId ( url , orgId ) ;
285
262
return createConnectionInvitation ?. response ;
286
263
} catch ( error ) {
@@ -301,14 +278,11 @@ export class ConnectionService {
301
278
async getQuestionAnswersRecord ( orgId : string ) : Promise < object > {
302
279
try {
303
280
const agentDetails = await this . connectionRepository . getAgentEndPoint ( orgId ) ;
304
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
305
281
const { agentEndPoint } = agentDetails ;
306
282
if ( ! agentDetails ) {
307
283
throw new NotFoundException ( ResponseMessages . issuance . error . agentEndPointNotFound ) ;
308
284
}
309
-
310
- const label = 'get-question-answer-record' ;
311
- const url = await this . getQuestionAnswerAgentUrl ( label , orgAgentType , agentEndPoint , agentDetails ?. tenantId ) ;
285
+ const url = await getAgentUrl ( agentEndPoint , CommonConstants . GET_QUESTION_ANSWER_RECORD ) ;
312
286
313
287
const record = await this . _getQuestionAnswersRecord ( url , orgId ) ;
314
288
return record ;
@@ -336,54 +310,6 @@ export class ConnectionService {
336
310
return this . natsCall ( pattern , payload ) ;
337
311
}
338
312
339
- async getQuestionAnswerAgentUrl (
340
- label : string ,
341
- orgAgentType : string ,
342
- agentEndPoint : string ,
343
- tenantId ?: string ,
344
- connectionId ?: string
345
- ) : Promise < string > {
346
- try {
347
- let url ;
348
- switch ( label ) {
349
- case 'send-question' : {
350
- url =
351
- orgAgentType === OrgAgentType . DEDICATED
352
- ? `${ agentEndPoint } ${ CommonConstants . URL_SEND_QUESTION } ` . replace ( '#' , connectionId )
353
- : orgAgentType === OrgAgentType . SHARED
354
- ? `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_SEND_QUESTION } `
355
- . replace ( '#' , connectionId )
356
- . replace ( '@' , tenantId )
357
- : null ;
358
- break ;
359
- }
360
-
361
- case 'get-question-answer-record' : {
362
- url =
363
- orgAgentType === OrgAgentType . DEDICATED
364
- ? `${ agentEndPoint } ${ CommonConstants . URL_QUESTION_ANSWER_RECORD } `
365
- : orgAgentType === OrgAgentType . SHARED
366
- ? `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_QUESTION_ANSWER_RECORD } ` . replace ( '#' , tenantId )
367
- : null ;
368
- break ;
369
- }
370
-
371
- default : {
372
- break ;
373
- }
374
- }
375
-
376
- if ( ! url ) {
377
- throw new NotFoundException ( ResponseMessages . issuance . error . agentUrlNotFound ) ;
378
- }
379
-
380
- return url ;
381
- } catch ( error ) {
382
- this . logger . error ( `Error get question answer agent Url: ${ JSON . stringify ( error ) } ` ) ;
383
- throw error ;
384
- }
385
- }
386
-
387
313
async _getOrgAgentApiKey ( orgId : string ) : Promise < {
388
314
response : string ;
389
315
} > {
@@ -411,25 +337,11 @@ export class ConnectionService {
411
337
) : Promise < IReceiveInvitationResponse > {
412
338
try {
413
339
const agentDetails = await this . connectionRepository . getAgentEndPoint ( orgId ) ;
414
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
415
-
416
340
const { agentEndPoint } = agentDetails ;
417
341
if ( ! agentDetails ) {
418
342
throw new NotFoundException ( ResponseMessages . issuance . error . agentEndPointNotFound ) ;
419
343
}
420
-
421
- let url ;
422
- if ( orgAgentType === OrgAgentType . DEDICATED ) {
423
- url = `${ agentEndPoint } ${ CommonConstants . URL_RECEIVE_INVITATION_URL } ` ;
424
- } else if ( orgAgentType === OrgAgentType . SHARED ) {
425
- url = `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_RECEIVE_INVITATION_URL } ` . replace (
426
- '#' ,
427
- agentDetails . tenantId
428
- ) ;
429
- } else {
430
- throw new NotFoundException ( ResponseMessages . connection . error . agentUrlNotFound ) ;
431
- }
432
-
344
+ const url = `${ agentEndPoint } ${ CommonConstants . URL_RECEIVE_INVITATION_URL } ` ;
433
345
const createConnectionInvitation = await this . _receiveInvitationUrl ( url , orgId , receiveInvitationUrl ) ;
434
346
return createConnectionInvitation . response ;
435
347
} catch ( error ) {
@@ -485,22 +397,11 @@ export class ConnectionService {
485
397
) : Promise < IReceiveInvitationResponse > {
486
398
try {
487
399
const agentDetails = await this . connectionRepository . getAgentEndPoint ( orgId ) ;
488
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
489
-
490
400
const { agentEndPoint } = agentDetails ;
491
401
if ( ! agentDetails ) {
492
402
throw new NotFoundException ( ResponseMessages . issuance . error . agentEndPointNotFound ) ;
493
403
}
494
-
495
- let url ;
496
- if ( orgAgentType === OrgAgentType . DEDICATED ) {
497
- url = `${ agentEndPoint } ${ CommonConstants . URL_RECEIVE_INVITATION } ` ;
498
- } else if ( orgAgentType === OrgAgentType . SHARED ) {
499
- url = `${ agentEndPoint } ${ CommonConstants . URL_SHAGENT_RECEIVE_INVITATION } ` . replace ( '#' , agentDetails . tenantId ) ;
500
- } else {
501
- throw new NotFoundException ( ResponseMessages . connection . error . agentUrlNotFound ) ;
502
- }
503
-
404
+ const url = `${ agentEndPoint } ${ CommonConstants . URL_RECEIVE_INVITATION } ` ;
504
405
const createConnectionInvitation = await this . _receiveInvitation ( url , orgId , receiveInvitation ) ;
505
406
return createConnectionInvitation ?. response ;
506
407
} catch ( error ) {
@@ -553,15 +454,7 @@ export class ConnectionService {
553
454
question
554
455
} ;
555
456
556
- const orgAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
557
- const label = 'send-question' ;
558
- const url = await this . getQuestionAnswerAgentUrl (
559
- label ,
560
- orgAgentType ,
561
- agentEndPoint ,
562
- agentDetails ?. tenantId ,
563
- connectionId
564
- ) ;
457
+ const url = await getAgentUrl ( agentEndPoint , CommonConstants . SEND_QUESTION , connectionId ) ;
565
458
566
459
const createQuestion = await this . _sendQuestion ( questionPayload , url , orgId ) ;
567
460
return createQuestion ;
@@ -833,16 +726,7 @@ export class ConnectionService {
833
726
const questionPayload = {
834
727
content
835
728
} ;
836
-
837
- const organizationAgentType = await this . connectionRepository . getOrgAgentType ( agentDetails ?. orgAgentTypeId ) ;
838
- const label = 'send-basic-message' ;
839
- const agentUrl = await this . commonService . sendBasicMessageAgentUrl (
840
- label ,
841
- organizationAgentType ,
842
- agentEndPoint ,
843
- agentDetails ?. tenantId ,
844
- connectionId
845
- ) ;
729
+ const agentUrl = await getAgentUrl ( agentEndPoint , CommonConstants . SEND_BASIC_MESSAGE , connectionId ) ;
846
730
847
731
const sendBasicMessage = await this . _sendBasicMessageToAgent ( questionPayload , agentUrl , orgId ) ;
848
732
return sendBasicMessage ;
0 commit comments