From 0473f742412caacb9f7d2edc29d9e4cb7c8f8f21 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Fri, 24 May 2024 18:15:33 -0500 Subject: [PATCH] Issues #47,#42, #35 resolved, request logging erweitert --- bizmatch-server/src/listings/listings.service.ts | 3 ++- .../request-duration.middleware.ts | 15 ++++++++++++--- bizmatch/src/app/guards/auth.guard.ts | 1 + .../details-business-listing.component.ts | 12 +++++++++--- ...tails-commercial-property-listing.component.ts | 9 +++++++-- .../subscription/account/account.component.ts | 2 +- .../edit-business-listing.component.ts | 2 -- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/bizmatch-server/src/listings/listings.service.ts b/bizmatch-server/src/listings/listings.service.ts index b08d98a..1619066 100644 --- a/bizmatch-server/src/listings/listings.service.ts +++ b/bizmatch-server/src/listings/listings.service.ts @@ -1,5 +1,5 @@ import { Inject, Injectable } from '@nestjs/common'; -import { and, eq, gte, ilike, lte, sql } from 'drizzle-orm'; +import { and, eq, gte, ilike, lte, ne, sql } from 'drizzle-orm'; import { NodePgDatabase } from 'drizzle-orm/node-postgres'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { BusinessListing, CommercialPropertyListing } from 'src/models/db.model.js'; @@ -18,6 +18,7 @@ export class ListingsService { ) {} private getConditions(criteria: ListingCriteria, table: typeof businesses | typeof commercials): any[] { const conditions = []; + conditions.push(ne(table.draft, true)); if (criteria.type) { conditions.push(eq(table.type, criteria.type)); } diff --git a/bizmatch-server/src/request-duration/request-duration.middleware.ts b/bizmatch-server/src/request-duration/request-duration.middleware.ts index 00f2c81..2f64805 100644 --- a/bizmatch-server/src/request-duration/request-duration.middleware.ts +++ b/bizmatch-server/src/request-duration/request-duration.middleware.ts @@ -1,5 +1,5 @@ -import { Injectable, NestMiddleware, Logger } from '@nestjs/common'; -import { Request, Response, NextFunction } from 'express'; +import { Injectable, Logger, NestMiddleware } from '@nestjs/common'; +import { NextFunction, Request, Response } from 'express'; @Injectable() export class RequestDurationMiddleware implements NestMiddleware { @@ -8,8 +8,17 @@ export class RequestDurationMiddleware implements NestMiddleware { use(req: Request, res: Response, next: NextFunction) { const start = Date.now(); res.on('finish', () => { + // const duration = Date.now() - start; + // this.logger.log(`${req.method} ${req.url} - ${duration}ms`); const duration = Date.now() - start; - this.logger.log(`${req.method} ${req.url} - ${duration}ms`); + let logMessage = `${req.method} ${req.url} - ${duration}ms`; + + if (req.method === 'POST' || req.method === 'PUT') { + const body = JSON.stringify(req.body); + logMessage += ` - Body: ${body}`; + } + + this.logger.log(logMessage); }); next(); } diff --git a/bizmatch/src/app/guards/auth.guard.ts b/bizmatch/src/app/guards/auth.guard.ts index 1d71b72..5d208f7 100644 --- a/bizmatch/src/app/guards/auth.guard.ts +++ b/bizmatch/src/app/guards/auth.guard.ts @@ -20,6 +20,7 @@ export class AuthGuard extends KeycloakAuthGuard { } // Force the user to log in if currently unauthenticated. const authenticated = this.keycloak.isLoggedIn(); + //this.keycloak.isTokenExpired() if (!this.authenticated && !authenticated) { await this.keycloak.login({ redirectUri: window.location.origin + state.url, 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 3ec3d42..b0c2336 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 @@ -15,7 +15,7 @@ import { MailService } from '../../../services/mail.service'; import { SelectOptionsService } from '../../../services/select-options.service'; import { UserService } from '../../../services/user.service'; import { SharedModule } from '../../../shared/shared/shared.module'; -import { getCriteriaStateObject, getSessionStorageHandler } from '../../../utils/utils'; +import { getCriteriaStateObject, getSessionStorageHandler, map2User } from '../../../utils/utils'; @Component({ selector: 'app-details-business-listing', @@ -49,7 +49,8 @@ export class DetailsBusinessListingComponent { criteria: ListingCriteria; mailinfo: MailInfo; environment = environment; - user: KeycloakUser; + keycloakUser: KeycloakUser; + user: User; listingUser: User; description: SafeHtml; private history: string[] = []; @@ -73,11 +74,16 @@ export class DetailsBusinessListingComponent { } }); this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl }; - this.user; this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler); } async ngOnInit() { + const token = await this.keycloakService.getToken(); + this.keycloakUser = map2User(token); + if (this.keycloakUser) { + this.user = await this.userService.getByMail(this.keycloakUser.email); + this.mailinfo.sender = { name: `${this.user.firstname} ${this.user.lastname}`, email: this.user.email, phoneNumber: this.user.email, state: this.user.companyLocation }; + } this.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'business')); this.listingUser = await this.userService.getById(this.listing.userId); this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description); 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 050633a..175c909 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 @@ -49,7 +49,8 @@ export class DetailsCommercialPropertyListingComponent { criteria: ListingCriteria; mailinfo: MailInfo; environment = environment; - user: KeycloakUser; + keycloakUser: KeycloakUser; + user: User; listingUser: User; description: SafeHtml; ts = new Date().getTime(); @@ -75,7 +76,11 @@ export class DetailsCommercialPropertyListingComponent { async ngOnInit() { const token = await this.keycloakService.getToken(); - this.user = map2User(token); + this.keycloakUser = map2User(token); + if (this.keycloakUser) { + this.user = await this.userService.getByMail(this.keycloakUser.email); + this.mailinfo.sender = { name: `${this.user.firstname} ${this.user.lastname}`, email: this.user.email, phoneNumber: this.user.email, state: this.user.companyLocation }; + } this.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'commercialProperty')); this.listingUser = await this.userService.getById(this.listing.userId); this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description); diff --git a/bizmatch/src/app/pages/subscription/account/account.component.ts b/bizmatch/src/app/pages/subscription/account/account.component.ts index c8806fd..67a3f91 100644 --- a/bizmatch/src/app/pages/subscription/account/account.component.ts +++ b/bizmatch/src/app/pages/subscription/account/account.component.ts @@ -87,7 +87,7 @@ export class AccountComponent { async updateProfile(user: User) { await this.userService.save(this.user); - this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Acount changes have been persisted', life: 3000 }); + this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Account changes have been persisted', life: 3000 }); } onUploadCompanyLogo(event: any) { diff --git a/bizmatch/src/app/pages/subscription/edit-business-listing/edit-business-listing.component.ts b/bizmatch/src/app/pages/subscription/edit-business-listing/edit-business-listing.component.ts index abfbd53..5bd37e5 100644 --- a/bizmatch/src/app/pages/subscription/edit-business-listing/edit-business-listing.component.ts +++ b/bizmatch/src/app/pages/subscription/edit-business-listing/edit-business-listing.component.ts @@ -60,7 +60,6 @@ export class EditBusinessListingComponent { private id: string | undefined = this.activatedRoute.snapshot.params['id'] as string | undefined; user: User; maxFileSize = 3000000; - uploadUrl: string; environment = environment; responsiveOptions = [ { @@ -130,7 +129,6 @@ export class EditBusinessListingComponent { this.listing.description = this.data?.description; } } - this.uploadUrl = `${environment.apiBaseUrl}/bizmatch/image/uploadPropertyPicture/${this.listing.id}`; } async save() {