├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── .vscode └── settings.json ├── Dockerfile ├── README.md ├── api.http ├── docker-compose.yaml ├── nest-cli.json ├── package-lock.json ├── package.json ├── src ├── app.controller.spec.ts ├── app.controller.ts ├── app.module.ts ├── app.service.ts ├── database │ ├── database.service.spec.ts │ └── database.service.ts ├── mailing │ ├── mailing.module.ts │ └── send-mail-with-tweets.job.ts ├── main.ts ├── test │ ├── test.controller.spec.ts │ └── test.controller.ts └── tweets │ ├── dto │ ├── create-tweet.dto.ts │ └── update-tweet.dto.ts │ ├── entities │ └── tweet.entity.ts │ ├── tweets-count │ ├── tweets-count.service.spec.ts │ └── tweets-count.service.ts │ ├── tweets.controller.spec.ts │ ├── tweets.controller.ts │ ├── tweets.module.ts │ ├── tweets.service.spec.ts │ └── tweets.service.ts ├── test ├── app.e2e-spec.ts └── jest-e2e.json ├── tsconfig.build.json └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint/eslint-plugin'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/recommended', 10 | 'plugin:prettier/recommended', 11 | ], 12 | root: true, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | ignorePatterns: ['.eslintrc.js'], 18 | rules: { 19 | '@typescript-eslint/interface-name-prefix': 'off', 20 | '@typescript-eslint/explicit-function-return-type': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': 'off', 22 | '@typescript-eslint/no-explicit-any': 'off', 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | .history/ -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorCustomizations": { 3 | "activityBar.activeBackground": "#e65072", 4 | "activityBar.activeBorder": "#4bdf20", 5 | "activityBar.background": "#e65072", 6 | "activityBar.foreground": "#15202b", 7 | "activityBar.inactiveForeground": "#15202b99", 8 | "activityBarBadge.background": "#4bdf20", 9 | "activityBarBadge.foreground": "#15202b", 10 | "sash.hoverBorder": "#e65072", 11 | "statusBar.background": "#e65072", 12 | "statusBar.foreground": "#15202b", 13 | "statusBarItem.hoverBackground": "#e0234e", 14 | "statusBarItem.remoteBackground": "#e65072", 15 | "statusBarItem.remoteForeground": "#15202b", 16 | "tab.activeBorder": "#e65072", 17 | "titleBar.activeBackground": "#e65072", 18 | "titleBar.activeForeground": "#15202b", 19 | "titleBar.inactiveBackground": "#e6507299", 20 | "titleBar.inactiveForeground": "#15202b99" 21 | }, 22 | "peacock.remoteColor": "#e0234e" 23 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.15.4-alpine3.12 2 | 3 | RUN npm install -g @nestjs/cli@8.0.0 4 | 5 | USER node 6 | 7 | WORKDIR /home/node/app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Imersão Full Stack && Full Cycle](https://events-fullcycle.s3.amazonaws.com/events-fullcycle/static/site/img/grupo_4417.png) 2 | 3 | Participe gratuitamente: https://imersao.fullcycle.com.br/ 4 | 5 | ## Sobre o repositório 6 | Esse repositório contém o código-fonte ministrado na aula Intensivão com Nest.js: [https://www.youtube.com/watch?v=PHIMN85trgk](https://www.youtube.com/watch?v=PHIMN85trgk) 7 | 8 | ## Rodar a aplicação 9 | 10 | Execute os comandos: 11 | 12 | ```bash 13 | docker-compose up 14 | ``` 15 | 16 | Acesse no browser http://localhost:3000/tweets. Use o arquivo `api.http` para testar a API. 17 | -------------------------------------------------------------------------------- /api.http: -------------------------------------------------------------------------------- 1 | GET http://localhost:3000/tweets 2 | 3 | ### 4 | POST http://localhost:3000/tweets 5 | Content-Type: application/json 6 | 7 | { 8 | "text": "conteudo do tweet111111" 9 | } -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | app: 5 | build: . 6 | entrypoint: sh -c "npm install && npm run start:dev" 7 | ports: 8 | - 3000:3000 9 | volumes: 10 | - .:/home/node/app 11 | depends_on: 12 | - redis 13 | 14 | redis: 15 | image: redis:6.2.6-alpine3.14 16 | -------------------------------------------------------------------------------- /nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nestjs-schedule-queue", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/bull": "^0.4.2", 25 | "@nestjs/common": "^8.0.0", 26 | "@nestjs/core": "^8.0.0", 27 | "@nestjs/mapped-types": "*", 28 | "@nestjs/platform-express": "^8.0.0", 29 | "@nestjs/schedule": "^1.0.2", 30 | "@nestjs/sequelize": "^8.0.0", 31 | "bull": "^4.5.0", 32 | "cache-manager": "^3.6.0", 33 | "reflect-metadata": "^0.1.13", 34 | "rimraf": "^3.0.2", 35 | "rxjs": "^7.2.0", 36 | "sequelize": "^6.15.0", 37 | "sequelize-typescript": "^2.1.2", 38 | "sqlite3": "^5.0.2" 39 | }, 40 | "devDependencies": { 41 | "@nestjs/cli": "^8.0.0", 42 | "@nestjs/schematics": "^8.0.0", 43 | "@nestjs/testing": "^8.0.0", 44 | "@types/bull": "^3.15.7", 45 | "@types/cache-manager": "^3.4.2", 46 | "@types/express": "^4.17.13", 47 | "@types/jest": "27.0.2", 48 | "@types/node": "^16.0.0", 49 | "@types/sequelize": "^4.28.11", 50 | "@types/supertest": "^2.0.11", 51 | "@typescript-eslint/eslint-plugin": "^5.0.0", 52 | "@typescript-eslint/parser": "^5.0.0", 53 | "eslint": "^8.0.1", 54 | "eslint-config-prettier": "^8.3.0", 55 | "eslint-plugin-prettier": "^4.0.0", 56 | "jest": "^27.2.5", 57 | "prettier": "^2.3.2", 58 | "source-map-support": "^0.5.20", 59 | "supertest": "^6.1.3", 60 | "ts-jest": "^27.0.3", 61 | "ts-loader": "^9.2.3", 62 | "ts-node": "^10.0.0", 63 | "tsconfig-paths": "^3.10.1", 64 | "typescript": "^4.3.5" 65 | }, 66 | "jest": { 67 | "moduleFileExtensions": [ 68 | "js", 69 | "json", 70 | "ts" 71 | ], 72 | "rootDir": "src", 73 | "testRegex": ".*\\.spec\\.ts$", 74 | "transform": { 75 | "^.+\\.(t|j)s$": "ts-jest" 76 | }, 77 | "collectCoverageFrom": [ 78 | "**/*.(t|j)s" 79 | ], 80 | "coverageDirectory": "../coverage", 81 | "testEnvironment": "node" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller('prefixo') 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get('test') //GET 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | 13 | @Get('test1') //GET 14 | acao(): string { 15 | return 'FullCycle'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { TestController } from './test/test.controller'; 5 | import { DatabaseService } from './database/database.service'; 6 | import { TweetsModule } from './tweets/tweets.module'; 7 | import { SequelizeModule } from '@nestjs/sequelize'; 8 | import { join } from 'path'; 9 | import { ScheduleModule } from '@nestjs/schedule'; 10 | import { BullModule } from '@nestjs/bull'; 11 | import { MailingModule } from './mailing/mailing.module'; 12 | 13 | @Module({ 14 | imports: [ 15 | ScheduleModule.forRoot(), 16 | BullModule.forRoot({ 17 | redis: { 18 | host: 'redis', 19 | port: 6379, 20 | }, 21 | }), 22 | SequelizeModule.forRoot({ 23 | dialect: 'sqlite', 24 | host: join(__dirname, 'database.sqlite'), 25 | autoLoadModels: true, 26 | synchronize: true, 27 | }), 28 | TweetsModule, 29 | MailingModule, 30 | ], 31 | controllers: [AppController, TestController], 32 | providers: [AppService, DatabaseService], 33 | }) 34 | export class AppModule {} 35 | -------------------------------------------------------------------------------- /src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/database/database.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { DatabaseService } from './database.service'; 3 | 4 | describe('DatabaseService', () => { 5 | let service: DatabaseService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [DatabaseService], 10 | }).compile(); 11 | 12 | service = module.get(DatabaseService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/database/database.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class DatabaseService {} 5 | -------------------------------------------------------------------------------- /src/mailing/mailing.module.ts: -------------------------------------------------------------------------------- 1 | import { SendMailWithTweetsJob } from './send-mail-with-tweets.job'; 2 | import { Module } from '@nestjs/common'; 3 | 4 | @Module({ 5 | providers: [SendMailWithTweetsJob], 6 | }) 7 | export class MailingModule {} 8 | 9 | 10 | // tarefas que verificar novos tweets 11 | 12 | //fila de processamento 13 | 14 | /// 1 2 3 4 5 6 7 15 | 16 | // bulljs usando redis -------------------------------------------------------------------------------- /src/mailing/send-mail-with-tweets.job.ts: -------------------------------------------------------------------------------- 1 | import { Process, Processor } from '@nestjs/bull'; 2 | import { Controller, UseGuards } from '@nestjs/common'; 3 | import { Job } from 'bull'; 4 | 5 | @Processor('emails') 6 | export class SendMailWithTweetsJob { 7 | @Process() 8 | handle(job: Job) { 9 | console.log(JSON.stringify(job.data)); 10 | } 11 | } 12 | 13 | 14 | //API Rest 15 | //Cron Job 16 | //Queue 17 | 18 | //sequelize 19 | 20 | //processos de agendamento 21 | 22 | //aplicação WEB | worker do agendamento - standalone 23 | 24 | //websocket -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | 10 | //javascript frontend | backend -------------------------------------------------------------------------------- /src/test/test.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TestController } from './test.controller'; 3 | 4 | describe('TestController', () => { 5 | let controller: TestController; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | controllers: [TestController], 10 | }).compile(); 11 | 12 | controller = module.get(TestController); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(controller).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/test/test.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller } from '@nestjs/common'; 2 | 3 | @Controller('test') 4 | export class TestController {} 5 | -------------------------------------------------------------------------------- /src/tweets/dto/create-tweet.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateTweetDto { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /src/tweets/dto/update-tweet.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateTweetDto } from './create-tweet.dto'; 3 | 4 | export class UpdateTweetDto extends PartialType(CreateTweetDto) {} 5 | -------------------------------------------------------------------------------- /src/tweets/entities/tweet.entity.ts: -------------------------------------------------------------------------------- 1 | import { Table, Column, Model } from 'sequelize-typescript'; 2 | 3 | @Table({ 4 | tableName: 'tweets', 5 | }) 6 | export class Tweet extends Model { 7 | @Column 8 | text: string; 9 | } 10 | 11 | //sqlite 12 | //biblioteca persistencia 13 | -------------------------------------------------------------------------------- /src/tweets/tweets-count/tweets-count.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TweetsCountService } from './tweets-count.service'; 3 | 4 | describe('TweetsCountService', () => { 5 | let service: TweetsCountService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [TweetsCountService], 10 | }).compile(); 11 | 12 | service = module.get(TweetsCountService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/tweets/tweets-count/tweets-count.service.ts: -------------------------------------------------------------------------------- 1 | import { InjectModel } from '@nestjs/sequelize'; 2 | import { Tweet } from './../entities/tweet.entity'; 3 | import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common'; 4 | import { Interval } from '@nestjs/schedule'; 5 | import { Cache } from 'cache-manager'; 6 | import { Queue } from 'bull'; 7 | import { InjectQueue } from '@nestjs/bull'; 8 | 9 | @Injectable() 10 | export class TweetsCountService { 11 | private limit = 10; 12 | constructor( 13 | @InjectModel(Tweet) 14 | private tweetModel: typeof Tweet, 15 | @Inject(CACHE_MANAGER) 16 | private cacheManager: Cache, 17 | @InjectQueue('emails') 18 | private emailsQueue: Queue, 19 | ) {} 20 | 21 | @Interval(5000) 22 | async countTweets() { 23 | console.log('procurando tweets'); 24 | let offset = await this.cacheManager.get('tweet-offset'); 25 | offset = offset === undefined ? 0 : offset; 26 | 27 | console.log(`offsets: ${offset}`); 28 | 29 | const tweets = await this.tweetModel.findAll({ 30 | offset, 31 | limit: this.limit, 32 | }); 33 | 34 | console.log(`${tweets.length} encontrados`); 35 | 36 | if (tweets.length === this.limit) { 37 | this.cacheManager.set('tweet-offset', offset + this.limit, { 38 | ttl: 1 * 60 * 10, 39 | }); 40 | console.log(`achou + ${this.limit} tweets`); 41 | this.emailsQueue.add({ tweets: tweets.map((t) => t.toJSON()) }); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/tweets/tweets.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TweetsController } from './tweets.controller'; 3 | import { TweetsService } from './tweets.service'; 4 | 5 | describe('TweetsController', () => { 6 | let controller: TweetsController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [TweetsController], 11 | providers: [TweetsService], 12 | }).compile(); 13 | 14 | controller = module.get(TweetsController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/tweets/tweets.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Controller, 3 | Get, 4 | Post, 5 | Body, 6 | Patch, 7 | Param, 8 | Delete, 9 | } from '@nestjs/common'; 10 | import { TweetsService } from './tweets.service'; 11 | import { CreateTweetDto } from './dto/create-tweet.dto'; 12 | import { UpdateTweetDto } from './dto/update-tweet.dto'; 13 | 14 | @Controller('tweets') 15 | export class TweetsController { 16 | constructor(private readonly tweetsService: TweetsService) {} 17 | 18 | @Post() 19 | create(@Body() createTweetDto: CreateTweetDto) { 20 | return this.tweetsService.create(createTweetDto); 21 | } 22 | 23 | @Get() 24 | findAll() { 25 | return this.tweetsService.findAll(); 26 | } 27 | 28 | @Get(':id') 29 | findOne(@Param('id') id: string) { 30 | return this.tweetsService.findOne(+id); 31 | } 32 | 33 | @Patch(':id') //PUT vs PATCH 34 | update(@Param('id') id: string, @Body() updateTweetDto: UpdateTweetDto) { 35 | return this.tweetsService.update(+id, updateTweetDto); 36 | } 37 | 38 | @Delete(':id') 39 | remove(@Param('id') id: string) { 40 | return this.tweetsService.remove(+id); 41 | } 42 | } 43 | 44 | //Express vs Nest.js 45 | 46 | //Nest.js - base Express 47 | 48 | // Loopback 49 | 50 | // JEST 51 | 52 | //Middlewares vs Interceptors -------------------------------------------------------------------------------- /src/tweets/tweets.module.ts: -------------------------------------------------------------------------------- 1 | import { BullModule } from '@nestjs/bull'; 2 | import { Tweet } from './entities/tweet.entity'; 3 | import { SequelizeModule } from '@nestjs/sequelize'; 4 | import { CacheModule, Module } from '@nestjs/common'; 5 | import { TweetsService } from './tweets.service'; 6 | import { TweetsController } from './tweets.controller'; 7 | import { TweetsCountService } from './tweets-count/tweets-count.service'; 8 | 9 | @Module({ 10 | imports: [ 11 | CacheModule.register(), 12 | SequelizeModule.forFeature([Tweet]), 13 | BullModule.registerQueue({ name: 'emails' }), 14 | ], 15 | controllers: [TweetsController], 16 | providers: [TweetsService, TweetsCountService], 17 | }) 18 | export class TweetsModule {} 19 | -------------------------------------------------------------------------------- /src/tweets/tweets.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TweetsService } from './tweets.service'; 3 | 4 | describe('TweetsService', () => { 5 | let service: TweetsService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [TweetsService], 10 | }).compile(); 11 | 12 | service = module.get(TweetsService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/tweets/tweets.service.ts: -------------------------------------------------------------------------------- 1 | import { Tweet } from './entities/tweet.entity'; 2 | import { Injectable } from '@nestjs/common'; 3 | import { CreateTweetDto } from './dto/create-tweet.dto'; 4 | import { UpdateTweetDto } from './dto/update-tweet.dto'; 5 | import { InjectModel } from '@nestjs/sequelize'; 6 | 7 | @Injectable() 8 | export class TweetsService { 9 | constructor( 10 | @InjectModel(Tweet) 11 | private tweetModel: typeof Tweet, 12 | ) {} 13 | 14 | create(createTweetDto: CreateTweetDto) { 15 | return this.tweetModel.create(createTweetDto as any); 16 | } 17 | 18 | findAll() { 19 | return this.tweetModel.findAll(); 20 | } 21 | 22 | findOne(id: number) { 23 | return `This action returns a #${id} tweet`; 24 | } 25 | 26 | update(id: number, updateTweetDto: UpdateTweetDto) { 27 | return `This action updates a #${id} tweet`; 28 | } 29 | 30 | remove(id: number) { 31 | return `This action removes a #${id} tweet`; 32 | } 33 | } 34 | 35 | 36 | //singleton - shared 37 | 38 | //reactive x - gerenciar eventos 39 | 40 | //Promise -------------------------------------------------------------------------------- /test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | }, 21 | "include": [ 22 | "src/" 23 | ] 24 | } 25 | --------------------------------------------------------------------------------