fix: production readiness — resolve build, lint, and code quality issues

- Fix Next.js build failure: remove duplicate route at (dashboard)/listings/[id]
  that conflicted with (public)/listings/[id] (same URL path in two route groups)
- Fix 772 ESLint errors: auto-fix import ordering (import-x/order), remove unused
  imports/variables, convert empty interfaces to type aliases, replace require()
  with ESM imports, fix consistent-type-imports violations
- Add CLAUDE.md for developer onboarding documentation
- All checks pass: 0 lint errors, typecheck clean, 230 tests passing, build success

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 07:15:06 +07:00
parent afa70320f5
commit 2502aa69b7
239 changed files with 746 additions and 984 deletions

View File

@@ -1,18 +1,18 @@
import { Inject, Logger } from '@nestjs/common';
import { CommandHandler, EventBus, type ICommandHandler } from '@nestjs/cqrs';
import { CommandHandler, type EventBus, type ICommandHandler } from '@nestjs/cqrs';
import { createId } from '@paralleldrive/cuid2';
import { ConflictException, ValidationException } from '@modules/shared/domain/domain-exception';
import { CreatePaymentCommand } from './create-payment.command';
import { PaymentEntity } from '../../../domain/entities/payment.entity';
import {
PAYMENT_REPOSITORY,
type IPaymentRepository,
} from '../../../domain/repositories/payment.repository';
import { Money } from '../../../domain/value-objects/money.vo';
import {
PAYMENT_GATEWAY_FACTORY,
type IPaymentGatewayFactory,
} from '../../../infrastructure/services/payment-gateway.interface';
import { PaymentEntity } from '../../../domain/entities/payment.entity';
import { Money } from '../../../domain/value-objects/money.vo';
import { CreatePaymentCommand } from './create-payment.command';
export interface CreatePaymentResult {
paymentId: string;

View File

@@ -1,7 +1,6 @@
import { Inject, Logger } from '@nestjs/common';
import { CommandHandler, EventBus, type ICommandHandler } from '@nestjs/cqrs';
import { CommandHandler, type EventBus, type ICommandHandler } from '@nestjs/cqrs';
import { NotFoundException, ValidationException } from '@modules/shared/domain/domain-exception';
import { HandleCallbackCommand } from './handle-callback.command';
import {
PAYMENT_REPOSITORY,
type IPaymentRepository,
@@ -10,6 +9,7 @@ import {
PAYMENT_GATEWAY_FACTORY,
type IPaymentGatewayFactory,
} from '../../../infrastructure/services/payment-gateway.interface';
import { HandleCallbackCommand } from './handle-callback.command';
export interface HandleCallbackResult {
paymentId: string;

View File

@@ -1,7 +1,6 @@
import { Inject, Logger } from '@nestjs/common';
import { CommandHandler, type ICommandHandler } from '@nestjs/cqrs';
import { NotFoundException, ValidationException } from '@modules/shared/domain/domain-exception';
import { RefundPaymentCommand } from './refund-payment.command';
import {
PAYMENT_REPOSITORY,
type IPaymentRepository,
@@ -10,6 +9,7 @@ import {
PAYMENT_GATEWAY_FACTORY,
type IPaymentGatewayFactory,
} from '../../../infrastructure/services/payment-gateway.interface';
import { RefundPaymentCommand } from './refund-payment.command';
export interface RefundPaymentResult {
paymentId: string;

View File

@@ -1,11 +1,11 @@
import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { NotFoundException, ForbiddenException } from '@modules/shared/domain/domain-exception';
import { GetPaymentStatusQuery } from './get-payment-status.query';
import {
PAYMENT_REPOSITORY,
type IPaymentRepository,
} from '../../../domain/repositories/payment.repository';
import { GetPaymentStatusQuery } from './get-payment-status.query';
export interface PaymentStatusDto {
id: string;

View File

@@ -1,10 +1,10 @@
import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { ListTransactionsQuery } from './list-transactions.query';
import {
PAYMENT_REPOSITORY,
type IPaymentRepository,
} from '../../../domain/repositories/payment.repository';
import { ListTransactionsQuery } from './list-transactions.query';
export interface TransactionItemDto {
id: string;

View File

@@ -1,9 +1,9 @@
import { describe, it, expect } from 'vitest';
import { PaymentEntity } from '../entities/payment.entity';
import { Money } from '../value-objects/money.vo';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { PaymentCompletedEvent } from '../events/payment-completed.event';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { PaymentFailedEvent } from '../events/payment-failed.event';
import { Money } from '../value-objects/money.vo';
describe('PaymentEntity', () => {
const createPayment = (status?: string) => {

View File

@@ -1,13 +1,13 @@
import { AggregateRoot } from '@modules/shared/domain/aggregate-root';
import {
type PaymentProvider,
type PaymentStatus,
type PaymentType,
} from '@prisma/client';
import { type Money } from '../value-objects/money.vo';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { AggregateRoot } from '@modules/shared/domain/aggregate-root';
import { PaymentCompletedEvent } from '../events/payment-completed.event';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { PaymentFailedEvent } from '../events/payment-failed.event';
import { type Money } from '../value-objects/money.vo';
export interface PaymentProps {
userId: string;

View File

@@ -1,5 +1,5 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PaymentProvider } from '@prisma/client';
import { type DomainEvent } from '@modules/shared/domain/domain-event';
export class PaymentCompletedEvent implements DomainEvent {
readonly eventName = 'payment.completed';

View File

@@ -1,5 +1,5 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PaymentProvider, type PaymentType } from '@prisma/client';
import { type DomainEvent } from '@modules/shared/domain/domain-event';
export class PaymentCreatedEvent implements DomainEvent {
readonly eventName = 'payment.created';

View File

@@ -1,5 +1,5 @@
import { type DomainEvent } from '@modules/shared/domain/domain-event';
import { type PaymentProvider } from '@prisma/client';
import { type DomainEvent } from '@modules/shared/domain/domain-event';
export class PaymentFailedEvent implements DomainEvent {
readonly eventName = 'payment.failed';

View File

@@ -1,5 +1,5 @@
import { type PaymentEntity } from '../entities/payment.entity';
import { type PaymentStatus } from '@prisma/client';
import { type PaymentEntity } from '../entities/payment.entity';
export const PAYMENT_REPOSITORY = Symbol('PAYMENT_REPOSITORY');

View File

@@ -1,5 +1,5 @@
import { ValueObject } from '@modules/shared/domain/value-object';
import { Result } from '@modules/shared/domain/result';
import { ValueObject } from '@modules/shared/domain/value-object';
interface MoneyProps {
amountVND: bigint;

View File

@@ -1,7 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';
import { MomoService } from '../services/momo.service';
import { PaymentGatewayFactory } from '../services/payment-gateway.factory';
import { VnpayService } from '../services/vnpay.service';
import { MomoService } from '../services/momo.service';
import { ZalopayService } from '../services/zalopay.service';
describe('PaymentGatewayFactory', () => {

View File

@@ -1,3 +1,4 @@
import * as crypto from 'crypto';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { VnpayService } from '../services/vnpay.service';
@@ -38,7 +39,6 @@ describe('VnpayService', () => {
};
// Generate valid hash
const crypto = require('crypto');
const sorted = Object.keys(params)
.sort()
.reduce((acc: Record<string, string>, key) => {
@@ -83,7 +83,6 @@ describe('VnpayService', () => {
vnp_TransactionNo: 'VNP123',
};
const crypto = require('crypto');
const sorted = Object.keys(params)
.sort()
.reduce((acc: Record<string, string>, key) => {

View File

@@ -1,8 +1,8 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '@modules/shared/infrastructure/prisma.service';
import { Prisma, type Payment as PrismaPayment, type PaymentStatus } from '@prisma/client';
import { type IPaymentRepository } from '../../domain/repositories/payment.repository';
import { type PrismaService } from '@modules/shared/infrastructure/prisma.service';
import { PaymentEntity, type PaymentProps } from '../../domain/entities/payment.entity';
import { type IPaymentRepository } from '../../domain/repositories/payment.repository';
import { Money } from '../../domain/value-objects/money.vo';
@Injectable()

View File

@@ -1,6 +1,6 @@
import * as crypto from 'crypto';
import { Injectable, Logger } from '@nestjs/common';
import { type PaymentProvider } from '@prisma/client';
import * as crypto from 'crypto';
import {
type IPaymentGateway,
type CreatePaymentUrlParams,

View File

@@ -1,12 +1,12 @@
import { Injectable, BadRequestException } from '@nestjs/common';
import { type PaymentProvider } from '@prisma/client';
import { type MomoService } from './momo.service';
import {
type IPaymentGateway,
type IPaymentGatewayFactory,
} from './payment-gateway.interface';
import { VnpayService } from './vnpay.service';
import { MomoService } from './momo.service';
import { ZalopayService } from './zalopay.service';
import { type VnpayService } from './vnpay.service';
import { type ZalopayService } from './zalopay.service';
@Injectable()
export class PaymentGatewayFactory implements IPaymentGatewayFactory {

View File

@@ -1,6 +1,6 @@
import * as crypto from 'crypto';
import { Injectable, Logger } from '@nestjs/common';
import { type PaymentProvider } from '@prisma/client';
import * as crypto from 'crypto';
import {
type IPaymentGateway,
type CreatePaymentUrlParams,

View File

@@ -1,6 +1,6 @@
import * as crypto from 'crypto';
import { Injectable, Logger } from '@nestjs/common';
import { type PaymentProvider } from '@prisma/client';
import * as crypto from 'crypto';
import {
type IPaymentGateway,
type CreatePaymentUrlParams,

View File

@@ -1,27 +1,17 @@
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
// Domain
import { PAYMENT_REPOSITORY } from './domain/repositories/payment.repository';
// Infrastructure
import { PrismaPaymentRepository } from './infrastructure/repositories/prisma-payment.repository';
import { PAYMENT_GATEWAY_FACTORY } from './infrastructure/services/payment-gateway.interface';
import { PaymentGatewayFactory } from './infrastructure/services/payment-gateway.factory';
import { VnpayService } from './infrastructure/services/vnpay.service';
import { MomoService } from './infrastructure/services/momo.service';
import { ZalopayService } from './infrastructure/services/zalopay.service';
// Application — Commands
import { CreatePaymentHandler } from './application/commands/create-payment/create-payment.handler';
import { HandleCallbackHandler } from './application/commands/handle-callback/handle-callback.handler';
import { RefundPaymentHandler } from './application/commands/refund-payment/refund-payment.handler';
// Application — Queries
import { GetPaymentStatusHandler } from './application/queries/get-payment-status/get-payment-status.handler';
import { ListTransactionsHandler } from './application/queries/list-transactions/list-transactions.handler';
// Presentation
import { PAYMENT_REPOSITORY } from './domain/repositories/payment.repository';
import { PrismaPaymentRepository } from './infrastructure/repositories/prisma-payment.repository';
import { MomoService } from './infrastructure/services/momo.service';
import { PaymentGatewayFactory } from './infrastructure/services/payment-gateway.factory';
import { PAYMENT_GATEWAY_FACTORY } from './infrastructure/services/payment-gateway.interface';
import { VnpayService } from './infrastructure/services/vnpay.service';
import { ZalopayService } from './infrastructure/services/zalopay.service';
import { PaymentsController } from './presentation/controllers/payments.controller';
const CommandHandlers = [

View File

@@ -8,6 +8,7 @@ import {
Query,
UseGuards,
} from '@nestjs/common';
import { type CommandBus, type QueryBus } from '@nestjs/cqrs';
import {
ApiTags,
ApiOperation,
@@ -16,26 +17,25 @@ import {
ApiParam,
} from '@nestjs/swagger';
import { Throttle } from '@nestjs/throttler';
import { CommandBus, QueryBus } from '@nestjs/cqrs';
import { JwtAuthGuard } from '@modules/auth/presentation/guards/jwt-auth.guard';
import { RolesGuard } from '@modules/auth/presentation/guards/roles.guard';
import { type PaymentProvider } from '@prisma/client';
import { type JwtPayload } from '@modules/auth/infrastructure/services/token.service';
import { CurrentUser } from '@modules/auth/presentation/decorators/current-user.decorator';
import { Roles } from '@modules/auth/presentation/decorators/roles.decorator';
import { type JwtPayload } from '@modules/auth/infrastructure/services/token.service';
import { JwtAuthGuard } from '@modules/auth/presentation/guards/jwt-auth.guard';
import { RolesGuard } from '@modules/auth/presentation/guards/roles.guard';
import { CreatePaymentCommand } from '../../application/commands/create-payment/create-payment.command';
import { HandleCallbackCommand } from '../../application/commands/handle-callback/handle-callback.command';
import { RefundPaymentCommand } from '../../application/commands/refund-payment/refund-payment.command';
import { GetPaymentStatusQuery } from '../../application/queries/get-payment-status/get-payment-status.query';
import { ListTransactionsQuery } from '../../application/queries/list-transactions/list-transactions.query';
import { type CreatePaymentResult } from '../../application/commands/create-payment/create-payment.handler';
import { HandleCallbackCommand } from '../../application/commands/handle-callback/handle-callback.command';
import { type HandleCallbackResult } from '../../application/commands/handle-callback/handle-callback.handler';
import { RefundPaymentCommand } from '../../application/commands/refund-payment/refund-payment.command';
import { type RefundPaymentResult } from '../../application/commands/refund-payment/refund-payment.handler';
import { type PaymentStatusDto } from '../../application/queries/get-payment-status/get-payment-status.handler';
import { GetPaymentStatusQuery } from '../../application/queries/get-payment-status/get-payment-status.query';
import { type TransactionListDto } from '../../application/queries/list-transactions/list-transactions.handler';
import { CreatePaymentDto } from '../dto/create-payment.dto';
import { RefundPaymentDto } from '../dto/refund-payment.dto';
import { ListTransactionsDto } from '../dto/list-transactions.dto';
import { type PaymentProvider } from '@prisma/client';
import { ListTransactionsQuery } from '../../application/queries/list-transactions/list-transactions.query';
import { type CreatePaymentDto } from '../dto/create-payment.dto';
import { type ListTransactionsDto } from '../dto/list-transactions.dto';
import { type RefundPaymentDto } from '../dto/refund-payment.dto';
@ApiTags('payments')
@Controller('payments')

View File

@@ -1,3 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { PaymentProvider, PaymentType } from '@prisma/client';
import { Transform } from 'class-transformer';
import {
IsEnum,
IsNotEmpty,
@@ -9,9 +12,6 @@ import {
Min,
MinLength,
} from 'class-validator';
import { Transform } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { PaymentProvider, PaymentType } from '@prisma/client';
export class CreatePaymentDto {
@ApiProperty({ enum: PaymentProvider, description: 'Payment provider' })

View File

@@ -1,6 +1,6 @@
import { IsEnum, IsInt, IsOptional, Max, Min } from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { PaymentStatus } from '@prisma/client';
import { IsEnum, IsInt, IsOptional, Max, Min } from 'class-validator';
export class ListTransactionsDto {
@ApiPropertyOptional({ enum: PaymentStatus, description: 'Filter by payment status' })

View File

@@ -1,5 +1,5 @@
import { IsString, MinLength } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsString, MinLength } from 'class-validator';
export class RefundPaymentDto {
@ApiProperty({ description: 'Reason for the refund', example: 'Customer requested cancellation' })