diff --git a/bizmatch-server/src/listings/business-listing.service.ts b/bizmatch-server/src/listings/business-listing.service.ts index 5812211..61dc472 100644 --- a/bizmatch-server/src/listings/business-listing.service.ts +++ b/bizmatch-server/src/listings/business-listing.service.ts @@ -102,7 +102,7 @@ export class BusinessListingService { if (criteria.brokerName) { whereConditions.push(or(ilike(schema.users.firstname, `%${criteria.brokerName}%`), ilike(schema.users.lastname, `%${criteria.brokerName}%`))); } - + whereConditions.push(and(eq(schema.users.customerType, 'professional'), eq(schema.users.customerSubType, 'broker'))); return whereConditions; } async searchBusinessListings(criteria: BusinessListingCriteria, user: JwtUser) { diff --git a/bizmatch-server/src/listings/commercial-property.service.ts b/bizmatch-server/src/listings/commercial-property.service.ts index 1f0ce26..7ca91c3 100644 --- a/bizmatch-server/src/listings/commercial-property.service.ts +++ b/bizmatch-server/src/listings/commercial-property.service.ts @@ -53,14 +53,14 @@ export class CommercialPropertyService { if (criteria.title) { whereConditions.push(or(ilike(schema.commercials.title, `%${criteria.title}%`), ilike(schema.commercials.description, `%${criteria.title}%`))); } - + whereConditions.push(and(eq(schema.users.customerType, 'professional'))); return whereConditions; } // #### Find by criteria ######################################## async searchCommercialProperties(criteria: CommercialPropertyListingCriteria, user: JwtUser): Promise { const start = criteria.start ? criteria.start : 0; const length = criteria.length ? criteria.length : 12; - const query = this.conn.select().from(schema.commercials); + const query = this.conn.select({ commercial: commercials }).from(commercials).leftJoin(schema.users, eq(commercials.email, schema.users.email)); const whereConditions = this.getWhereConditions(criteria); if (whereConditions.length > 0) { @@ -71,7 +71,8 @@ export class CommercialPropertyService { // Paginierung query.limit(length).offset(start); - const results = await query; + const data = await query; + const results = data.map(r => r.commercial); const totalCount = await this.getCommercialPropertiesCount(criteria); return { @@ -80,7 +81,7 @@ export class CommercialPropertyService { }; } async getCommercialPropertiesCount(criteria: CommercialPropertyListingCriteria): Promise { - const countQuery = this.conn.select({ value: count() }).from(schema.commercials); + const countQuery = this.conn.select({ value: count() }).from(schema.commercials).leftJoin(schema.users, eq(commercials.email, schema.users.email)); const whereConditions = this.getWhereConditions(criteria); if (whereConditions.length > 0) { diff --git a/bizmatch-server/src/user/user.service.ts b/bizmatch-server/src/user/user.service.ts index 6466b60..1882f6e 100644 --- a/bizmatch-server/src/user/user.service.ts +++ b/bizmatch-server/src/user/user.service.ts @@ -24,7 +24,7 @@ export class UserService { private getWhereConditions(criteria: UserListingCriteria): SQL[] { const whereConditions: SQL[] = []; - + whereConditions.push(eq(schema.users.customerType, 'professional')); if (criteria.city && criteria.searchType === 'exact') { whereConditions.push(ilike(schema.users.companyLocation, `%${criteria.city}%`)); } @@ -53,9 +53,6 @@ export class UserService { whereConditions.push(or(...criteria.counties.map(county => sql`EXISTS (SELECT 1 FROM jsonb_array_elements(${schema.users.areasServed}) AS area WHERE area->>'county' ILIKE ${`%${county}%`})`))); } - // if (criteria.states && criteria.states.length > 0) { - // whereConditions.push(or(...criteria.states.map(state => sql`EXISTS (SELECT 1 FROM jsonb_array_elements(${schema.users.areasServed}) AS area WHERE area->>'state' = ${state})`))); - // } if (criteria.state) { whereConditions.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements(${schema.users.areasServed}) AS area WHERE area->>'state' = ${criteria.state})`); } diff --git a/bizmatch/src/app/app.component.html b/bizmatch/src/app/app.component.html index 598f06b..9c69e0f 100644 --- a/bizmatch/src/app/app.component.html +++ b/bizmatch/src/app/app.component.html @@ -11,7 +11,10 @@ @if (loadingService.isLoading$ | async) {
-
{{ loadingText }}
+ @let loadingText = (loadingService.loadingText$ | async); + +
{{ loadingText }}
+
} diff --git a/bizmatch/src/app/components/search-modal/search-modal.component.ts b/bizmatch/src/app/components/search-modal/search-modal.component.ts index 82ba32c..233d825 100644 --- a/bizmatch/src/app/components/search-modal/search-modal.component.ts +++ b/bizmatch/src/app/components/search-modal/search-modal.component.ts @@ -1,6 +1,7 @@ import { AsyncPipe, NgIf } from '@angular/common'; import { Component } from '@angular/core'; import { NgSelectModule } from '@ng-select/ng-select'; +import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { catchError, concat, debounceTime, distinctUntilChanged, map, Observable, of, Subject, Subscription, switchMap, tap } from 'rxjs'; import { BusinessListingCriteria, CommercialPropertyListingCriteria, CountyResult, GeoResult, KeyValue, KeyValueStyle, UserListingCriteria } from '../../../../../bizmatch-server/src/models/main.model'; import { CriteriaChangeService } from '../../services/criteria-change.service'; @@ -10,7 +11,7 @@ import { SelectOptionsService } from '../../services/select-options.service'; import { UserService } from '../../services/user.service'; import { SharedModule } from '../../shared/shared/shared.module'; import { ModalService } from './modal.service'; - +@UntilDestroy() @Component({ selector: 'app-search-modal', standalone: true, @@ -38,10 +39,15 @@ export class SearchModalComponent { ) {} ngOnInit() { this.setupCriteriaChangeListener(); - this.modalService.message$.subscribe(msg => { + this.modalService.message$.pipe(untilDestroyed(this)).subscribe(msg => { this.criteria = msg; this.setTotalNumberOfResults(); }); + this.modalService.modalVisible$.pipe(untilDestroyed(this)).subscribe(val => { + if (val) { + this.criteria.page = 1; + } + }); this.loadCities(); this.loadCounties(); } diff --git a/bizmatch/src/app/pages/home/home.component.ts b/bizmatch/src/app/pages/home/home.component.ts index 1f36c36..301129e 100644 --- a/bizmatch/src/app/pages/home/home.component.ts +++ b/bizmatch/src/app/pages/home/home.component.ts @@ -162,6 +162,7 @@ export class HomeComponent { this.criteria.radius = 20; } } else { + this.criteria.state = null; this.criteria.city = null; this.criteria.radius = null; this.criteria.searchType = 'exact'; diff --git a/bizmatch/src/app/pages/listings/business-listings/business-listings.component.ts b/bizmatch/src/app/pages/listings/business-listings/business-listings.component.ts index a602f50..d7e34b5 100644 --- a/bizmatch/src/app/pages/listings/business-listings/business-listings.component.ts +++ b/bizmatch/src/app/pages/listings/business-listings/business-listings.component.ts @@ -58,12 +58,11 @@ export class BusinessListingsComponent { } }); } - async ngOnInit() {} + async ngOnInit() { + this.search(); + } async init() { this.reset(); - const statesResult = await this.listingsService.getAllStates('business'); - this.states = statesResult.map(ls => ({ name: this.selectOptions.getState(ls.state as string), value: ls.state, count: ls.count })); - this.search(); } async search() { diff --git a/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.html b/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.html index 04bcc2b..e5deaaa 100644 --- a/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.html +++ b/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.html @@ -58,7 +58,7 @@ @for (listing of listings; track listing.id) {
@if (listing.imageOrder?.length>0){ - Image + Image } @else { Image } diff --git a/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.ts b/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.ts index 3531c22..851d900 100644 --- a/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.ts +++ b/bizmatch/src/app/pages/listings/commercial-property-listings/commercial-property-listings.component.ts @@ -37,6 +37,7 @@ export class CommercialPropertyListingsComponent { env = environment; page = 1; pageCount = 1; + ts = new Date().getTime(); constructor( public selectOptions: SelectOptionsService, private listingsService: ListingsService,