File tree Expand file tree Collapse file tree 4 files changed +25
-8
lines changed
01-contenedores/lemoncode-challenge/node-stack/backend/src Expand file tree Collapse file tree 4 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 11import express , { Application } from 'express' ;
22import cors from 'cors' ;
3+ import { startCollections } from './init.collections' ;
4+ import { topicDALFactory } from '../dal/topics.dal' ;
5+ import { mapTopic , mapTopics , topicsServiceFactory } from '../services' ;
36import { routesInitialization } from '../routes' ;
7+
48
5- export const createApp = ( ) => {
9+ export const createApp = async ( ) => {
610 const app : Application = express ( ) ;
711
8- // TODO: Set up cors.
912 app . use ( cors ( ) ) ;
1013 app . use ( express . json ( ) ) ;
1114 app . use ( express . urlencoded ( { extended : true } ) ) ;
1215
13- // TODO: Inject DAL
14- routesInitialization ( app ) ;
16+ const [ topicsCollection ] = await startCollections ( ) ;
17+ const topicsDAL = topicDALFactory ( topicsCollection ) ;
18+ const topicsService = topicsServiceFactory ( topicsDAL , mapTopic , mapTopics ) ;
19+
20+ routesInitialization ( app , topicsService ) ;
1521
1622 return app ;
1723} ;
Original file line number Diff line number Diff line change 1+ import config from '../config' ;
2+ import { Collection } from 'mongodb' ;
3+ import { connect , getDatabaseInstance , getCollection } from '../dal/mongo-client.manager' ;
4+
5+ export const startCollections = async ( ) : Promise < Collection [ ] > => {
6+ await connect ( ) ;
7+ const db = getDatabaseInstance ( config . database . name ) ;
8+ const topicsCollection = getCollection ( db , 'Topics' ) ;
9+ return [ topicsCollection ] ;
10+ }
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { createApp } from './create-app';
44
55const { app : { host, port } } = config ;
66
7- export const initExpressApp = ( ) => {
8- const app : Application = createApp ( ) ;
7+ export const initExpressApp = async ( ) => {
8+ const app : Application = await createApp ( ) ;
99
1010 app . listen (
1111 port ,
Original file line number Diff line number Diff line change 11import { Application } from 'express' ;
2+ import { TopicsService } from '../services' ;
23import { topicsRoutes } from './topics.route' ;
34
4- export const routesInitialization = ( app : Application ) => {
5+ export const routesInitialization = ( app : Application , topicsService : TopicsService ) => {
56 // TODO: Inject DAL
6- app . use ( '/api/topics' , topicsRoutes ( null ) ) ;
7+ app . use ( '/api/topics' , topicsRoutes ( topicsService ) ) ;
78} ;
You can’t perform that action at this time.
0 commit comments