11import { HttpClient , HttpParams } from '@angular/common/http' ;
22import { Injectable , inject } from '@angular/core' ;
3- import { catchError , map , Observable , of , switchMap , tap , throwError } from 'rxjs' ;
3+ import { catchError , map , Observable , of , switchMap , throwError } from 'rxjs' ;
44import { GitHubConnectionState , GitHubRepo , SyncStatus } from '../models/github-integration.model' ;
5- import { JiraIntegrationResponse , JiraProject , JiraSyncStatus } from '../models/jira-integration.model' ;
65import { SlackConnectionState } from '../models/slack-integration.model' ;
76import { toError } from './http-error' ;
87
@@ -38,10 +37,6 @@ interface GitHubSyncResponse {
3837 status : string ;
3938}
4039
41- interface JiraSyncResponse {
42- status : string ;
43- }
44-
4540@Injectable ( {
4641 providedIn : 'root' ,
4742} )
@@ -61,7 +56,6 @@ export class IntegrationService {
6156 return this . getSlackAuthUrl ( workspaceId ) . pipe (
6257 map ( ( { authUrl } ) => {
6358 window . open ( authUrl , '_blank' ) ;
64- return ;
6559 } ) ,
6660 ) ;
6761 }
@@ -131,7 +125,6 @@ export class IntegrationService {
131125 return this . getGitHubAuthUrl ( ) . pipe (
132126 map ( ( { authUrl } ) => {
133127 window . open ( authUrl , '_blank' ) ;
134- return ;
135128 } ) ,
136129 ) ;
137130 }
@@ -189,48 +182,38 @@ export class IntegrationService {
189182 ) ;
190183 }
191184
192- getJiraAuthUrl ( workspaceId : string , redirectUrl ?: string ) : Observable < { authUrl : string } > {
193- console . log ( 'Fetching Jira Auth URL for workspace:' , workspaceId ) ;
194- let params = new HttpParams ( ) . set ( 'workspace_id' , workspaceId ) ;
195- if ( redirectUrl ) {
196- params = params . set ( 'redirect_url' , redirectUrl ) ;
197- }
185+ getJiraAuthUrl ( workspaceId : string ) : Observable < { authUrl : string } > {
186+ const params = new HttpParams ( ) . set ( 'workspace_id' , workspaceId ) ;
198187 return this . http . get < OAuthResponse > ( `${ this . apiUrl } /jira/auth` , { params } ) . pipe (
199- tap ( resp => console . log ( 'Jira Auth URL response:' , resp ) ) ,
200188 map ( ( response ) => ( { authUrl : response . auth_url } ) ) ,
201- catchError ( ( error ) => {
202- console . error ( 'Jira Auth URL error:' , error ) ;
203- return throwError ( ( ) => toError ( error , 'Unable to start Jira connection.' ) ) ;
204- } ) ,
189+ catchError ( ( error ) => throwError ( ( ) => toError ( error , 'Unable to start Jira connection.' ) ) ) ,
205190 ) ;
206191 }
207192
208193 connectJira ( workspaceId : string ) : Observable < void > {
209- const redirectUrl = window . location . origin + window . location . pathname ;
210- return this . getJiraAuthUrl ( workspaceId , redirectUrl ) . pipe (
194+ return this . getJiraAuthUrl ( workspaceId ) . pipe (
211195 map ( ( { authUrl } ) => {
212- window . location . href = authUrl ;
213- return ;
196+ window . open ( authUrl , '_blank' ) ;
214197 } ) ,
215198 ) ;
216199 }
217200
218- getJiraProjects ( workspaceId : string ) : Observable < JiraIntegrationResponse > {
201+ getJiraProjects ( workspaceId : string ) : Observable < any > {
219202 return this . getIntegrations ( workspaceId ) . pipe (
220203 switchMap ( ( integrations ) => {
221204 const jiraIntegration = integrations . find ( ( integration ) => integration . provider === 'jira' ) ;
222205 if ( ! jiraIntegration ) {
223206 return of ( {
224207 connected : false ,
225- projects : [ ] ,
208+ resources : [ ] ,
226209 } ) ;
227210 }
228211
229212 const params = new HttpParams ( ) . set ( 'workspace_id' , workspaceId ) ;
230- return this . http . get < JiraProject [ ] > ( `${ this . apiUrl } /jira/projects` , { params } ) . pipe (
231- map ( ( projects ) => ( {
213+ return this . http . get < any [ ] > ( `${ this . apiUrl } /jira/projects` , { params } ) . pipe (
214+ map ( ( resources ) => ( {
232215 connected : true ,
233- projects ,
216+ resources : resources ,
234217 lastSyncAt : jiraIntegration . updated_at ? new Date ( jiraIntegration . updated_at ) : undefined ,
235218 } ) ) ,
236219 ) ;
@@ -246,13 +229,13 @@ export class IntegrationService {
246229 ) ;
247230 }
248231
249- syncJira ( workspaceId : string ) : Observable < JiraSyncStatus > {
232+ syncJira ( workspaceId : string ) : Observable < any > {
250233 const params = new HttpParams ( ) . set ( 'workspace_id' , workspaceId ) ;
251- return this . http . post < JiraSyncResponse > ( `${ this . apiUrl } /jira/sync` , { } , { params } ) . pipe (
234+ return this . http . post < any > ( `${ this . apiUrl } /jira/sync` , { } , { params } ) . pipe (
252235 map ( ( response ) => {
253236 return {
254237 status : response . status === 'sync_started' ? 'in_progress' : 'failed' ,
255- } as JiraSyncStatus ;
238+ } ;
256239 } ) ,
257240 catchError ( ( error ) => throwError ( ( ) => toError ( error , 'Unable to sync Jira.' ) ) ) ,
258241 ) ;
0 commit comments