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 1
1
import express , { Application } from 'express' ;
2
2
import cors from 'cors' ;
3
+ import { startCollections } from './init.collections' ;
4
+ import { topicDALFactory } from '../dal/topics.dal' ;
5
+ import { mapTopic , mapTopics , topicsServiceFactory } from '../services' ;
3
6
import { routesInitialization } from '../routes' ;
7
+
4
8
5
- export const createApp = ( ) => {
9
+ export const createApp = async ( ) => {
6
10
const app : Application = express ( ) ;
7
11
8
- // TODO: Set up cors.
9
12
app . use ( cors ( ) ) ;
10
13
app . use ( express . json ( ) ) ;
11
14
app . use ( express . urlencoded ( { extended : true } ) ) ;
12
15
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 ) ;
15
21
16
22
return app ;
17
23
} ;
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';
4
4
5
5
const { app : { host, port } } = config ;
6
6
7
- export const initExpressApp = ( ) => {
8
- const app : Application = createApp ( ) ;
7
+ export const initExpressApp = async ( ) => {
8
+ const app : Application = await createApp ( ) ;
9
9
10
10
app . listen (
11
11
port ,
Original file line number Diff line number Diff line change 1
1
import { Application } from 'express' ;
2
+ import { TopicsService } from '../services' ;
2
3
import { topicsRoutes } from './topics.route' ;
3
4
4
- export const routesInitialization = ( app : Application ) => {
5
+ export const routesInitialization = ( app : Application , topicsService : TopicsService ) => {
5
6
// TODO: Inject DAL
6
- app . use ( '/api/topics' , topicsRoutes ( null ) ) ;
7
+ app . use ( '/api/topics' , topicsRoutes ( topicsService ) ) ;
7
8
} ;
You can’t perform that action at this time.
0 commit comments