2023-07-23 08:12:21 +00:00
|
|
|
import { Module, OnModuleInit } from '@nestjs/common';
|
2023-07-22 09:01:26 +00:00
|
|
|
import { AssetsController } from './assets.controller';
|
2023-07-23 08:12:21 +00:00
|
|
|
import { AssetsService } from './services/assets.service';
|
2023-07-22 09:01:26 +00:00
|
|
|
import { makeKnex, makeTypeOrm, natsClient } from '@freeblox/shared';
|
|
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
|
import { ClientsModule } from '@nestjs/microservices';
|
|
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
2023-07-23 08:12:21 +00:00
|
|
|
import knex from 'knex';
|
|
|
|
import { AssetEntity } from './database/entities/asset.entity';
|
|
|
|
import { s3Config } from './config/s3.config';
|
|
|
|
import { S3Service } from './services/s3.service';
|
|
|
|
|
|
|
|
const entities = [AssetEntity];
|
2023-07-22 09:01:26 +00:00
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
ConfigModule.forRoot({
|
|
|
|
ignoreEnvFile: process.env.NODE_ENV === 'development',
|
2023-07-23 08:12:21 +00:00
|
|
|
load: [makeKnex('assets', __dirname), makeTypeOrm('assets'), s3Config],
|
2023-07-22 09:01:26 +00:00
|
|
|
}),
|
|
|
|
TypeOrmModule.forRootAsync({
|
|
|
|
imports: [ConfigModule],
|
|
|
|
inject: [ConfigService],
|
2023-07-23 08:12:21 +00:00
|
|
|
useFactory: (config: ConfigService) => ({
|
|
|
|
...config.get('typeorm'),
|
|
|
|
entities,
|
|
|
|
}),
|
2023-07-22 09:01:26 +00:00
|
|
|
}),
|
2023-07-23 08:12:21 +00:00
|
|
|
TypeOrmModule.forFeature(entities),
|
|
|
|
ClientsModule.register([natsClient('assets'), natsClient('auth')]),
|
2023-07-22 09:01:26 +00:00
|
|
|
],
|
|
|
|
controllers: [AssetsController],
|
2023-07-23 08:12:21 +00:00
|
|
|
providers: [S3Service, AssetsService],
|
2023-07-22 09:01:26 +00:00
|
|
|
})
|
2023-07-23 08:12:21 +00:00
|
|
|
export class AssetsModule implements OnModuleInit {
|
|
|
|
constructor(private readonly config: ConfigService) {}
|
|
|
|
|
|
|
|
async onModuleInit() {
|
|
|
|
const knexInstance = knex(this.config.get('knex'));
|
|
|
|
await knexInstance.migrate.latest();
|
|
|
|
}
|
|
|
|
}
|