40 lines
2.0 KiB
TypeScript
40 lines
2.0 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
import { environment } from '../../environments/environment';
|
|
import { BusinessListing, ImageProperty, ListingCriteria, ListingType } from '../../../../common-models/src/main.model';
|
|
import onChange from 'on-change';
|
|
import { getSessionStorageHandler } from '../utils/utils';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ListingsService {
|
|
private apiBaseUrl = environment.apiBaseUrl;
|
|
constructor(private http: HttpClient) {
|
|
}
|
|
|
|
// getAllListings():Observable<ListingType[]>{
|
|
// return this.http.get<ListingType[]>(`${this.apiBaseUrl}/bizmatch/business-listings`);
|
|
// }
|
|
async getListings(criteria:ListingCriteria):Promise<ListingType[]>{
|
|
const result = await lastValueFrom(this.http.post<ListingType[]>(`${this.apiBaseUrl}/bizmatch/listings/${criteria.listingsCategory}/search`,criteria));
|
|
return result;
|
|
}
|
|
getListingById(id:string,listingsCategory?:'business'|'commercialProperty'):Observable<ListingType>{
|
|
return this.http.get<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/${id}`);
|
|
}
|
|
getListingByUserId(userid:string):Promise<BusinessListing[]>{
|
|
return lastValueFrom(this.http.get<BusinessListing[]>(`${this.apiBaseUrl}/bizmatch/listings/business/user/${userid}`));
|
|
}
|
|
async save(listing:any,listingsCategory:'business'|'professionals_brokers'|'commercialProperty'){
|
|
await lastValueFrom(this.http.post<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}`,listing));
|
|
}
|
|
async deleteListing(id:string,listingsCategory:'business'|'professionals_brokers'|'commercialProperty'){
|
|
await lastValueFrom(this.http.delete<ListingType>(`${this.apiBaseUrl}/bizmatch/listings/${listingsCategory}/${id}`));
|
|
}
|
|
async getPropertyImages(id:string):Promise<ImageProperty[]>{
|
|
return await lastValueFrom(this.http.get<ImageProperty[]>(`${this.apiBaseUrl}/bizmatch/image/${id}`));
|
|
}
|
|
}
|