Skip to content

Commit

Permalink
docs(@nestjs) update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 30, 2017
1 parent cc1aae0 commit d6dbe61
Show file tree
Hide file tree
Showing 27 changed files with 527 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/06-mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@nestjs/microservices": "^4.0.1",
"@nestjs/testing": "^4.0.1",
"@nestjs/websockets": "^4.0.1",
"@types/mongoose": "^4.7.23",
"body-parser": "^1.17.2",
"mongoose": "^4.11.13",
"redis": "^2.7.1",
Expand All @@ -23,6 +22,7 @@
"typescript": "^2.4.2"
},
"devDependencies": {
"@types/mongoose": "^4.7.23",
"@types/node": "^7.0.41",
"ts-node": "^3.3.0"
}
Expand Down
21 changes: 21 additions & 0 deletions examples/07-sequelize/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# dependencies
/node_modules

# IDE
/.idea
/.awcache
/.vscode

# misc
npm-debug.log

# example
/quick-start

# tests
/test
/coverage
/.nyc_output

# dist
/dist
14 changes: 14 additions & 0 deletions examples/07-sequelize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('ts-node/register');
require('./src/server');












31 changes: 31 additions & 0 deletions examples/07-sequelize/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "nest-typescript-starter",
"version": "1.0.0",
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
},
"dependencies": {
"@nestjs/common": "^4.0.1",
"@nestjs/core": "^4.0.1",
"@nestjs/microservices": "^4.0.1",
"@nestjs/testing": "^4.0.1",
"@nestjs/websockets": "^4.0.1",
"body-parser": "^1.17.2",
"mysql2": "^1.4.2",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.4.3",
"sequelize": "^4.12.0",
"sequelize-typescript": "^0.5.0",
"typescript": "^2.4.2"
},
"devDependencies": {
"@types/node": "^7.0.41",
"@types/sequelize": "^4.0.75",
"ts-node": "^3.3.0"
}
}
7 changes: 7 additions & 0 deletions examples/07-sequelize/src/modules/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { CatsModule } from './cats/cats.module';

@Module({
modules: [CatsModule],
})
export class ApplicationModule {}
13 changes: 13 additions & 0 deletions examples/07-sequelize/src/modules/cats/cat.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Table, Column, Model } from 'sequelize-typescript';

@Table
export class Cat extends Model<Cat> {
@Column
name: string;

@Column
age: number;

@Column
breed: string;
}
19 changes: 19 additions & 0 deletions examples/07-sequelize/src/modules/cats/cats.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { CreateCatDto } from './dto/create-cat.dto';
import { CatsService } from './cats.service';
import { Cat } from './cat.entity';

@Controller('cats')
export class CatsController {
constructor(private readonly catsService: CatsService) {}

@Post()
async create(@Body() createCatDto: CreateCatDto) {
this.catsService.create(createCatDto);
}

@Get()
async findAll(): Promise<Cat[]> {
return this.catsService.findAll();
}
}
15 changes: 15 additions & 0 deletions examples/07-sequelize/src/modules/cats/cats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';
import { catsProviders } from './cats.providers';
import { DatabaseModule } from '../database/database.module';

@Module({
modules: [DatabaseModule],
controllers: [CatsController],
components: [
CatsService,
...catsProviders,
],
})
export class CatsModule {}
8 changes: 8 additions & 0 deletions examples/07-sequelize/src/modules/cats/cats.providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Cat } from './cat.entity';

export const catsProviders = [
{
provide: 'CatsRepository',
useValue: Cat,
},
];
25 changes: 25 additions & 0 deletions examples/07-sequelize/src/modules/cats/cats.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { Component, Inject } from '@nestjs/common';
import { CatsModule } from './cats.module';
import { CreateCatDto } from './dto/create-cat.dto';
import { Model } from 'sequelize-typescript';
import { Cat } from './cat.entity';

@Component()
export class CatsService {
constructor(
@Inject('CatsRepository') private readonly catsRepository: typeof Model) {}

async create(createCatDto: CreateCatDto): Promise<Cat> {
const cat = new Cat();
cat.name = createCatDto.name;
cat.breed = createCatDto.breed;
cat.age = createCatDto.age;

return await cat.save();
}

async findAll(): Promise<Cat[]> {
return await this.catsRepository.findAll<Cat>();
}
}
5 changes: 5 additions & 0 deletions examples/07-sequelize/src/modules/cats/dto/create-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class CreateCatDto {
readonly name: string;
readonly age: number;
readonly breed: string;
}
8 changes: 8 additions & 0 deletions examples/07-sequelize/src/modules/database/database.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { databaseProviders } from './database.providers';

@Module({
components: [...databaseProviders],
exports: [...databaseProviders],
})
export class DatabaseModule {}
21 changes: 21 additions & 0 deletions examples/07-sequelize/src/modules/database/database.providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Sequelize } from 'sequelize-typescript';
import { Cat } from '../cats/cat.entity';

export const databaseProviders = [
{
provide: 'SequelizeToken',
useFactory: async () => {
const sequelize = new Sequelize({
dialect: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: '',
database: 'test',
});
sequelize.addModels([Cat]);
await sequelize.sync();
return sequelize;
},
},
];
10 changes: 10 additions & 0 deletions examples/07-sequelize/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as bodyParser from 'body-parser';
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
app.use(bodyParser.json());
await app.listen(3001);
}
bootstrap();
22 changes: 22 additions & 0 deletions examples/07-sequelize/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"allowJs": true,
"outDir": "./dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
53 changes: 53 additions & 0 deletions examples/07-sequelize/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"eofline": false,
"quotemark": [
true,
"single"
],
"ordered-imports": [
false
],
"max-line-length": [
150
],
"member-ordering": [
false
],
"curly": false,
"interface-name": [
false
],
"array-type": [
false
],
"member-access": [
false
],
"no-empty-interface": false,
"no-empty": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
"max-classes-per-file": [
false
],
"variable-name": [
false
],
"one-line": [
false
],
"one-variable-per-declaration": [
false
]
},
"rulesDirectory": []
}
21 changes: 21 additions & 0 deletions examples/08-passport/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# dependencies
/node_modules

# IDE
/.idea
/.awcache
/.vscode

# misc
npm-debug.log

# example
/quick-start

# tests
/test
/coverage
/.nyc_output

# dist
/dist
14 changes: 14 additions & 0 deletions examples/08-passport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('ts-node/register');
require('./src/server');












31 changes: 31 additions & 0 deletions examples/08-passport/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "nest-typescript-starter",
"version": "1.0.0",
"description": "Nest TypeScript starter repository",
"license": "MIT",
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
},
"dependencies": {
"@nestjs/common": "^4.0.1",
"@nestjs/core": "^4.0.1",
"@nestjs/microservices": "^4.0.1",
"@nestjs/testing": "^4.0.1",
"@nestjs/websockets": "^4.0.1",
"@types/passport-jwt": "^2.0.24",
"body-parser": "^1.17.2",
"jsonwebtoken": "^8.0.1",
"passport": "^0.4.0",
"passport-jwt": "^3.0.0",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.4.3",
"typescript": "^2.4.2"
},
"devDependencies": {
"@types/node": "^7.0.41",
"ts-node": "^3.3.0"
}
}
7 changes: 7 additions & 0 deletions examples/08-passport/src/modules/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { AuthModule } from './auth/auth.module';

@Module({
modules: [AuthModule],
})
export class ApplicationModule {}
Loading

0 comments on commit d6dbe61

Please sign in to comment.