├── .env.example ├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── README.md ├── docker-compose.yml ├── nest-cli.json ├── package-lock.json ├── package.json ├── src ├── app.controller.ts ├── app.module.ts ├── app.service.ts ├── main.ts └── modules │ ├── bases │ ├── dto │ │ └── base.dto.ts │ └── entities │ │ └── base.entity.ts │ ├── contents │ ├── contents.module.ts │ ├── dto │ │ ├── content.dto.ts │ │ ├── create-content.input.ts │ │ └── update-content.input.ts │ └── entities │ │ └── content.entity.ts │ ├── disciplines │ ├── disciplines.module.ts │ ├── dto │ │ ├── create-discipline.input.ts │ │ ├── discipline.dto.ts │ │ └── update-discipline.input.ts │ └── entities │ │ └── discipline.entity.ts │ ├── lessons │ ├── dto │ │ ├── create-lesson.input.ts │ │ ├── lesson.dto.ts │ │ └── update-lesson.input.ts │ ├── entities │ │ └── lesson.entity.ts │ └── lessons.module.ts │ └── students │ ├── dto │ ├── create-student.input.ts │ ├── student.dto.ts │ └── update-student.input.ts │ ├── entities │ └── student.entity.ts │ └── students.module.ts ├── test ├── app.e2e-spec.ts └── jest-e2e.json ├── tsconfig.build.json ├── tsconfig.json └── yarn.lock /.env.example: -------------------------------------------------------------------------------- 1 | TYPEORM_CONNECTION = postgres 2 | TYPEORM_HOST = localhost 3 | TYPEORM_USERNAME = test 4 | TYPEORM_PASSWORD = test 5 | TYPEORM_DATABASE = test 6 | TYPEORM_PORT = 5432 7 | TYPEORM_SYNCHRONIZE = true 8 | TYPEORM_LOGGING = true 9 | TYPEORM_ENTITIES = **/entities/*.js,modules/**/entities/*.js -------------------------------------------------------------------------------- /.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 | # DOTENV 38 | .env 39 | /src/schema.gql -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 |

Projeto de estudos gerado a partir dos vídeos do Canal do Youtube.

6 |

7 | Stars 8 | 9 | 10 | GitHub last commit 11 | 12 | 13 | Repository issues 14 | 15 | 16 | Repository pulls 17 |

18 | 19 | 20 | ## 🔐 Pré requisitos 21 | 22 | Docker   23 | 24 | Docker-compose   25 | 26 | ## 📹 Aulas 27 | Aula 01 - Criando o projeto do zero e configurando as tecnologias   28 | 29 | Aula 02 - Primeiro módulo com filtro, ordenação e paginação   30 | 31 | Aula 03 - Criando os módulos de disciplinas, aulas e conteúdos   32 | 33 | Aula 04 - Criando os relacionamentos do TypeORM e do Nestjs-query   34 | 35 | ## Executando o projeto 36 | ### Ajustando o .env 37 | Renomeie ``.env.example`` para ``.env`` e configure como desejar. 38 | 39 | ### Executando a postgres 40 | 41 | ```bash 42 | $ docker-compose up 43 | ``` 44 | 45 | ### Instalando as dependências 46 | 47 | ```bash 48 | $ npm install 49 | ``` 50 | 51 | ### Executando a aplicação 52 | 53 | ```bash 54 | $ yarn start:dev 55 | ``` 56 | 57 | ## 🤝 Contribuídores 58 | 59 |   60 | 61 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | postgres: 4 | image: 'postgres:9.6.1' 5 | ports: 6 | - '5432:5432' 7 | environment: 8 | POSTGRES_USER: 'test' 9 | POSTGRES_PASSWORD: 'test' 10 | POSTGRES_DB: 'test' 11 | -------------------------------------------------------------------------------- /nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src/modules", 4 | "compilerOptions": { 5 | "plugins": [ 6 | { 7 | "name": "@nestjs/graphql", 8 | "options": { 9 | "typeFileNameSuffix": [".input.ts", ".dto.ts"], 10 | "introspectComments": true 11 | } 12 | } 13 | ] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "utube", 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-query/core": "^0.29.0", 25 | "@nestjs-query/query-graphql": "^0.29.0", 26 | "@nestjs-query/query-typeorm": "^0.29.0", 27 | "@nestjs/common": "^8.0.8", 28 | "@nestjs/core": "^8.0.8", 29 | "@nestjs/graphql": "^9.0.5", 30 | "@nestjs/platform-express": "^8.0.0", 31 | "@nestjs/typeorm": "^8.0.2", 32 | "apollo-server-express": "^3.3.0", 33 | "class-transformer": "^0.4.0", 34 | "class-validator": "^0.13.1", 35 | "dataloader": "^2.0.0", 36 | "dotenv": "^10.0.0", 37 | "graphql": "^15.6.0", 38 | "graphql-subscriptions": "^1.2.1", 39 | "pg": "^8.7.1", 40 | "postgres": "^1.0.2", 41 | "reflect-metadata": "^0.1.13", 42 | "rimraf": "^3.0.2", 43 | "rxjs": "^7.3.0", 44 | "typeorm": "^0.2.37" 45 | }, 46 | "devDependencies": { 47 | "@nestjs/cli": "^8.0.0", 48 | "@nestjs/schematics": "^8.0.0", 49 | "@nestjs/testing": "^8.0.0", 50 | "@types/express": "^4.17.13", 51 | "@types/jest": "^27.0.1", 52 | "@types/node": "^16.0.0", 53 | "@types/supertest": "^2.0.11", 54 | "@typescript-eslint/eslint-plugin": "^4.28.2", 55 | "@typescript-eslint/parser": "^4.28.2", 56 | "eslint": "^7.30.0", 57 | "eslint-config-prettier": "^8.3.0", 58 | "eslint-plugin-prettier": "^3.4.0", 59 | "jest": "^27.0.6", 60 | "prettier": "^2.3.2", 61 | "supertest": "^6.1.3", 62 | "ts-jest": "^27.0.3", 63 | "ts-loader": "^9.2.3", 64 | "ts-node": "^10.0.0", 65 | "tsconfig-paths": "^3.10.1", 66 | "typescript": "^4.3.5" 67 | }, 68 | "jest": { 69 | "moduleFileExtensions": [ 70 | "js", 71 | "json", 72 | "ts" 73 | ], 74 | "rootDir": "src", 75 | "testRegex": ".*\\.spec\\.ts$", 76 | "transform": { 77 | "^.+\\.(t|j)s$": "ts-jest" 78 | }, 79 | "collectCoverageFrom": [ 80 | "**/*.(t|j)s" 81 | ], 82 | "coverageDirectory": "../coverage", 83 | "testEnvironment": "node" 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { GraphQLModule } from '@nestjs/graphql'; 3 | import { TypeOrmModule } from '@nestjs/typeorm'; 4 | import { join } from 'path'; 5 | import { AppController } from './app.controller'; 6 | import { AppService } from './app.service'; 7 | import { StudentsModule } from './modules/students/students.module'; 8 | import { DisciplinesModule } from './modules/disciplines/disciplines.module'; 9 | import { LessonsModule } from './modules/lessons/lessons.module'; 10 | import { ContentsModule } from './modules/contents/contents.module'; 11 | 12 | @Module({ 13 | imports: [ 14 | TypeOrmModule.forRoot(), 15 | GraphQLModule.forRoot({ 16 | debug: false, 17 | autoSchemaFile: join(process.cwd(), 'src/schema.gql'), 18 | sortSchema: true, 19 | }), 20 | StudentsModule, 21 | DisciplinesModule, 22 | LessonsModule, 23 | ContentsModule, 24 | ], 25 | controllers: [AppController], 26 | providers: [AppService], 27 | }) 28 | export class AppModule {} 29 | -------------------------------------------------------------------------------- /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/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(3002); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /src/modules/bases/dto/base.dto.ts: -------------------------------------------------------------------------------- 1 | import { FilterableField } from '@nestjs-query/query-graphql'; 2 | import { ObjectType } from '@nestjs/graphql'; 3 | 4 | @ObjectType() 5 | export class BaseDTO { 6 | @FilterableField() 7 | id: string; 8 | 9 | @FilterableField() 10 | createdAt: Date; 11 | 12 | @FilterableField() 13 | updatedAt: Date; 14 | 15 | @FilterableField() 16 | deletedAt: Date; 17 | } 18 | -------------------------------------------------------------------------------- /src/modules/bases/entities/base.entity.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CreateDateColumn, 3 | DeleteDateColumn, 4 | Entity, 5 | PrimaryGeneratedColumn, 6 | UpdateDateColumn, 7 | } from 'typeorm'; 8 | 9 | @Entity() 10 | export class BaseEntity { 11 | @PrimaryGeneratedColumn('uuid') 12 | id: string; 13 | 14 | @CreateDateColumn() 15 | createdAt: Date; 16 | 17 | @UpdateDateColumn() 18 | updatedAt: Date; 19 | 20 | @DeleteDateColumn() 21 | deletedAt: Date; 22 | } 23 | -------------------------------------------------------------------------------- /src/modules/contents/contents.module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NestjsQueryGraphQLModule, 3 | PagingStrategies, 4 | } from '@nestjs-query/query-graphql'; 5 | import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm'; 6 | import { Module } from '@nestjs/common'; 7 | import { ContentDTO } from './dto/content.dto'; 8 | import { CreateContentInput } from './dto/create-content.input'; 9 | import { UpdateContentInput } from './dto/update-content.input'; 10 | import { Content } from './entities/content.entity'; 11 | 12 | @Module({ 13 | imports: [ 14 | NestjsQueryGraphQLModule.forFeature({ 15 | imports: [NestjsQueryTypeOrmModule.forFeature([Content])], 16 | resolvers: [ 17 | { 18 | DTOClass: ContentDTO, 19 | EntityClass: Content, 20 | CreateDTOClass: CreateContentInput, 21 | UpdateDTOClass: UpdateContentInput, 22 | enableTotalCount: true, 23 | pagingStrategy: PagingStrategies.OFFSET, 24 | }, 25 | ], 26 | }), 27 | ], 28 | providers: [], 29 | }) 30 | export class ContentsModule {} 31 | -------------------------------------------------------------------------------- /src/modules/contents/dto/content.dto.ts: -------------------------------------------------------------------------------- 1 | import { 2 | FilterableField, 3 | FilterableRelation, 4 | } from '@nestjs-query/query-graphql'; 5 | import { ObjectType } from '@nestjs/graphql'; 6 | import { BaseDTO } from 'src/modules/bases/dto/base.dto'; 7 | import { LessonDTO } from 'src/modules/lessons/dto/lesson.dto'; 8 | 9 | @ObjectType('Content') 10 | @FilterableRelation('lesson', () => LessonDTO) 11 | export class ContentDTO extends BaseDTO { 12 | @FilterableField({ nullable: true }) 13 | description: string; 14 | 15 | @FilterableField({ nullable: true }) 16 | linkContent: string; 17 | } 18 | -------------------------------------------------------------------------------- /src/modules/contents/dto/create-content.input.ts: -------------------------------------------------------------------------------- 1 | import { InputType } from '@nestjs/graphql'; 2 | 3 | @InputType() 4 | export class CreateContentInput { 5 | description: string; 6 | 7 | linkContent?: string; 8 | 9 | lessonId?: string; 10 | } 11 | -------------------------------------------------------------------------------- /src/modules/contents/dto/update-content.input.ts: -------------------------------------------------------------------------------- 1 | import { Field, ID, InputType, PartialType } from '@nestjs/graphql'; 2 | import { CreateContentInput } from './create-content.input'; 3 | 4 | @InputType() 5 | export class UpdateContentInput extends PartialType(CreateContentInput) { 6 | @Field(() => ID, { nullable: true }) 7 | id?: string; 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/contents/entities/content.entity.ts: -------------------------------------------------------------------------------- 1 | import { BaseEntity } from 'src/modules/bases/entities/base.entity'; 2 | import { Lesson } from 'src/modules/lessons/entities/lesson.entity'; 3 | import { Column, Entity, ManyToOne } from 'typeorm'; 4 | 5 | @Entity() 6 | export class Content extends BaseEntity { 7 | @Column() 8 | description: string; 9 | 10 | @Column({ nullable: true }) 11 | linkContent: string; 12 | 13 | @ManyToOne(() => Lesson) 14 | lesson: Lesson; 15 | 16 | @Column({ nullable: true }) 17 | lessonId: string; 18 | } 19 | -------------------------------------------------------------------------------- /src/modules/disciplines/disciplines.module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NestjsQueryGraphQLModule, 3 | PagingStrategies, 4 | } from '@nestjs-query/query-graphql'; 5 | import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm'; 6 | import { Module } from '@nestjs/common'; 7 | import { CreateDisciplineInput } from './dto/create-discipline.input'; 8 | import { DisciplineDTO } from './dto/discipline.dto'; 9 | import { UpdateDisciplineInput } from './dto/update-discipline.input'; 10 | import { Discipline } from './entities/discipline.entity'; 11 | 12 | @Module({ 13 | imports: [ 14 | NestjsQueryGraphQLModule.forFeature({ 15 | imports: [NestjsQueryTypeOrmModule.forFeature([Discipline])], 16 | resolvers: [ 17 | { 18 | DTOClass: DisciplineDTO, 19 | EntityClass: Discipline, 20 | CreateDTOClass: CreateDisciplineInput, 21 | UpdateDTOClass: UpdateDisciplineInput, 22 | enableTotalCount: true, 23 | pagingStrategy: PagingStrategies.OFFSET, 24 | }, 25 | ], 26 | }), 27 | ], 28 | providers: [], 29 | }) 30 | export class DisciplinesModule {} 31 | -------------------------------------------------------------------------------- /src/modules/disciplines/dto/create-discipline.input.ts: -------------------------------------------------------------------------------- 1 | import { InputType } from '@nestjs/graphql'; 2 | 3 | @InputType() 4 | export class CreateDisciplineInput { 5 | name: string; 6 | } 7 | -------------------------------------------------------------------------------- /src/modules/disciplines/dto/discipline.dto.ts: -------------------------------------------------------------------------------- 1 | import { 2 | FilterableField, 3 | FilterableOffsetConnection, 4 | } from '@nestjs-query/query-graphql'; 5 | import { ObjectType } from '@nestjs/graphql'; 6 | import { BaseDTO } from 'src/modules/bases/dto/base.dto'; 7 | import { StudentDTO } from './../../students/dto/student.dto'; 8 | 9 | @ObjectType('Discipline') 10 | @FilterableOffsetConnection('students', () => StudentDTO, { 11 | nullable: true, 12 | }) 13 | export class DisciplineDTO extends BaseDTO { 14 | @FilterableField() 15 | name: string; 16 | } 17 | -------------------------------------------------------------------------------- /src/modules/disciplines/dto/update-discipline.input.ts: -------------------------------------------------------------------------------- 1 | import { Field, ID, InputType, PartialType } from '@nestjs/graphql'; 2 | import { CreateDisciplineInput } from './create-discipline.input'; 3 | 4 | @InputType() 5 | export class UpdateDisciplineInput extends PartialType(CreateDisciplineInput) { 6 | @Field(() => ID, { nullable: true }) 7 | id?: string; 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/disciplines/entities/discipline.entity.ts: -------------------------------------------------------------------------------- 1 | import { BaseEntity } from 'src/modules/bases/entities/base.entity'; 2 | import { Student } from 'src/modules/students/entities/student.entity'; 3 | import { Column, Entity, JoinTable, ManyToMany } from 'typeorm'; 4 | 5 | @Entity() 6 | export class Discipline extends BaseEntity { 7 | @Column() 8 | name: string; 9 | 10 | @ManyToMany(() => Student, (students) => students.disciplines, { 11 | nullable: true, 12 | }) 13 | @JoinTable() 14 | students: Student[]; 15 | } 16 | -------------------------------------------------------------------------------- /src/modules/lessons/dto/create-lesson.input.ts: -------------------------------------------------------------------------------- 1 | import { InputType } from '@nestjs/graphql'; 2 | 3 | @InputType() 4 | export class CreateLessonInput { 5 | description: string; 6 | } 7 | -------------------------------------------------------------------------------- /src/modules/lessons/dto/lesson.dto.ts: -------------------------------------------------------------------------------- 1 | import { 2 | FilterableField, 3 | FilterableOffsetConnection, 4 | } from '@nestjs-query/query-graphql'; 5 | import { ObjectType } from '@nestjs/graphql'; 6 | import { BaseDTO } from 'src/modules/bases/dto/base.dto'; 7 | import { ContentDTO } from './../../contents/dto/content.dto'; 8 | 9 | @ObjectType('Lesson') 10 | @FilterableOffsetConnection('contents', () => ContentDTO, { nullable: true }) 11 | export class LessonDTO extends BaseDTO { 12 | @FilterableField() 13 | description: string; 14 | } 15 | -------------------------------------------------------------------------------- /src/modules/lessons/dto/update-lesson.input.ts: -------------------------------------------------------------------------------- 1 | import { Field, ID, InputType, PartialType } from '@nestjs/graphql'; 2 | import { CreateLessonInput } from './create-lesson.input'; 3 | 4 | @InputType() 5 | export class UpdateLessonInput extends PartialType(CreateLessonInput) { 6 | @Field(() => ID) 7 | id?: string; 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/lessons/entities/lesson.entity.ts: -------------------------------------------------------------------------------- 1 | import { BaseEntity } from 'src/modules/bases/entities/base.entity'; 2 | import { Content } from 'src/modules/contents/entities/content.entity'; 3 | import { Column, Entity, OneToMany } from 'typeorm'; 4 | 5 | @Entity() 6 | export class Lesson extends BaseEntity { 7 | @Column() 8 | description: string; 9 | 10 | @OneToMany(() => Content, (contents) => contents.lesson) 11 | contents: Content[]; 12 | } 13 | -------------------------------------------------------------------------------- /src/modules/lessons/lessons.module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NestjsQueryGraphQLModule, 3 | PagingStrategies, 4 | } from '@nestjs-query/query-graphql'; 5 | import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm'; 6 | import { Module } from '@nestjs/common'; 7 | import { CreateLessonInput } from './dto/create-lesson.input'; 8 | import { LessonDTO } from './dto/lesson.dto'; 9 | import { UpdateLessonInput } from './dto/update-lesson.input'; 10 | import { Lesson } from './entities/lesson.entity'; 11 | 12 | @Module({ 13 | imports: [ 14 | NestjsQueryGraphQLModule.forFeature({ 15 | imports: [NestjsQueryTypeOrmModule.forFeature([Lesson])], 16 | resolvers: [ 17 | { 18 | DTOClass: LessonDTO, 19 | EntityClass: Lesson, 20 | CreateDTOClass: CreateLessonInput, 21 | UpdateDTOClass: UpdateLessonInput, 22 | enableTotalCount: true, 23 | pagingStrategy: PagingStrategies.OFFSET, 24 | }, 25 | ], 26 | }), 27 | ], 28 | providers: [], 29 | }) 30 | export class LessonsModule {} 31 | -------------------------------------------------------------------------------- /src/modules/students/dto/create-student.input.ts: -------------------------------------------------------------------------------- 1 | import { InputType } from '@nestjs/graphql'; 2 | 3 | @InputType() 4 | export class CreateStudentInput { 5 | name: string; 6 | 7 | key: string; 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/students/dto/student.dto.ts: -------------------------------------------------------------------------------- 1 | import { 2 | FilterableField, 3 | FilterableOffsetConnection, 4 | } from '@nestjs-query/query-graphql'; 5 | import { ObjectType } from '@nestjs/graphql'; 6 | import { BaseDTO } from 'src/modules/bases/dto/base.dto'; 7 | import { DisciplineDTO } from 'src/modules/disciplines/dto/discipline.dto'; 8 | 9 | @ObjectType('Student') 10 | @FilterableOffsetConnection('disciplines', () => DisciplineDTO, { 11 | nullable: true, 12 | }) 13 | export class StudentDTO extends BaseDTO { 14 | @FilterableField() 15 | name: string; 16 | 17 | @FilterableField() 18 | key: string; 19 | } 20 | -------------------------------------------------------------------------------- /src/modules/students/dto/update-student.input.ts: -------------------------------------------------------------------------------- 1 | import { Field, InputType, PartialType } from '@nestjs/graphql'; 2 | import { CreateStudentInput } from './create-student.input'; 3 | 4 | @InputType() 5 | export class UpdateStudentInput extends PartialType(CreateStudentInput) { 6 | @Field(() => String) 7 | id: string; 8 | } 9 | -------------------------------------------------------------------------------- /src/modules/students/entities/student.entity.ts: -------------------------------------------------------------------------------- 1 | import { Discipline } from 'src/modules/disciplines/entities/discipline.entity'; 2 | import { Column, Entity, ManyToMany } from 'typeorm'; 3 | import { BaseEntity } from './../../bases/entities/base.entity'; 4 | 5 | @Entity() 6 | export class Student extends BaseEntity { 7 | @Column() 8 | name: string; 9 | 10 | @Column() 11 | key: string; 12 | 13 | @ManyToMany(() => Discipline, (disciplines) => disciplines.students, { 14 | nullable: true, 15 | }) 16 | disciplines: Discipline[]; 17 | } 18 | -------------------------------------------------------------------------------- /src/modules/students/students.module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | NestjsQueryGraphQLModule, 3 | PagingStrategies, 4 | } from '@nestjs-query/query-graphql'; 5 | import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm'; 6 | import { Module } from '@nestjs/common'; 7 | import { CreateStudentInput } from './dto/create-student.input'; 8 | import { StudentDTO } from './dto/student.dto'; 9 | import { UpdateStudentInput } from './dto/update-student.input'; 10 | import { Student } from './entities/student.entity'; 11 | 12 | @Module({ 13 | imports: [ 14 | NestjsQueryGraphQLModule.forFeature({ 15 | imports: [NestjsQueryTypeOrmModule.forFeature([Student])], 16 | resolvers: [ 17 | { 18 | DTOClass: StudentDTO, 19 | EntityClass: Student, 20 | CreateDTOClass: CreateStudentInput, 21 | UpdateDTOClass: UpdateStudentInput, 22 | enableTotalCount: true, 23 | pagingStrategy: PagingStrategies.OFFSET, 24 | }, 25 | ], 26 | }), 27 | ], 28 | providers: [], 29 | }) 30 | export class StudentsModule {} 31 | -------------------------------------------------------------------------------- /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 | } 22 | --------------------------------------------------------------------------------