mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
152 lines
4.0 KiB
TypeScript
152 lines
4.0 KiB
TypeScript
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<any>(`${geturl}`, options);
|
|
}
|
|
|
|
GetPresidentialAction(id:any){
|
|
const geturl = environment.apiURL + 'presidentialActions/'+id;
|
|
|
|
let options = {
|
|
headers: this.headers,
|
|
};
|
|
return this.http.get<any>(`${geturl}`, options);
|
|
}
|
|
|
|
UpdatePresidentialAction(body:any){
|
|
const geturl = environment.apiURL + 'presidentialActions';
|
|
|
|
let options = {
|
|
headers: this.headers,
|
|
};
|
|
return this.http.put<any>(`${geturl}`, body, options);
|
|
}
|
|
|
|
CreatePublicationFolder(body:any){
|
|
const geturl = environment.apiURL + 'presidentialActions';
|
|
let options = {
|
|
headers: this.headers,
|
|
};
|
|
return this.http.post<any>(`${geturl}`, body, options)
|
|
}
|
|
|
|
UpdatePublicationFolder(body:any) {
|
|
const geturl = environment.apiURL + 'presidentialActions';
|
|
|
|
let options = {
|
|
headers: this.headers,
|
|
};
|
|
|
|
return this.http.put<any>(`${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<any>(`${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<any>(`${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<any>(`${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<any>(`${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<any>(`${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');
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|