You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
34 lines
1.2 KiB
import { Sequelize } from 'sequelize-typescript'; |
|
import { SEQUELIZE, DEVELOPMENT, TEST, PRODUCTION } from '../constants'; |
|
import { databaseConfig } from './database.config'; |
|
import { User } from 'src/modules/users/entities/user.entity'; |
|
import { Product } from 'src/modules/products/entities/product.entity'; |
|
import { OrderStatuses } from 'src/modules/orders/entities/order-status.entity'; |
|
import { Order } from 'src/modules/orders/entities/order.entity'; |
|
import { Wallet } from 'src/modules/wallets/entities/wallet.entity'; |
|
|
|
export const databaseProviders = [ |
|
{ |
|
provide: SEQUELIZE, |
|
useFactory: async () => { |
|
let config; |
|
switch (process.env.NODE_ENV) { |
|
case DEVELOPMENT: |
|
config = databaseConfig.development; |
|
break; |
|
case TEST: |
|
config = databaseConfig.test; |
|
break; |
|
case PRODUCTION: |
|
config = databaseConfig.production; |
|
break; |
|
default: |
|
config = databaseConfig.development; |
|
} |
|
const sequelize = new Sequelize(config); |
|
sequelize.addModels([User, Product, Order, OrderStatuses, Wallet]); |
|
await sequelize.sync(); |
|
return sequelize; |
|
}, |
|
}, |
|
];
|
|
|