2020-08-24 23:41:15 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2021-04-19 15:21:35 +01:00
|
|
|
import { Attachment, EventAttachment } from '../models/attachment.model';
|
2020-08-24 23:41:15 +01:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class AttachmentsService {
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 11:25:08 +01:00
|
|
|
getAttachmentsBySerial(serialNumber: string): Observable<Attachment[]>{
|
2020-08-24 23:41:15 +01:00
|
|
|
let geturl = environment.apiURL + 'attachments/GetAttachments';
|
|
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
2020-11-25 11:25:08 +01:00
|
|
|
params = params.set("SerialNumber", serialNumber);
|
2020-11-16 00:41:11 +01:00
|
|
|
|
2020-08-24 23:41:15 +01:00
|
|
|
let options = {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
params: params
|
|
|
|
|
};
|
|
|
|
|
return this.http.get<Attachment[]>(`${geturl}`, options);
|
|
|
|
|
}
|
2020-09-08 09:01:41 +01:00
|
|
|
|
2021-04-19 15:21:35 +01:00
|
|
|
getAttachments(source: number, sourceid: string): Observable<Attachment[]> {
|
2020-11-05 16:43:01 +01:00
|
|
|
let geturl = environment.apiURL + 'attachments/GetSourceName';
|
2020-09-08 09:01:41 +01:00
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
|
|
|
|
params = params.set("Source", source.toString());
|
2020-11-05 16:43:01 +01:00
|
|
|
/* params = params.set("SourceId", sourceid); */
|
|
|
|
|
|
2020-09-08 09:01:41 +01:00
|
|
|
let options = {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
params: params
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-25 11:25:08 +01:00
|
|
|
return this.http.get<Attachment[]>(`${geturl}`, options);
|
|
|
|
|
}
|
2021-04-19 15:21:35 +01:00
|
|
|
|
|
|
|
|
getAttachmentsById(eventId: string): Observable<Attachment[]> {
|
2020-11-25 11:25:08 +01:00
|
|
|
let geturl = environment.apiURL + 'attachments/GetAttachmentsByEventId';
|
|
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
|
|
|
|
params = params.set("ParentId", eventId);
|
|
|
|
|
/* params = params.set("SourceId", sourceid); */
|
|
|
|
|
|
2021-04-19 15:21:35 +01:00
|
|
|
let options = {
|
2020-11-25 11:25:08 +01:00
|
|
|
headers: this.headers,
|
|
|
|
|
params: params
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-08 09:01:41 +01:00
|
|
|
return this.http.get<Attachment[]>(`${geturl}`, options);
|
|
|
|
|
}
|
2021-04-19 15:21:35 +01:00
|
|
|
|
|
|
|
|
setEventAttachmentById(body: EventAttachment) {
|
|
|
|
|
|
|
|
|
|
let geturl = environment.apiURL + 'Attachments/Create';
|
|
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.http.post(`${geturl}`, body, options);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 15:05:40 +01:00
|
|
|
deleteEventAttachmentById(attachmentId) {
|
|
|
|
|
|
|
|
|
|
let geturl = environment.apiURL + `Attachments/Delete?attachmentId=${attachmentId}`;
|
|
|
|
|
|
|
|
|
|
let params = new HttpParams();
|
|
|
|
|
|
|
|
|
|
params = params.set("attachmentId", attachmentId);
|
|
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
headers: this.headers,
|
|
|
|
|
params: params
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.http.post(`${geturl}`, options);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 23:41:15 +01:00
|
|
|
}
|