Skip to content

gamingumar/nestjs-tasks

Repository files navigation

nestjs-tasks

Nest JS Tasks management API

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

Description

Tasks CRUD API implemented in NestJS, with custom route guarding and authentication.

Installation

$ yarn

Running the app

# development
$ yarn start | nest start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Migrations

yarn typeorm migration:run

yarn typeorm migration:revert

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Stay in touch

License

Nest is MIT licensed.

Notes

Creating Module:

nest g module name

Controller

  • generate a controller without tests spec

nest g controller name —no-spec

Service

  • generate a service without tests spec

nest g service name —no-spec

DTO

  • (Data transfer Object)
dto/module.dto.ts
module.controller.ts
module.entity.ts
module.module.ts
module.repository.ts
module.service.ts

entity

import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm";

@Entity()
export class Module extends BaseEntity {
}

repository

import { Repository, EntityRepository } from "typeorm";
import { Logger, InternalServerErrorException } from "@nestjs/common";

@EntityRepository(T)
export class ModuleRepository extends Repository<T>{
}

TypeOrm

  • Create Postgres Database (pgadmin and postgres)

yarn add @nestjs/typeorm typeorm p

Documentation

npx compodoc -p tsconfig.json -s

Defining Guards (Role Based Authentication)

@UseGuards(RolesGuard)

@CanAccess(UserTypes.Admin)

Dependencies:

yarn add @nestjs/jwt @nestjs/passport @nestjs/swagger @nestjs/typeorm typeorm passport passport-jwt pg bcrypt class-transformer class-validator config swagger-ui-express

yarn add -D @compodoc/compodoc @types/bcrypt @types/config