@@ -5,17 +5,17 @@ import { Svix } from 'svix'; // Import Svix SDK type
5
5
6
6
import { GetWebhookPortalTokenCommand } from './get-webhook-portal-token.command' ;
7
7
import { GetWebhookPortalTokenResponseDto } from '../../dtos/get-webhook-portal-token-response.dto' ;
8
+ import { CreateWebhookPortalUsecase } from '../create-webhook-portal-token/create-webhook-portal.usecase' ;
9
+ import { CreateWebhookPortalCommand } from '../create-webhook-portal-token/create-webhook-portal.command' ;
8
10
9
11
const LOG_CONTEXT = 'GetWebhookPortalTokenUsecase' ;
10
12
11
- @Injectable ( {
12
- scope : Scope . REQUEST ,
13
- } )
13
+ @Injectable ( )
14
14
export class GetWebhookPortalTokenUsecase {
15
15
constructor (
16
16
private environmentRepository : EnvironmentRepository ,
17
17
@Inject ( 'SVIX_CLIENT' ) private svix : Svix ,
18
- private organizationRepository : OrganizationRepository
18
+ private createWebhookPortalUsecase : CreateWebhookPortalUsecase
19
19
) { }
20
20
21
21
@LogDecorator ( )
@@ -44,32 +44,21 @@ export class GetWebhookPortalTokenUsecase {
44
44
appId : `${ command . organizationId } -${ command . environmentId } ` ,
45
45
} ;
46
46
} catch ( error ) {
47
- console . log ( 'AAAAA' , error . code ) ;
48
47
if ( error . code === 404 ) {
49
- const organization = await this . organizationRepository . findById ( command . organizationId ) ;
50
- if ( ! organization ) {
51
- throw new NotFoundException ( `Organization not found for id ${ command . organizationId } ` ) ;
52
- }
53
-
54
- const app = await this . svix . application . create ( {
55
- name : organization . name ,
56
- uid : `${ command . organizationId } -${ command . environmentId } ` ,
57
- metadata : {
48
+ const app = await this . createWebhookPortalUsecase . execute (
49
+ CreateWebhookPortalCommand . create ( {
58
50
environmentId : command . environmentId ,
59
- } ,
60
- } ) ;
61
-
62
- const svixResponse = await this . svix . authentication . appPortalAccess (
63
- `${ command . organizationId } -${ command . environmentId } ` ,
64
- { }
51
+ organizationId : command . organizationId ,
52
+ userId : command . userId ,
53
+ } )
65
54
) ;
66
55
67
- console . log ( 'APPsSSSs' , svixResponse ) ;
56
+ const svixResponse = await this . svix . authentication . appPortalAccess ( app . appId , { } ) ;
68
57
69
58
return {
70
59
url : svixResponse . url ,
71
60
token : svixResponse . token ,
72
- appId : ` ${ command . organizationId } - ${ command . environmentId } ` ,
61
+ appId : app . appId ,
73
62
} ;
74
63
}
75
64
// Re-throw or handle specific Svix errors as needed
0 commit comments