Skip to content

Commit

Permalink
Update test providers and fix multiple connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ecaminero committed Jul 7, 2019
1 parent 30b6b5e commit 7b23f59
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 79 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

# Env
.env
108 changes: 98 additions & 10 deletions doc/request.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,104 @@
POST http://{{host}} HTTP/1.1
Content-Type: {{contentType}}

{
"name": "Waldo Daniel",
"lastname": "Schmeler",
"age": 19436,
"picture": "http://lorempixel.com/640/480",
"company": "Borer - Jakubowski",
"email": "[email protected]",
"phone": "1-961-579-6644",
"balance": "795.61"
{
"name" : "Mertie Beier Sr.",
"lastname" : "Ziemann",
"age" : 90402,
"picture" : "http://lorempixel.com/640/480",
"company" : "Schaefer LLC",
"email" : "[email protected]",
"phone" : "1-666-252-6434 x715",
"balance" : "934.61",
"jobTitle" : "Direct Infrastructure Assistant",
"avatar" : "https://s3.amazonaws.com/uifaces/faces/twitter/coderdiaz/128.jpg",
"ipv6" : "4e82:20d3:2695:6a75:a5a4:0ad9:bc26:2e35",
"id" : "cb9d7866-a355-4c6c-9a69-4d8a7d97620b",
"finance" : {
"account" : "23856570",
"accountName" : "Money Market Account"
},
"address" : {
"zipCode" : "35626",
"city" : "West Elnora",
"streetAddress" : "968 Emmerich Points",
"country" : "Czech Republic"
},
"shopping" : [
{
"productName" : "Intelligent Frozen Chips",
"price" : "664.00",
"productAdjective" : "Tasty",
"productMaterial" : "Steel",
"product" : "Sausages",
"department" : "Beauty"
},
{
"productName" : "Unbranded Cotton Keyboard",
"price" : "401.00",
"productAdjective" : "Rustic",
"productMaterial" : "Soft",
"product" : "Bacon",
"department" : "Electronics"
},
{
"productName" : "Licensed Concrete Computer",
"price" : "772.00",
"productAdjective" : "Sleek",
"productMaterial" : "Cotton",
"product" : "Computer",
"department" : "Beauty"
},
{
"productName" : "Fantastic Frozen Cheese",
"price" : "789.00",
"productAdjective" : "Handcrafted",
"productMaterial" : "Plastic",
"product" : "Fish",
"department" : "Beauty"
},
{
"productName" : "Tasty Frozen Shoes",
"price" : "422.00",
"productAdjective" : "Awesome",
"productMaterial" : "Frozen",
"product" : "Chicken",
"department" : "Baby"
},
{
"productName" : "Gorgeous Plastic Mouse",
"price" : "317.00",
"productAdjective" : "Sleek",
"productMaterial" : "Wooden",
"product" : "Salad",
"department" : "Computers"
},
{
"productName" : "Practical Cotton Fish",
"price" : "174.00",
"productAdjective" : "Practical",
"productMaterial" : "Fresh",
"product" : "Bike",
"department" : "Books"
},
{
"productName" : "Refined Plastic Hat",
"price" : "170.00",
"productAdjective" : "Sleek",
"productMaterial" : "Soft",
"product" : "Chips",
"department" : "Music"
},
{
"productName" : "Tasty Soft Pizza",
"price" : "223.00",
"productAdjective" : "Incredible",
"productMaterial" : "Cotton",
"product" : "Mouse",
"department" : "Movies"
}
],
"__v" : 0
}

### Get all services
GET http://localhost:4000/all HTTP/1.1
19 changes: 19 additions & 0 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 @@ -25,14 +25,17 @@
"@nestjs/mongoose": "^6.1.2",
"@nestjs/platform-express": "^6.0.0",
"@types/faker": "^4.1.5",
"dotenv": "^8.0.0",
"faker": "^4.1.0",
"moment": "^2.24.0",
"mongoose": "^5.6.3",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@nestjs/testing": "^6.0.0",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.13",
"@types/node": "^10.12.18",
Expand Down
3 changes: 0 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { MongooseModule } from '@nestjs/mongoose';
import { MONGO_DB_SERVER } from './config';

@Module({
imports: [
MongooseModule.forRoot(MONGO_DB_SERVER, {useNewUrlParser: true}),
UserModule,
],
})
Expand Down
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as dotenv from 'dotenv';
dotenv.config();

export const SERVICE = 'DB_MONGO_SERVICE';
export const APP_NAME = process.env.APP_NAME || 'mongo.database.service';
export const DATABASE_SERVICE = process.env.DATABASE_SERVICE || 'DATABASE_SERVICE';
export const MONGO_DB_SERVER = process.env.MONGO_DB_SERVER || 'mongodb://localhost/walmartpci';
export const APP_PORT = process.env.PORT || 4000;
export const DB_SERVER = process.env.DB_SERVER || 'mongodb://localhost/testing';
export const APP_PORT = process.env.PORT || 4000;
4 changes: 2 additions & 2 deletions src/database/database.providers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as mongoose from 'mongoose';
import { MONGO_DB_SERVER } from './../config';
import { DB_SERVER } from './../config';

export const databaseProviders = [{
provide: 'DATABASE_CONNECTION',
useFactory: async (): Promise<typeof mongoose> =>
await mongoose.connect(MONGO_DB_SERVER, { useNewUrlParser: true }),
await mongoose.connect(DB_SERVER, { useNewUrlParser: true }),
}];
22 changes: 22 additions & 0 deletions src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,26 @@ export interface CreateUserDto {
readonly email: string;
readonly phone: string;
readonly balance: string;
readonly jobTitle: string;
readonly avatar: string;
readonly ipv6: string;
readonly id: string;
readonly finance: {
readonly account: string;
readonly accountName: string;
};
readonly address: {
readonly zipCode: string;
readonly city: string;
readonly streetAddress: string;
readonly country: string;
};
readonly shopping: [{
readonly productName: string;
readonly price: string;
readonly productAdjective: string;
readonly productMaterial: string;
readonly product: string;
readonly department: string;
}];
}
25 changes: 23 additions & 2 deletions src/user/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { Document } from 'mongoose';

export interface User extends Document {
Expand All @@ -10,4 +9,26 @@ export interface User extends Document {
readonly email: string;
readonly phone: string;
readonly balance: string;
}
readonly jobTitle: string;
readonly avatar: string;
readonly ipv6: string;
readonly id: string;
readonly finance: {
readonly account: string;
readonly accountName: string;
};
readonly address: {
readonly zipCode: string;
readonly city: string;
readonly streetAddress: string;
readonly country: string;
};
readonly shopping: [{
readonly productName: string;
readonly price: string;
readonly productAdjective: string;
readonly productMaterial: string;
readonly product: string;
readonly department: string;
}];
}
23 changes: 23 additions & 0 deletions src/user/schemas/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,27 @@ export const UserSchema = new mongoose.Schema({
email: String,
phone: String,
balance: String,
jobTitle: String,
phoneNumber: String,
avatar: String,
ipv6: String,
id: String,
finance: {
account: String,
accountName: String,
},
address: {
zipCode: String,
city: String,
streetAddress: String,
country: String,
},
shopping: [{
productName: String,
price: String,
productAdjective: String,
productMaterial: String,
product: String,
department: String,
}],
});
28 changes: 0 additions & 28 deletions src/user/user.controller.spec.ts

This file was deleted.

10 changes: 4 additions & 6 deletions src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { MongooseModule } from '@nestjs/mongoose';
import { UserSchema } from './schemas/user.schema';
const schemas = [
{ name: 'User', schema: UserSchema },
];
import { DatabaseModule } from '../database/database.module';
import { userProviders } from './user.provider';

@Module({
imports: [MongooseModule.forFeature(schemas)],
imports: [DatabaseModule],
controllers: [UserController],
providers: [
UserService,
...userProviders,
],
})
export class UserModule {}
10 changes: 10 additions & 0 deletions src/user/user.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Connection } from 'mongoose';
import { UserSchema } from './schemas/user.schema';

export const userProviders = [
{
provide: 'USER_MODEL',
useFactory: (connection: Connection) => connection.model('User', UserSchema),
inject: ['DATABASE_CONNECTION'],
},
];
5 changes: 2 additions & 3 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Inject } from '@nestjs/common';
import { Model } from 'mongoose';
import { User } from './interfaces/user.interface';
import { CreateUserDto } from './dto/create-user.dto';
import { InjectModel } from '@nestjs/mongoose';

@Injectable()
export class UserService {
constructor(@InjectModel('User') private readonly userModel: Model<User>) {}
constructor(@Inject('USER_MODEL') private readonly userModel: Model<User>) {}

getHello(): string {
return 'Hello World!';
Expand Down
Loading

0 comments on commit 7b23f59

Please sign in to comment.