Creating a new module
nest g module auth
nest for nest
g for generate
auth for the file name
Creating a controller
nest g controller auth
nest g service auth
For Connecting Database
Create a file Entity.ts under auth
Decorators can be defined for either a class, a method or a property. (@Entity)
import { BaseEntity, Column, PrimaryGeneratedColumn } from "typeorm"; export class User extends BaseEntity { @PrimaryGeneratedColumn() id: number; @Column() username: string; @Column() password: string; }
Base Class Repository for TypeORM ---
Repository for type USER === Repository<User>
Auth Module
we want to show that database which we are going to use throughout our module soo
introducing the Repository under Module section
import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeORMError } from 'typeorm'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; import { UserRepository } from './user.repository'; @Module({ imports: [ TypeOrmModule.forFeature([UserRepository]), ], controllers: [AuthController], providers: [AuthService], }) export class AuthModule {}
Comentarios