Issues #47,#42, #35 resolved, request logging erweitert
This commit is contained in:
parent
c9d94e973a
commit
0473f74241
|
|
@ -1,5 +1,5 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
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 { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||||
import { BusinessListing, CommercialPropertyListing } from 'src/models/db.model.js';
|
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[] {
|
private getConditions(criteria: ListingCriteria, table: typeof businesses | typeof commercials): any[] {
|
||||||
const conditions = [];
|
const conditions = [];
|
||||||
|
conditions.push(ne(table.draft, true));
|
||||||
if (criteria.type) {
|
if (criteria.type) {
|
||||||
conditions.push(eq(table.type, criteria.type));
|
conditions.push(eq(table.type, criteria.type));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Injectable, NestMiddleware, Logger } from '@nestjs/common';
|
import { Injectable, Logger, NestMiddleware } from '@nestjs/common';
|
||||||
import { Request, Response, NextFunction } from 'express';
|
import { NextFunction, Request, Response } from 'express';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RequestDurationMiddleware implements NestMiddleware {
|
export class RequestDurationMiddleware implements NestMiddleware {
|
||||||
|
|
@ -8,8 +8,17 @@ export class RequestDurationMiddleware implements NestMiddleware {
|
||||||
use(req: Request, res: Response, next: NextFunction) {
|
use(req: Request, res: Response, next: NextFunction) {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
res.on('finish', () => {
|
res.on('finish', () => {
|
||||||
|
// const duration = Date.now() - start;
|
||||||
|
// this.logger.log(`${req.method} ${req.url} - ${duration}ms`);
|
||||||
const duration = Date.now() - start;
|
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();
|
next();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export class AuthGuard extends KeycloakAuthGuard {
|
||||||
}
|
}
|
||||||
// Force the user to log in if currently unauthenticated.
|
// Force the user to log in if currently unauthenticated.
|
||||||
const authenticated = this.keycloak.isLoggedIn();
|
const authenticated = this.keycloak.isLoggedIn();
|
||||||
|
//this.keycloak.isTokenExpired()
|
||||||
if (!this.authenticated && !authenticated) {
|
if (!this.authenticated && !authenticated) {
|
||||||
await this.keycloak.login({
|
await this.keycloak.login({
|
||||||
redirectUri: window.location.origin + state.url,
|
redirectUri: window.location.origin + state.url,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import { MailService } from '../../../services/mail.service';
|
||||||
import { SelectOptionsService } from '../../../services/select-options.service';
|
import { SelectOptionsService } from '../../../services/select-options.service';
|
||||||
import { UserService } from '../../../services/user.service';
|
import { UserService } from '../../../services/user.service';
|
||||||
import { SharedModule } from '../../../shared/shared/shared.module';
|
import { SharedModule } from '../../../shared/shared/shared.module';
|
||||||
import { getCriteriaStateObject, getSessionStorageHandler } from '../../../utils/utils';
|
import { getCriteriaStateObject, getSessionStorageHandler, map2User } from '../../../utils/utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-details-business-listing',
|
selector: 'app-details-business-listing',
|
||||||
|
|
@ -49,7 +49,8 @@ export class DetailsBusinessListingComponent {
|
||||||
criteria: ListingCriteria;
|
criteria: ListingCriteria;
|
||||||
mailinfo: MailInfo;
|
mailinfo: MailInfo;
|
||||||
environment = environment;
|
environment = environment;
|
||||||
user: KeycloakUser;
|
keycloakUser: KeycloakUser;
|
||||||
|
user: User;
|
||||||
listingUser: User;
|
listingUser: User;
|
||||||
description: SafeHtml;
|
description: SafeHtml;
|
||||||
private history: string[] = [];
|
private history: string[] = [];
|
||||||
|
|
@ -73,11 +74,16 @@ export class DetailsBusinessListingComponent {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl };
|
this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl };
|
||||||
this.user;
|
|
||||||
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
|
this.criteria = onChange(getCriteriaStateObject(), getSessionStorageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
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.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'business'));
|
||||||
this.listingUser = await this.userService.getById(this.listing.userId);
|
this.listingUser = await this.userService.getById(this.listing.userId);
|
||||||
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
|
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ export class DetailsCommercialPropertyListingComponent {
|
||||||
criteria: ListingCriteria;
|
criteria: ListingCriteria;
|
||||||
mailinfo: MailInfo;
|
mailinfo: MailInfo;
|
||||||
environment = environment;
|
environment = environment;
|
||||||
user: KeycloakUser;
|
keycloakUser: KeycloakUser;
|
||||||
|
user: User;
|
||||||
listingUser: User;
|
listingUser: User;
|
||||||
description: SafeHtml;
|
description: SafeHtml;
|
||||||
ts = new Date().getTime();
|
ts = new Date().getTime();
|
||||||
|
|
@ -75,7 +76,11 @@ export class DetailsCommercialPropertyListingComponent {
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
const token = await this.keycloakService.getToken();
|
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.listing = await lastValueFrom(this.listingsService.getListingById(this.id, 'commercialProperty'));
|
||||||
this.listingUser = await this.userService.getById(this.listing.userId);
|
this.listingUser = await this.userService.getById(this.listing.userId);
|
||||||
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
|
this.description = this.sanitizer.bypassSecurityTrustHtml(this.listing.description);
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ export class AccountComponent {
|
||||||
|
|
||||||
async updateProfile(user: User) {
|
async updateProfile(user: User) {
|
||||||
await this.userService.save(this.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) {
|
onUploadCompanyLogo(event: any) {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ export class EditBusinessListingComponent {
|
||||||
private id: string | undefined = this.activatedRoute.snapshot.params['id'] as string | undefined;
|
private id: string | undefined = this.activatedRoute.snapshot.params['id'] as string | undefined;
|
||||||
user: User;
|
user: User;
|
||||||
maxFileSize = 3000000;
|
maxFileSize = 3000000;
|
||||||
uploadUrl: string;
|
|
||||||
environment = environment;
|
environment = environment;
|
||||||
responsiveOptions = [
|
responsiveOptions = [
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +129,6 @@ export class EditBusinessListingComponent {
|
||||||
this.listing.description = this.data?.description;
|
this.listing.description = this.data?.description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.uploadUrl = `${environment.apiBaseUrl}/bizmatch/image/uploadPropertyPicture/${this.listing.id}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue