Issues #47,#42, #35 resolved, request logging erweitert
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user