From d4ec9d067f6b71b07be115c2ea764ef2cf68894e Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Fri, 13 Sep 2024 09:45:48 +0200 Subject: [PATCH] kleinere Korrekturen zu #60 --- .../app/components/email/email.component.ts | 2 +- .../src/app/components/email/email.service.ts | 10 +++++----- .../details-business-listing.component.ts | 6 +++--- ...ls-commercial-property-listing.component.ts | 6 +++--- bizmatch/src/app/services/audit.service.ts | 18 ++++++------------ 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/bizmatch/src/app/components/email/email.component.ts b/bizmatch/src/app/components/email/email.component.ts index 73cc57e..e2aa94f 100644 --- a/bizmatch/src/app/components/email/email.component.ts +++ b/bizmatch/src/app/components/email/email.component.ts @@ -27,7 +27,7 @@ export class EMailComponent { async sendMail() { try { const result = await this.mailService.mailToFriend(this.shareByEMail); - this.eMailService.accept(); + this.eMailService.accept(this.shareByEMail); } catch (error) { if (error.error && Array.isArray(error.error?.message)) { this.validationMessagesService.updateMessages(error.error.message); diff --git a/bizmatch/src/app/components/email/email.service.ts b/bizmatch/src/app/components/email/email.service.ts index bfc0786..9f95913 100644 --- a/bizmatch/src/app/components/email/email.service.ts +++ b/bizmatch/src/app/components/email/email.service.ts @@ -8,22 +8,22 @@ import { ShareByEMail } from '../../../../../bizmatch-server/src/models/db.model export class EMailService { private modalVisibleSubject = new BehaviorSubject(false); private shareByEMailSubject = new BehaviorSubject({}); - private resolvePromise!: (value: boolean) => void; + private resolvePromise!: (value: boolean | ShareByEMail) => void; modalVisible$: Observable = this.modalVisibleSubject.asObservable(); shareByEMail$: Observable = this.shareByEMailSubject.asObservable(); - showShareByEMail(shareByEMail: ShareByEMail): Promise { + showShareByEMail(shareByEMail: ShareByEMail): Promise { this.shareByEMailSubject.next(shareByEMail); this.modalVisibleSubject.next(true); - return new Promise(resolve => { + return new Promise(resolve => { this.resolvePromise = resolve; }); } - accept(): void { + accept(value: ShareByEMail): void { this.modalVisibleSubject.next(false); - this.resolvePromise(true); + this.resolvePromise(value); } reject(): void { diff --git a/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts b/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts index 0ec7edf..aaa0856 100644 --- a/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts +++ b/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts @@ -4,7 +4,7 @@ import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { KeycloakService } from 'keycloak-angular'; import { ShareButton } from 'ngx-sharebuttons/button'; import { lastValueFrom } from 'rxjs'; -import { BusinessListing, EventTypeEnum, User } from '../../../../../../bizmatch-server/src/models/db.model'; +import { BusinessListing, EventTypeEnum, ShareByEMail, User } from '../../../../../../bizmatch-server/src/models/db.model'; import { KeycloakUser, MailInfo } from '../../../../../../bizmatch-server/src/models/main.model'; import { environment } from '../../../../environments/environment'; import { EMailService } from '../../../components/email/email.service'; @@ -112,7 +112,7 @@ export class DetailsBusinessListingComponent { this.mailinfo.email = this.listingUser.email; this.mailinfo.listing = this.listing; await this.mailService.mail(this.mailinfo); - this.auditService.createEvent(this.listing.id, 'contact', this.user?.email); + this.auditService.createEvent(this.listing.id, 'contact', this.user?.email, this.mailinfo.sender); this.messageService.addMessage({ severity: 'success', text: 'Your message has been sent to the creator of the listing', duration: 3000 }); } catch (error) { this.messageService.addMessage({ @@ -173,7 +173,7 @@ export class DetailsBusinessListingComponent { type: 'business', }); if (result) { - this.auditService.createEvent(this.listing.id, 'email', this.user?.email); + this.auditService.createEvent(this.listing.id, 'email', this.user?.email, result); this.messageService.addMessage({ severity: 'success', text: 'Your Email has beend sent', diff --git a/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts b/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts index 44abc5e..133bf46 100644 --- a/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts +++ b/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts @@ -6,7 +6,7 @@ import { KeycloakService } from 'keycloak-angular'; import { GalleryModule, ImageItem } from 'ng-gallery'; import { ShareButton } from 'ngx-sharebuttons/button'; import { lastValueFrom } from 'rxjs'; -import { CommercialPropertyListing, EventTypeEnum, User } from '../../../../../../bizmatch-server/src/models/db.model'; +import { CommercialPropertyListing, EventTypeEnum, ShareByEMail, User } from '../../../../../../bizmatch-server/src/models/db.model'; import { CommercialPropertyListingCriteria, ErrorResponse, KeycloakUser, MailInfo } from '../../../../../../bizmatch-server/src/models/main.model'; import { environment } from '../../../../environments/environment'; import { EMailService } from '../../../components/email/email.service'; @@ -143,7 +143,7 @@ export class DetailsCommercialPropertyListingComponent { this.mailinfo.email = this.listingUser.email; this.mailinfo.listing = this.listing; await this.mailService.mail(this.mailinfo); - this.auditService.createEvent(this.listing.id, 'contact', this.user?.email); + this.auditService.createEvent(this.listing.id, 'contact', this.user?.email, this.mailinfo.sender); this.messageService.addMessage({ severity: 'success', text: 'Your message has been sent to the creator of the listing', duration: 3000 }); } catch (error) { this.messageService.addMessage({ @@ -183,7 +183,7 @@ export class DetailsCommercialPropertyListingComponent { type: 'commercialProperty', }); if (result) { - this.auditService.createEvent(this.listing.id, 'email', this.user?.email); + this.auditService.createEvent(this.listing.id, 'email', this.user?.email, result); this.messageService.addMessage({ severity: 'success', text: 'Your Email has beend sent', diff --git a/bizmatch/src/app/services/audit.service.ts b/bizmatch/src/app/services/audit.service.ts index 1fefe47..ae8ac3d 100644 --- a/bizmatch/src/app/services/audit.service.ts +++ b/bizmatch/src/app/services/audit.service.ts @@ -1,6 +1,6 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { BehaviorSubject, lastValueFrom, Observable } from 'rxjs'; +import { lastValueFrom } from 'rxjs'; import { EventTypeEnum, ListingEvent } from '../../../../bizmatch-server/src/models/db.model'; import { LogMessage } from '../../../../bizmatch-server/src/models/main.model'; import { environment } from '../../environments/environment'; @@ -12,21 +12,13 @@ import { GeoService } from './geo.service'; export class AuditService { private apiBaseUrl = environment.apiBaseUrl; private apiKey = environment.ipinfo_token; - // private ipifyUrl = 'https://api.ipify.org?format=json'; - // private ipInfoUrl = 'https://ipinfo.io'; - private ipifyUrl = 'https://api.ipify.org?format=json'; - private ipInfoUrl = 'https://ipinfo.io'; - - // BehaviorSubject to store the geolocation data - private geoLocationSubject = new BehaviorSubject(null); - public geoLocation$: Observable = this.geoLocationSubject.asObservable(); constructor(private http: HttpClient, private geoService: GeoService) {} async log(message: LogMessage): Promise { lastValueFrom(this.http.post(`${this.apiBaseUrl}/bizmatch/log`, message)); } - async createEvent(id: string, eventType: EventTypeEnum, userId: string): Promise { + async createEvent(id: string, eventType: EventTypeEnum, userId: string, additionalData?): Promise { const ipInfo = await this.geoService.getIpInfo(); const [latitude, longitude] = ipInfo.loc ? ipInfo.loc.split(',') : [null, null]; //.map(Number); const listingEvent: ListingEvent = { @@ -40,7 +32,9 @@ export class AuditService { locationCity: ipInfo.city, locationLat: latitude, locationLng: longitude, + additionalData, }; - lastValueFrom(this.http.post(`${this.apiBaseUrl}/bizmatch/event`, listingEvent)); + let headers = new HttpHeaders().set('X-Hide-Loading', 'true'); + lastValueFrom(this.http.post(`${this.apiBaseUrl}/bizmatch/event`, listingEvent, { headers })); } }