aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list.service.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-02-18 00:11:24 +0800
committercrupest <crupest@outlook.com>2019-02-18 00:11:24 +0800
commit633e7357b41b5b3e99df887215bed620034eda6a (patch)
treecae8958b853ee87a885d2a8e73e8df78220e2cf6 /Timeline/ClientApp/src/app/todo-list.service.ts
parent122a28595e45c6ec48a773ca1284238566d497d3 (diff)
downloadtimeline-633e7357b41b5b3e99df887215bed620034eda6a.tar.gz
timeline-633e7357b41b5b3e99df887215bed620034eda6a.tar.bz2
timeline-633e7357b41b5b3e99df887215bed620034eda6a.zip
Add todo list request service.
Diffstat (limited to 'Timeline/ClientApp/src/app/todo-list.service.ts')
-rw-r--r--Timeline/ClientApp/src/app/todo-list.service.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list.service.ts
new file mode 100644
index 00000000..e92a11c9
--- /dev/null
+++ b/Timeline/ClientApp/src/app/todo-list.service.ts
@@ -0,0 +1,50 @@
+import { Injectable } from '@angular/core';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { Observable } from 'rxjs';
+import { switchMap, concatMap, map, toArray } from 'rxjs/operators';
+
+interface WiqlWorkItemResult {
+ id: number;
+ url: string;
+}
+
+interface WiqlResult {
+ workItems: WiqlWorkItemResult[];
+}
+
+interface WorkItemResult {
+ id: number;
+ fields: { [name: string]: any };
+}
+
+@Injectable({
+ providedIn: 'root'
+})
+export class TodoListService {
+
+ private username = 'crupest';
+ private pat = 'ehnmegogmk6r7qlkpy6zdl2hnfl6ntqbvggzxvvgp4a5vhr7lmnq';
+ private organization = 'crupest-web';
+ private project = 'Timeline';
+ private fieldId = 'System.Title';
+
+ private headers: HttpHeaders;
+
+ constructor(private client: HttpClient) {
+ this.headers = new HttpHeaders({
+ 'Accept': 'application/json',
+ 'Authorization': `Basic ${btoa(this.username + ':' + this.pat)}`
+ });
+ }
+
+ getWorkItemList(): Observable<string[]> {
+ return this.client.post<WiqlResult>(`https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, {
+ query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project'
+ }, { headers: this.headers }).pipe(
+ switchMap(result => result.workItems),
+ concatMap(result => this.client.get<WorkItemResult>(result.url, {headers: this.headers})),
+ map(result => <string>(result.fields[this.fieldId])),
+ toArray()
+ );
+ }
+}