forked from Shared/esg
feat: add Persian error translations and comprehensive test suite
Implement normalized error handling with Persian translations across all exception types, replace legacy NestJS exceptions with AppException, and add unit, integration, and smoke tests. - Add error catalog with gateway-owned codes and Persian messages - Introduce AppException wrapping normalized error envelopes - Add translateError helper for automatic messageFa population - Remove claims module and update provider error normalization - Add unit tests for error contracts and helper functions - Add integration tests for admin and inquiry endpoints - Add smoke tests for real provider connectivity - Add test support utilities (auth mocks, assertions, app factory)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ConflictException, Injectable, Logger } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { randomBytes } from 'crypto';
|
||||
@@ -8,6 +8,7 @@ import { PasswordService } from '../auth/services/password.service';
|
||||
import { User, UserDocument } from '../users/schemas/user.schema';
|
||||
import { UserMapper } from '../users/mappers/user.mapper';
|
||||
import { UserResponseDto } from '../users/dto/user-response.dto';
|
||||
import { AppException } from '../common/exceptions/app-exception';
|
||||
|
||||
export interface CreateSuperAdminInput {
|
||||
fullName: string;
|
||||
@@ -27,7 +28,7 @@ export class CreateSuperAdminService {
|
||||
|
||||
async create(input: CreateSuperAdminInput): Promise<UserResponseDto> {
|
||||
if (input.password.length < 8) {
|
||||
throw new ConflictException('Password must be at least 8 characters');
|
||||
throw new AppException('PASSWORD_TOO_SHORT');
|
||||
}
|
||||
|
||||
const username = input.username.toLowerCase().trim();
|
||||
@@ -35,7 +36,7 @@ export class CreateSuperAdminService {
|
||||
|
||||
const existing = await this.userModel.findOne({ $or: [{ username }, { email }] });
|
||||
if (existing) {
|
||||
throw new ConflictException('Username or email already exists');
|
||||
throw new AppException('USERNAME_OR_EMAIL_EXISTS');
|
||||
}
|
||||
|
||||
const superAdminExists = await this.userModel.exists({ role: Role.SUPER_ADMIN });
|
||||
|
||||
Reference in New Issue
Block a user