refactor(api): replace new Logger() with DI LoggerService and split large files

- Migrate 30 files from `new Logger(ClassName.name)` to injected LoggerService
  for consistent PII masking and centralized logging config
- Split prisma-admin-query.repository.ts (313→121 lines) into admin-stats.queries.ts
  and admin-user.queries.ts
- Split admin.controller.ts (285→154 lines) into admin-moderation.controller.ts
- Split prisma-listing.repository.ts (274→111 lines) into listing-read.queries.ts
- Update 28 test files with mock LoggerService
- All 831 tests passing, zero direct new Logger() calls remaining

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-10 05:35:04 +07:00
parent 4e71036ddd
commit 34202f2527
67 changed files with 851 additions and 653 deletions

View File

@@ -1,7 +1,8 @@
import * as crypto from 'crypto';
import { Injectable, Logger } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { type ConfigService } from '@nestjs/config';
import { type PaymentProvider } from '@prisma/client';
import { type LoggerService } from '@modules/shared';
import {
type IPaymentGateway,
type CreatePaymentUrlParams,
@@ -13,7 +14,6 @@ import {
@Injectable()
export class VnpayService implements IPaymentGateway {
private readonly logger = new Logger(VnpayService.name);
readonly provider: PaymentProvider = 'VNPAY';
private readonly tmnCode: string;
@@ -21,7 +21,10 @@ export class VnpayService implements IPaymentGateway {
private readonly baseUrl: string;
private readonly apiUrl: string;
constructor(private readonly config: ConfigService) {
constructor(
private readonly config: ConfigService,
private readonly logger: LoggerService,
) {
this.tmnCode = this.config.getOrThrow<string>('VNPAY_TMN_CODE');
this.hashSecret = this.config.getOrThrow<string>('VNPAY_HASH_SECRET');
this.baseUrl = this.config.get<string>('VNPAY_BASE_URL', 'https://sandbox.vnpayment.vn/paymentv2/vpcpay.html');
@@ -58,7 +61,7 @@ export class VnpayService implements IPaymentGateway {
const paymentUrl = `${this.baseUrl}?${new URLSearchParams(sortedParams).toString()}`;
this.logger.log(`VNPay payment URL created for order ${params.orderId}`);
this.logger.log(`VNPay payment URL created for order ${params.orderId}`, 'VnpayService');
return {
paymentUrl,
@@ -89,6 +92,7 @@ export class VnpayService implements IPaymentGateway {
this.logger.log(
`VNPay callback verified: orderId=${orderId}, valid=${isValid}, success=${isSuccess}`,
'VnpayService',
);
return {
@@ -151,6 +155,7 @@ export class VnpayService implements IPaymentGateway {
this.logger.log(
`VNPay refund ${success ? 'successful' : 'failed'} for ${params.providerTxId}`,
'VnpayService',
);
return {
@@ -158,7 +163,7 @@ export class VnpayService implements IPaymentGateway {
refundTxId: success ? requestId : null,
};
} catch (error) {
this.logger.error(`VNPay refund error: ${error}`);
this.logger.error(`VNPay refund error: ${error}`, undefined, 'VnpayService');
return { success: false, refundTxId: null };
}
}