Skip to content

Commit

Permalink
add database
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed May 22, 2024
1 parent 22045aa commit 3b38e95
Show file tree
Hide file tree
Showing 13 changed files with 4,348 additions and 5,250 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ To run the apps using the `docker-compose` file, you can use the following comma
- `docker-compose up --build`: Rebuilds the images and starts the containers.
- `docker-compose up -d api --build`: Starts only the API application in detached mode and rebuilds the image.
- `docker-compose up -d client --build`: Starts only the client application in detached mode and rebuilds the image.
- `docker-compose up -d postgres`: Starts only the database in detached mode and rebuilds the image.

## TODO

Expand Down
24 changes: 19 additions & 5 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from '@api/app.service';
import { UsersModule } from '@api/modules/users/users.module';
import { CountriesModule } from '@api/modules/countries/countries.module';
import { User } from '@shared/dto/users/user.entity';

// TODO: The dist folder structure changes if some shared lib is imported in the api. Check this

const user: User = new User();
import { Country } from '@shared/dto/countries/country.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as config from '@shared/config/development.json';

@Module({
imports: [UsersModule],
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: config.db.username,
password: config.db.password,
database: config.db.database,
entities: [User, Country],
synchronize: true,
}),

UsersModule,
CountriesModule,
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
9 changes: 9 additions & 0 deletions api/src/modules/countries/countries.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';

@Controller()
export class CountriesController {
@Get('countries')
createCountry() {
return 'This action adds a new country';
}
}
9 changes: 9 additions & 0 deletions api/src/modules/countries/countries.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { CountriesController } from '@api/modules/countries/countries.controller';
import { CountriesService } from '@api/modules/countries/countries.service';

@Module({
controllers: [CountriesController],
providers: [CountriesService],
})
export class CountriesModule {}
4 changes: 4 additions & 0 deletions api/src/modules/countries/countries.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class CountriesService {}
3 changes: 2 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ services:
networks:
- 4-growth-docker-network

postgres:
image: postgres:13
environment:
POSTGRES_USER: 4growth
POSTGRES_PASSWORD: 4growth
POSTGRES_DB: 4growth
ports:
- "5432:5432"
networks:
- 4-growth-docker-network


networks:
4-growth-docker-network:
Expand Down
Loading

0 comments on commit 3b38e95

Please sign in to comment.