Files
doneit-web/src/app/services/publications.service.ts
T

275 lines
6.8 KiB
TypeScript
Raw Normal View History

2021-11-29 15:48:35 +01:00
import { Injectable, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
2021-08-27 15:21:15 +01:00
import { LoginUserRespose } from '../models/user.model';
2021-04-08 09:14:28 +01:00
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators'
2021-08-23 11:30:42 +01:00
import { Publication } from '../models/publication';
2021-11-29 15:48:35 +01:00
import { getUrl } from 'ionicons/dist/types/components/icon/utils';
import { ActivatedRoute, Router } from '@angular/router';
2022-10-12 17:01:09 +01:00
import { SessionStore } from '../store/session.service';
2023-01-24 15:56:47 +01:00
import { ChangeProfileService } from './change-profile.service';
@Injectable({
providedIn: 'root'
})
2021-11-29 15:48:35 +01:00
export class PublicationsService {
2024-01-18 17:17:03 +01:00
authheader = {};
2021-08-27 15:21:15 +01:00
loggeduser: LoginUserRespose;
headers: HttpHeaders;
2021-11-29 15:48:35 +01:00
constructor(private http: HttpClient, user: AuthService,
private activatedRoute: ActivatedRoute,
2023-01-24 15:56:47 +01:00
private router: Router,
private changeProfileService: ChangeProfileService,) {
this.setHeader()
this.changeProfileService.registerCallback(() => {
this.setHeader()
})
2024-01-18 17:17:03 +01:00
2023-01-24 15:56:47 +01:00
}
setHeader () {
2022-10-12 17:01:09 +01:00
this.loggeduser = SessionStore.user;
2023-10-25 09:08:49 +01:00
this.headers = new HttpHeaders();;
2023-11-29 12:17:52 +01:00
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
}
GetPublicationFolderList(){
const geturl = environment.apiURL + 'presidentialActions';
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
};
return this.http.get<any>(`${geturl}`, options);
}
2021-07-01 09:36:17 +01:00
GetPresidentialAction(id:any){
const geturl = environment.apiURL + 'presidentialActions/'+id;
2024-01-18 17:17:03 +01:00
let options = {
2021-07-01 09:36:17 +01:00
headers: this.headers,
};
return this.http.get<any>(`${geturl}`, options);
}
2021-08-23 11:30:42 +01:00
UpdatePresidentialAction(body:any) {
2021-07-01 11:08:04 +01:00
const geturl = environment.apiURL + 'presidentialActions';
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
};
2021-07-01 11:08:04 +01:00
return this.http.put<any>(`${geturl}`, body, options);
}
CreatePublicationFolder(body:any){
const geturl = environment.apiURL + 'presidentialActions';
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
};
2021-05-25 16:12:40 +01:00
return this.http.post<any>(`${geturl}`, body, options)
}
2021-05-25 16:21:14 +01:00
UpdatePublicationFolder(body:any) {
const geturl = environment.apiURL + 'presidentialActions';
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
};
2024-01-18 17:17:03 +01:00
return this.http.put<any>(`${geturl}`, body, options).toPromise().then(res =>{
2024-01-18 17:17:03 +01:00
});
}
2021-06-30 15:48:37 +01:00
DeletePresidentialAction(id:any){
const geturl = environment.apiURL + 'presidentialActions/'+id;
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
};
return this.http.delete<any>(`${geturl}`, options);
}
2023-03-04 07:21:33 +01:00
GetPublicationsList(folder:any) {
const geturl = environment.apiURL + 'presidentialActions/'+ folder +'/posts/ids';
let params = new HttpParams();
params = params.set("folderId", folder);
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
params: params
};
2023-03-04 07:21:33 +01:00
return this.http.get<number[]>(`${geturl}`, options)
}
GetPublications(id:any){
const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts';
let params = new HttpParams();
params = params.set("folderId", id);
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
params: params
};
2021-08-23 11:30:42 +01:00
return this.http.get<Publication[]>(`${geturl}`, options)
}
2021-11-29 15:48:35 +01:00
// this one too,goes to observable as a first api call
2021-11-30 09:24:34 +01:00
GetIdsPublicationsImages(id:any) {
2021-11-29 15:48:35 +01:00
const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts/ids';
let params = new HttpParams();
params = params.set("folderId", id);
2024-01-18 17:17:03 +01:00
let options = {
2021-11-29 15:48:35 +01:00
headers: this.headers,
params: params
};
return this.http.get<number[]>(`${geturl}`, options)
}
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
GetPublicationById( publicationId:any){
const geturl = environment.apiURL + 'presidentialActions/posts/'+ publicationId;
let params = new HttpParams();
params = params.set("id", publicationId);
2024-01-18 17:17:03 +01:00
let options = {
headers: this.headers,
params: params
};
return this.http.get<any>(`${geturl}`, options);
}
2023-11-20 14:12:32 +01:00
GetPublicationWithArrayOfFilesById( publicationId:any){
const geturl = environment.apiURL + 'presidentialActions/v2/posts/'+ publicationId;
let params = new HttpParams();
params = params.set("id", publicationId);
2024-01-18 17:17:03 +01:00
let options = {
2023-11-20 14:12:32 +01:00
headers: this.headers,
params: params
};
return this.http.get<any>(`${geturl}`, options);
}
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
// my own tries
GetPublicationByIdNext( publicationId:any){
let geturl = environment.apiURL + 'presidentialActions/'+ publicationId + '/posts/ids';
let params = new HttpParams();
2024-01-18 17:17:03 +01:00
params = params.set("folderId", publicationId);
2021-11-29 15:48:35 +01:00
2024-01-18 17:17:03 +01:00
let options = {
2021-11-29 15:48:35 +01:00
headers: this.headers,
/* params: params */
};
const imageLoads = !!(+localStorage.getItem('loadedimage'))
if(imageLoads){
return true
}else{
const navigation = this.router.getCurrentNavigation()
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
if(navigation){
geturl = navigation.extractedUrl.toString()
}
this.router.navigate([URL], {queryParams: {returnto: geturl}})
}
}
GetIdsPublicationNext(id:any){
let geturl = environment.apiURL + 'presidentialActions/posts/' + id;
let params = new HttpParams();
params = params.set("id", id);
2024-01-18 17:17:03 +01:00
let options = {
2021-11-29 15:48:35 +01:00
headers: this.headers,
params: params
};
var search = this.http.get<any>(`${geturl}`, options).subscribe(
res => {
res.this.activatedRoute.snapshot.queryParams.get('returnto') || '/posts'
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
}
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
)
return search
2024-01-18 17:17:03 +01:00
2021-11-29 15:48:35 +01:00
}
//my last tries
2020-12-10 11:22:06 +01:00
CreatePublication(folderId:any,body:any){
2023-11-29 12:17:52 +01:00
console.log('body publi', body)
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/v2/posts';
2020-12-10 11:22:06 +01:00
let params = new HttpParams();
params = params.set("folderId", folderId);
2024-01-18 17:17:03 +01:00
let options = {
2020-12-10 11:22:06 +01:00
headers: this.headers,
2020-12-11 15:09:53 +01:00
/* params: params */
2020-12-10 11:22:06 +01:00
};
2021-05-25 16:12:40 +01:00
return this.http.post<any>(`${geturl}`, body, options)
2020-12-10 11:22:06 +01:00
}
UpdatePublication(folderId:any,body:any){
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts';
let params = new HttpParams();
params = params.set("folderId", folderId);
2024-01-18 17:17:03 +01:00
let options = {
2020-12-10 11:22:06 +01:00
headers: this.headers,
2020-12-11 15:09:53 +01:00
/* params: params */
2020-12-10 11:22:06 +01:00
};
2021-05-25 16:21:14 +01:00
2024-01-18 17:17:03 +01:00
body.Files = body.Files.map( e => ({
FileBase64: e.FileBase64,
FileExtension: e.FileExtension,
OriginalFileName: 'foto'
}))
2021-05-25 16:12:40 +01:00
return this.http.put<any>(`${geturl}`, body, options)
2020-12-10 11:22:06 +01:00
}
2020-12-11 15:09:53 +01:00
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);
2024-01-18 17:17:03 +01:00
let options = {
2020-12-11 15:09:53 +01:00
headers: this.headers,
/* params: params */
};
2021-05-25 16:21:14 +01:00
return this.http.delete(`${geturl}`, options)
2020-12-11 15:09:53 +01:00
}
2021-04-08 09:14:28 +01:00
handleError(error){
return throwError(error || 'Server Error');
}
}