|
1 | 1 | import { Module } from '@nestjs/common'; |
2 | | -import { TypeOrmModule } from '@nestjs/typeorm'; |
3 | 2 | import { ConfigModule, ConfigService } from '@nestjs/config'; |
4 | 3 | import { AppController } from './app.controller'; |
5 | 4 | import { AppService } from './app.service'; |
6 | 5 | import { AssetCategoriesModule } from './asset-categories/asset-categories.module'; |
7 | 6 | import { AssetCategory } from './asset-categories/asset-category.entity'; |
8 | 7 | import { DepartmentsModule } from './departments/departments.module'; |
9 | 8 | import { Department } from './departments/department.entity'; |
| 9 | +import { SuppliersModule } from './suppliers/suppliers.module'; |
| 10 | +import { |
| 11 | + I18nModule, |
| 12 | + QueryResolver, |
| 13 | + HeaderResolver, |
| 14 | + AcceptLanguageResolver, |
| 15 | +} from 'nestjs-i18n'; |
| 16 | +import * as path from 'path'; |
| 17 | +import { Supplier } from './suppliers/entities/supplier.entity'; |
| 18 | +import { TypeOrmModule } from '@nestjs/typeorm'; |
10 | 19 |
|
11 | 20 | @Module({ |
12 | 21 | imports: [ |
13 | 22 | ConfigModule.forRoot({ |
14 | 23 | isGlobal: true, |
15 | 24 | }), |
16 | | - TypeOrmModule.forRootAsync({ |
17 | | - imports: [ConfigModule, |
18 | | - // --- ADD THIS CONFIGURATION --- |
19 | | - I18nModule.forRoot({ |
| 25 | + |
| 26 | + // i18n should be registered at top-level imports (not nested inside TypeOrm import) |
| 27 | + I18nModule.forRoot({ |
20 | 28 | fallbackLanguage: 'en', |
21 | 29 | loaderOptions: { |
22 | | - path: path.join(__dirname, '/i18n/'), // Directory for translation files |
23 | | - watch: true, // Watch for changes in translation files |
| 30 | + path: path.join(__dirname, '/i18n/'), |
| 31 | + watch: true, |
24 | 32 | }, |
25 | 33 | resolvers: [ |
26 | | - // Order matters: checks query param, then header, then browser settings |
27 | | - new QueryResolver(['lang', 'l']), |
28 | | - new HeaderResolver(['x-custom-lang-header']), |
29 | | - AcceptLanguageResolver, // Standard 'Accept-Language' header |
| 34 | + { use: QueryResolver, options: ['lang', 'l'] }, |
| 35 | + { use: HeaderResolver, options: ['x-custom-lang-header'] }, |
| 36 | + AcceptLanguageResolver, |
30 | 37 | ], |
31 | 38 | }), |
32 | | - // --- END OF CONFIGURATION --- |
33 | | - ],], |
| 39 | + |
| 40 | + // TypeORM async config |
| 41 | + TypeOrmModule.forRootAsync({ |
| 42 | + imports: [ConfigModule], |
34 | 43 | useFactory: (configService: ConfigService) => ({ |
35 | 44 | type: 'postgres', |
36 | | - host: configService.get('DB_HOST', 'localhost'), |
37 | | - port: configService.get('DB_PORT', 5432), |
38 | | - username: configService.get('DB_USERNAME', 'postgres'), |
39 | | - password: configService.get('DB_PASSWORD', 'password'), |
40 | | - database: configService.get('DB_DATABASE', 'manage_assets'), |
41 | | - entities: [AssetCategory, Department], |
42 | | - synchronize: configService.get('NODE_ENV') !== 'production', // Only for development |
| 45 | + host: configService.get<string>('DB_HOST', 'localhost'), |
| 46 | + port: Number(configService.get<number>('DB_PORT', 5432)), |
| 47 | + username: configService.get<string>('DB_USERNAME', 'postgres'), |
| 48 | + password: configService.get<string>('DB_PASSWORD', 'password'), |
| 49 | + database: configService.get<string>('DB_DATABASE', 'manage_assets'), |
| 50 | + // include all entity classes used by your app |
| 51 | + entities: [AssetCategory, Department, Supplier], |
| 52 | + synchronize: configService.get<string>('NODE_ENV') !== 'production', |
43 | 53 | }), |
44 | 54 | inject: [ConfigService], |
45 | 55 | }), |
| 56 | + |
46 | 57 | AssetCategoriesModule, |
47 | 58 | DepartmentsModule, |
| 59 | + SuppliersModule, |
48 | 60 | ], |
49 | 61 | controllers: [AppController], |
50 | 62 | providers: [AppService], |
|
0 commit comments