HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
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;
  }
}