aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-02-21 16:32:16 +0000
committer杨宇千 <crupest@outlook.com>2019-02-21 16:32:16 +0000
commit9ae2a899eb53b8ee31710a5533cdf21b0f14dafd (patch)
tree8f22c966d15d928a5587385f38b5284f0691b2de /Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts
parent35f8562f1f1db36a42c53ce42c39db3d615deb0f (diff)
parent504d770e51a07ca7765de725979412b6dacdcf15 (diff)
downloadtimeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.tar.gz
timeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.tar.bz2
timeline-9ae2a899eb53b8ee31710a5533cdf21b0f14dafd.zip
Merged PR 3: Add unit test for front side.
Related work items: #1
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.ts40
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()
);