File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const convictConfig = convict({
1212 doc : 'The Mongo connection URL' ,
1313 format : String ,
1414 env : 'MONGO_URL' ,
15- default : 'mongodb://localhost:27017/dev'
15+ default : 'mongodb://localhost:27017/backoffice-frontend- dev'
1616 }
1717 }
1818} ) ;
Original file line number Diff line number Diff line change 1- {}
1+ {
2+ "mongo" : {
3+ "url" : " mongodb://localhost:27017/backoffice-frontend-test"
4+ }
5+ }
Original file line number Diff line number Diff line change 1+ import { CoursesCounterRepository } from '../../../Contexts/Mooc/CoursesCounter/domain/CoursesCounterRepository' ;
2+ import { CoursesCounter } from '../../../Contexts/Mooc/CoursesCounter/domain/CoursesCounter' ;
3+ import { CoursesCounterId } from '../../../Contexts/Mooc/CoursesCounter/domain/CoursesCounterId' ;
4+ import container from './config/dependency-injection' ;
5+
6+ export async function seed ( ) {
7+ const repository : CoursesCounterRepository = container . get ( 'Mooc.coursesCounter.CoursesCounterRepository' ) ;
8+ const logger = container . get ( 'Contexts.shared.Logger' ) ;
9+
10+ const alreadyExists = await repository . search ( ) ;
11+ const isTestEnvironment = process . env . NODE_ENV === 'test' ;
12+
13+ if ( ! alreadyExists && ! isTestEnvironment ) {
14+ logger . info ( '[Seed] Initializing CourseCounter' ) ;
15+ const courseCounter = CoursesCounter . initialize ( CoursesCounterId . random ( ) ) ;
16+ await repository . save ( courseCounter ) ;
17+ }
18+ }
Original file line number Diff line number Diff line change 11import errorHandler from 'errorhandler' ;
22import app from './app' ;
33import container from './config/dependency-injection' ;
4+ import { seed } from './seed' ;
45
56/**
67 * Error Handler. Provides full stack - remove for production
@@ -10,9 +11,11 @@ app.use(errorHandler());
1011/**
1112 * Start Express server.
1213 */
13- const server = app . listen ( app . get ( 'port' ) , ( ) => {
14+ const server = app . listen ( app . get ( 'port' ) , async ( ) => {
1415 const winstonLogger = container . get ( 'Contexts.shared.Logger' ) ;
1516
17+ await seed ( ) ;
18+
1619 winstonLogger . info (
1720 ` Backoffice frontend is running at http://localhost:${ app . get ( 'port' ) } in ${ app . get ( 'env' ) } mode`
1821 ) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const convictConfig = convict({
1212 doc : 'The Mongo connection URL' ,
1313 format : String ,
1414 env : 'MONGO_URL' ,
15- default : 'mongodb://localhost:27017/dev'
15+ default : 'mongodb://localhost:27017/mooc-backend- dev'
1616 }
1717 }
1818} ) ;
Original file line number Diff line number Diff line change 11{
2- "mongo" : { "url" : " mongodb://localhost:27017/test" }
2+ "mongo" : { "url" : " mongodb://localhost:27017/mooc-backend- test" }
33}
You can’t perform that action at this time.
0 commit comments