From 5e5ef00d48e4c59296e96bbdc8e9d89933c2b5a9 Mon Sep 17 00:00:00 2001 From: Ivan Alglave <ivanalglave@outlook.fr> Date: Tue, 8 Nov 2022 14:17:48 +0100 Subject: [PATCH] added mongodb with docker image and integration in nest server --- docker/docker-compose.yml | 7 +++++++ package.json | 2 ++ src/app.controller.spec.ts | 22 ---------------------- src/app.controller.ts | 12 ------------ src/app.module.ts | 10 +++++----- src/app.service.ts | 8 -------- src/config/config.model.ts | 5 +++++ src/config/config.template.json | 5 ++++- src/config/index.ts | 1 + 9 files changed, 24 insertions(+), 48 deletions(-) create mode 100644 docker/docker-compose.yml delete mode 100644 src/app.controller.spec.ts delete mode 100644 src/app.controller.ts delete mode 100644 src/app.service.ts diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..7c91d0d --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,7 @@ +services: + mongo: + image: mongo + container_name: mongo + ports: + - 27017:27017 + restart: always diff --git a/package.json b/package.json index ef426af..4ba4e23 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "dependencies": { "@nestjs/common": "^9.0.0", "@nestjs/core": "^9.0.0", + "@nestjs/mongoose": "^9.2.1", "@nestjs/platform-express": "^9.0.0", + "mongoose": "^6.7.2", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0" diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts deleted file mode 100644 index d22f389..0000000 --- a/src/app.controller.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; - -describe('AppController', () => { - let appController: AppController; - - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); - - appController = app.get<AppController>(AppController); - }); - - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); -}); diff --git a/src/app.controller.ts b/src/app.controller.ts deleted file mode 100644 index cce879e..0000000 --- a/src/app.controller.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; -import { AppService } from './app.service'; - -@Controller() -export class AppController { - constructor(private readonly appService: AppService) {} - - @Get() - getHello(): string { - return this.appService.getHello(); - } -} diff --git a/src/app.module.ts b/src/app.module.ts index 8662803..92af588 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,10 +1,10 @@ import { Module } from '@nestjs/common'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { MongooseModule } from '@nestjs/mongoose'; +import { mongodb } from './config'; @Module({ - imports: [], - controllers: [AppController], - providers: [AppService], + imports: [MongooseModule.forRoot(mongodb.uri)], + controllers: [], + providers: [], }) export class AppModule {} diff --git a/src/app.service.ts b/src/app.service.ts deleted file mode 100644 index 927d7cc..0000000 --- a/src/app.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class AppService { - getHello(): string { - return 'Hello World!'; - } -} diff --git a/src/config/config.model.ts b/src/config/config.model.ts index 18c0cae..79984c4 100644 --- a/src/config/config.model.ts +++ b/src/config/config.model.ts @@ -2,6 +2,11 @@ export interface IServerConfig { port: number; } +export interface IMongodbConfig { + uri: string; +} + export interface IConfig { server: IServerConfig; + mongodb: IMongodbConfig; } diff --git a/src/config/config.template.json b/src/config/config.template.json index 88fb611..ee6bb83 100644 --- a/src/config/config.template.json +++ b/src/config/config.template.json @@ -1,5 +1,8 @@ { "server": { - "port": 0 + "port": 3001 + }, + "mongodb": { + "uri": "mongodb://localhost:27017/internship-manager" } } diff --git a/src/config/index.ts b/src/config/index.ts index 3e77fb1..3bf48c8 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -4,4 +4,5 @@ import { IConfig } from './config.model'; const config = _config as IConfig; export const server = config.server; +export const mongodb = config.mongodb; export default config; -- GitLab