Moved DB config to ENV (#4)
Co-authored-by: Joe Arndt <jmarndt@users.noreply.github.com> Reviewed-on: #4
This commit is contained in:
parent
6600745072
commit
164e51bf03
10 changed files with 431 additions and 80 deletions
|
|
@ -1,29 +1,29 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { MerchantsModule } from './merchants/merchants.module';
|
||||
import { Merchant } from './merchants/entities/merchant.entity';
|
||||
import { TagsModule } from './tags/tags.module';
|
||||
import { Tag } from './tags/entities/tag.entity';
|
||||
import { CategoriesModule } from './categories/categories.module';
|
||||
import { Category } from './categories/entities/category.entity';
|
||||
import { SubCategoriesModule } from './sub-categories/sub-categories.module';
|
||||
import { SubCategory } from './sub-categories/entities/sub-category.entity';
|
||||
import { ExpensesModule } from './expenses/expenses.module';
|
||||
import { Expense } from './expenses/entities/expense.entity';
|
||||
|
||||
const entities = [Merchant, Tag, Category, SubCategory, Expense];
|
||||
|
||||
const sqliteConfig: TypeOrmModuleOptions = {
|
||||
synchronize: true,
|
||||
type: 'sqlite',
|
||||
database: 'common-cents.db',
|
||||
entities
|
||||
}
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRoot(sqliteConfig),
|
||||
TypeOrmModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
synchronize: configService.get<boolean>('DB_SYNC') ?? true,
|
||||
type: 'postgres',
|
||||
host: configService.get<string>('DB_HOST') ?? 'localhost',
|
||||
port: configService.get<number>('DB_PORT') ?? 5432,
|
||||
username: configService.get<string>('DB_USER') ?? 'common-cents',
|
||||
password: configService.get<string>('DB_PASS') ?? 'CommonCents_123!',
|
||||
database: configService.get<string>('DB_NAME') ?? 'common-cents',
|
||||
autoLoadEntities: true
|
||||
})
|
||||
}),
|
||||
MerchantsModule,
|
||||
TagsModule,
|
||||
CategoriesModule,
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import { Module } from '@nestjs/common';
|
|||
import { CategoriesService } from './categories.service';
|
||||
import { CategoriesController } from './categories.controller';
|
||||
import { CategoryDataService } from './category-data.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Category } from './entities/category.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [CategoriesController],
|
||||
providers: [CategoriesService, CategoryDataService]
|
||||
providers: [CategoriesService, CategoryDataService],
|
||||
imports: [TypeOrmModule.forFeature([Category])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class CategoriesModule { }
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import { Module } from '@nestjs/common';
|
|||
import { ExpensesService } from './expenses.service';
|
||||
import { ExpensesController } from './expenses.controller';
|
||||
import { ExpenseDataService } from './expense-data.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Expense } from './entities/expense.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [ExpensesController],
|
||||
providers: [ExpensesService, ExpenseDataService],
|
||||
imports: [TypeOrmModule.forFeature([Expense])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class ExpensesModule { }
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import { Module } from '@nestjs/common';
|
|||
import { MerchantsService } from './merchants.service';
|
||||
import { MerchantsController } from './merchants.controller';
|
||||
import { MerchantDataService } from './merchant-data.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Merchant } from './entities/merchant.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [MerchantsController],
|
||||
providers: [MerchantsService, MerchantDataService]
|
||||
providers: [MerchantsService, MerchantDataService],
|
||||
imports: [TypeOrmModule.forFeature([Merchant])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class MerchantsModule { }
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import { Module } from '@nestjs/common';
|
|||
import { SubCategoriesService } from './sub-categories.service';
|
||||
import { SubCategoriesController } from './sub-categories.controller';
|
||||
import { SubCategoryDataService } from './sub-category-data.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { SubCategory } from './entities/sub-category.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [SubCategoriesController],
|
||||
providers: [SubCategoriesService, SubCategoryDataService]
|
||||
providers: [SubCategoriesService, SubCategoryDataService],
|
||||
imports: [TypeOrmModule.forFeature([SubCategory])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class SubCategoriesModule { }
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ import { Module } from '@nestjs/common';
|
|||
import { TagsService } from './tags.service';
|
||||
import { TagsController } from './tags.controller';
|
||||
import { TagDataService } from './tag-data.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Tag } from './entities/tag.entity';
|
||||
|
||||
@Module({
|
||||
controllers: [TagsController],
|
||||
providers: [TagsService, TagDataService]
|
||||
providers: [TagsService, TagDataService],
|
||||
imports: [TypeOrmModule.forFeature([Tag])],
|
||||
exports: [TypeOrmModule]
|
||||
})
|
||||
export class TagsModule { }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue