feat: wip migrate server to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-11-12 23:08:51 +02:00
parent f5834c72c6
commit 19080a67ab
94 changed files with 7587 additions and 98 deletions

View File

@@ -0,0 +1,49 @@
import Knex from 'knex';
import { Global, Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
SystemKnexConnection,
SystemKnexConnectionConfigure,
} from './SystemDB.constants';
import { SystemDatabaseController } from './SystemDB.controller';
import { knexSnakeCaseMappers } from 'objection';
const providers = [
{
provide: SystemKnexConnectionConfigure,
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
client: configService.get('systemDatabase.client'),
connection: {
host: configService.get('systemDatabase.host'),
user: configService.get('systemDatabase.user'),
password: configService.get('systemDatabase.password'),
database: configService.get('systemDatabase.databaseName'),
charset: 'utf8',
},
migrations: {
directory: configService.get('systemDatabase.migrationDir'),
},
seeds: {
directory: configService.get('systemDatabase.seedsDir'),
},
pool: { min: 0, max: 7 },
...knexSnakeCaseMappers({ upperCase: true }),
}),
},
{
provide: SystemKnexConnection,
inject: [SystemKnexConnectionConfigure],
useFactory: (knexConfig) => {
return Knex(knexConfig);
},
},
];
@Global()
@Module({
providers: [...providers],
exports: [...providers],
controllers: [SystemDatabaseController],
})
export class SystemDatabaseModule {}