forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc1aae0
commit d6dbe61
Showing
27 changed files
with
527 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require('ts-node/register'); | ||
require('./src/server'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
examples/07-sequelize/src/modules/database/database.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
examples/07-sequelize/src/modules/database/database.providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require('ts-node/register'); | ||
require('./src/server'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Oops, something went wrong.