import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { lastValueFrom } from 'rxjs'; import { ImageType } from '../../../../bizmatch-server/src/models/main.model'; import { environment } from '../../environments/environment'; @Injectable({ providedIn: 'root', }) export class ImageService { private apiBaseUrl = environment.apiBaseUrl; constructor(private http: HttpClient) {} uploadImage(imageBlob: Blob, type: 'uploadPropertyPicture' | 'uploadCompanyLogo' | 'uploadProfile', imagePath: string) { const uploadUrl = `${this.apiBaseUrl}/bizmatch/image/${type}/${imagePath}`; const formData = new FormData(); formData.append('file', imageBlob, 'image.png'); return this.http.post(uploadUrl, formData, { // headers: this.headers, //reportProgress: true, observe: 'events', }); } async deleteUserImage(userid: string, type: ImageType, name?: string) { return await lastValueFrom(this.http.delete<[]>(`${this.apiBaseUrl}/bizmatch/image/${type.delete}${userid}`)); } async deleteListingImage(listingid: string, name?: string) { return await lastValueFrom(this.http.delete<[]>(`${this.apiBaseUrl}/bizmatch/image/propertyPicture/${listingid}/${name}`)); } async getProfileImagesForUsers(userids: string[]) { return await lastValueFrom(this.http.get<[]>(`${this.apiBaseUrl}/bizmatch/image/profileImages/${userids.join(',')}`)); } async getCompanyLogosForUsers(userids: string[]) { return await lastValueFrom(this.http.get<[]>(`${this.apiBaseUrl}/bizmatch/image/companyLogos/${userids.join(',')}`)); } }