Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

02 mongodb #1

Open
wants to merge 2 commits into
base: 01-introduction
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 175 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"dependencies": {
"@nestjs/common": "^6.0.0",
"@nestjs/core": "^6.0.0",
"@nestjs/mongoose": "^6.1.2",
"@nestjs/platform-express": "^6.0.0",
"mongoose": "^5.6.1",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3"
Expand All @@ -31,6 +33,7 @@
"@nestjs/testing": "^6.0.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.13",
"@types/mongoose": "^5.5.6",
"@types/node": "^10.12.18",
"@types/supertest": "^2.0.7",
"concurrently": "^4.1.0",
Expand Down
8 changes: 7 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ProductsModule } from './products/products.module';

@Module({
imports: [ProductsModule],
imports: [
ProductsModule,
MongooseModule.forRoot(
'mongodb+srv://maximilian:[email protected]/nestjs-demo?retryWrites=true&w=majority',
),
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
20 changes: 13 additions & 7 deletions src/products/product.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export class Product {
constructor(
public id: string,
public title: string,
public description: string,
public price: number,
) {}
import * as mongoose from 'mongoose';

export const ProductSchema = new mongoose.Schema({
title: { type: String, required: true },
description: { type: String, required: true },
price: { type: Number, required: true },
});

export interface Product extends mongoose.Document {
id: string;
title: string;
description: string;
price: number;
}
Loading