import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import { AuthService } from '../services/auth.service'; import { User } from '../models/user.model'; import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators' @Injectable({ providedIn: 'root' }) export class PublicationsService { authheader = {}; loggeduser: User; headers: HttpHeaders; constructor(private http: HttpClient, user: AuthService) { this.loggeduser = user.ValidatedUser; this.headers = new HttpHeaders(); this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey); } GetPublicationFolderList(){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.get(`${geturl}`, options); } GetPresidentialAction(id:any){ const geturl = environment.apiURL + 'presidentialActions/'+id; let options = { headers: this.headers, }; return this.http.get(`${geturl}`, options); } UpdatePresidentialAction(body:any){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.put(`${geturl}`, body, options); } CreatePublicationFolder(body:any){ const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.post(`${geturl}`, body, options) } UpdatePublicationFolder(body:any) { const geturl = environment.apiURL + 'presidentialActions'; let options = { headers: this.headers, }; return this.http.put(`${geturl}`, body, options).toPromise().then(res =>{ console.log(res); }); } DeletePresidentialAction(id:any){ const geturl = environment.apiURL + 'presidentialActions/'+id; let options = { headers: this.headers, }; return this.http.delete(`${geturl}`, options); } GetPublications(id:any){ const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts'; let params = new HttpParams(); params = params.set("folderId", id); let options = { headers: this.headers, params: params }; return this.http.get(`${geturl}`, options) .pipe(catchError(this.handleError)); } GetPublicationById( publicationId:any){ const geturl = environment.apiURL + 'presidentialActions/posts/'+ publicationId; let params = new HttpParams(); /* params = params.set("id", publicationId); */ let options = { headers: this.headers, /* params: params */ }; return this.http.get(`${geturl}`, options); } CreatePublication(folderId:any,body:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts'; let params = new HttpParams(); params = params.set("folderId", folderId); let options = { headers: this.headers, /* params: params */ }; return this.http.post(`${geturl}`, body, options) } UpdatePublication(folderId:any,body:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts'; let params = new HttpParams(); params = params.set("folderId", folderId); let options = { headers: this.headers, /* params: params */ }; return this.http.put(`${geturl}`, body, options) } DeletePublication(folderId:any,publicationId:any){ const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts/'+publicationId; let params = new HttpParams(); params = params.set("folderId", folderId); params = params.set("id", publicationId); let options = { headers: this.headers, /* params: params */ }; return this.http.delete(`${geturl}`, options) } handleError(error){ return throwError(error || 'Server Error'); } }