File: /var/dev/shahnamag/back-end/src/triplet/triplet.controller.ts
import { Controller, Get, Post, Body, Patch, Param, Delete, HttpException, HttpStatus } from '@nestjs/common';
import { TripletService } from './triplet.service';
import { CreateTripletDto } from './dto/create-triplet.dto';
import { UpdateTripletDto } from './dto/update-triplet.dto';
import { Public } from 'src/user/auth.guard';
@Controller('triplet')
export class TripletController {
constructor(private readonly tripletService: TripletService) {}
@Post()
create(@Body() createTripletDto: CreateTripletDto) {
return this.tripletService.create(createTripletDto);
}
@Public()
@Get()
async findAll() {
let triplets = await this.tripletService.findAll().catch(error => error);
if(triplets instanceof Error)
throw new HttpException({error: 500, message: triplets.message}, HttpStatus.INTERNAL_SERVER_ERROR);
return {data: triplets, error: 0};
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.tripletService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateTripletDto: UpdateTripletDto) {
return this.tripletService.update(+id, updateTripletDto);
}
@Delete(':id')
async remove(@Param('id') id: string) {
let result = await this.tripletService.remove(+id).catch(error => error);
if(result instanceof Error)
throw new HttpException({error: 500, message: result.message}, HttpStatus.INTERNAL_SERVER_ERROR);
return true;
}
}