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/section/section.controller.ts
import { Controller, Get, Post, Body, Patch, Param, Delete, HttpException, HttpStatus } from '@nestjs/common';
import { SectionService } from './section.service';
import { CreateSectionDto } from './dto/create-section.dto';
import { UpdateSectionDto } from './dto/update-section.dto';
import { Public } from 'src/user/auth.guard';

@Controller('section')
export class SectionController {
  constructor(private readonly sectionService: SectionService) {}

  @Post()
  create(@Body() createSectionDto: CreateSectionDto) {
    return this.sectionService.create(createSectionDto);
  }

  @Public()
  @Get()
  async findAll() {
    let sections = await this.sectionService.findAll().catch(error => error);
    if(sections instanceof Error)
      throw new HttpException({error: 500, message: sections.message}, HttpStatus.INTERNAL_SERVER_ERROR);
    for(let section of sections) {
      section.title = {fa: section.title, en: section.translation};
      delete section.translation;

      for(let child of section.children) {
        child.title = {fa: child.title, en: child.translation};
        delete child.translation;
      }
    }
    return {data: sections, error: 0};
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.sectionService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateSectionDto: UpdateSectionDto) {
    return this.sectionService.update(+id, updateSectionDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.sectionService.remove(+id);
  }
}