nest js dto code example
Example 1: nestjs controller
import { Controller, Get, Post, Body } from '@nestjs/common';
import { CreateCatDto } from './dto/create-cat.dto';
import { CatsService } from './cats.service';
import { Cat } from './interfaces/cat.interface';
@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}
@Post()
async create(@Body() createCatDto: CreateCatDto) {
this.catsService.create(createCatDto);
}
@Get()
async findAll(): Promise<Cat[]> {
return this.catsService.findAll();
}
}
Example 2: netjs dto
interface IUsers {
readonly user_id?: number
readonly email: string
readonly password: string
readonly active?: boolean
readonly created_at?: any
readonly updated_at?: any
}
class UsersDTO implements IUsers {
readonly user_id?: number
readonly email: string
readonly password: string
readonly active?: boolean
readonly created_at?: any
readonly updated_at?: any
}