diff options
Diffstat (limited to 'Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts index 0b54653b..619e9a6b 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts @@ -3,20 +3,28 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { switchMap, concatMap, map, toArray } from 'rxjs/operators'; -interface WiqlWorkItemResult { +export interface AzureDevOpsAccessInfo { + username: string; + personalAccessToken: string; + organization: string; + project: string; +} + +export interface WiqlWorkItemResult { id: number; url: string; } -interface WiqlResult { +export interface WiqlResult { workItems: WiqlWorkItemResult[]; } -interface WorkItemResult { +export interface WorkItemResult { id: number; fields: { [name: string]: any }; } + export interface WorkItem { id: number; title: string; @@ -28,41 +36,33 @@ export interface WorkItem { }) export class TodoListService { - private username = 'crupest'; - private organization = 'crupest-web'; - private project = 'Timeline'; - private titleFieldName = 'System.Title'; - private stateFieldName = 'System.State'; + public static titleFieldName = 'System.Title'; + public static stateFieldName = 'System.State'; constructor(private client: HttpClient) { } - private getAzureDevOpsPat(): Observable<string> { - return this.client.get('/api/TodoList/AzureDevOpsPat', { - headers: { - 'Accept': 'text/plain' - }, - responseType: 'text' - }); + private getAzureDevOpsPat(): Observable<AzureDevOpsAccessInfo> { + return this.client.get<AzureDevOpsAccessInfo>('/api/TodoPage/AzureDevOpsAccessInfo'); } getWorkItemList(): Observable<WorkItem[]> { return this.getAzureDevOpsPat().pipe( switchMap( - pat => { + accessInfo => { const headers = new HttpHeaders({ 'Accept': 'application/json', - 'Authorization': `Basic ${btoa(this.username + ':' + pat)}` + 'Authorization': `Basic ${btoa(accessInfo.username + ':' + accessInfo.personalAccessToken)}` }); return this.client.post<WiqlResult>( - `https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { + `https://dev.azure.com/${accessInfo.organization}/${accessInfo.project}/_apis/wit/wiql?api-version=5.0`, { query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' }, { headers: headers }).pipe( switchMap(result => result.workItems), concatMap(result => this.client.get<WorkItemResult>(result.url, { headers: headers })), map(result => <WorkItem>{ id: result.id, - title: <string>result.fields[this.titleFieldName], - closed: ((<string>result.fields[this.stateFieldName]).toLowerCase() === 'closed') + title: <string>result.fields[TodoListService.titleFieldName], + closed: ((<string>result.fields[TodoListService.stateFieldName]).toLowerCase() === 'closed') }), toArray() ); |