1
|
import { Injectable } from '@angular/core';
|
2
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
3
|
import {map} from "rxjs/operators";
|
4
|
|
5
|
@Injectable()
|
6
|
export class SubjectsService {
|
7
|
|
8
|
constructor(private http: HttpClient) {
|
9
|
|
10
|
}
|
11
|
|
12
|
addSubjects(url: string, subjects: any) {
|
13
|
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
14
|
|
15
|
const body = JSON.stringify(subjects);
|
16
|
|
17
|
return this.http.post(url, body, {headers: headers})
|
18
|
// .do(request => console.log("Insert Response:"+request.status))
|
19
|
//.map(res => res.json())
|
20
|
.pipe(map(res => {
|
21
|
res['method'] = 'post';
|
22
|
return res;
|
23
|
}));
|
24
|
}
|
25
|
|
26
|
removeSubjects(url: string, subjects: any) {
|
27
|
//const headers = new Headers({'Content-Type': 'application/json'});
|
28
|
let headers = new HttpHeaders({'Content-Type': 'application/json'});
|
29
|
|
30
|
const body = JSON.stringify(subjects);
|
31
|
//const options = new RequestOptions({headers: headers, body: body});
|
32
|
|
33
|
//return this.http.delete(url, options)
|
34
|
return this.http.request('delete', url, { body: body, headers: headers})
|
35
|
// .do(request => console.log("Delete Response:"+request.status))
|
36
|
//.map(res => res.json())
|
37
|
.pipe(map(res => {
|
38
|
res['method'] = 'delete';
|
39
|
return res;
|
40
|
}));
|
41
|
}
|
42
|
}
|