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.service.ts
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateSectionDto } from './dto/create-section.dto';
import { UpdateSectionDto } from './dto/update-section.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Section } from './entities/section.entity';

@Injectable()
export class SectionService {
  constructor(
    @InjectRepository(Section) private readonly sectionRepository: Repository<Section>,
    ) {}

  create(createSectionDto: CreateSectionDto) {
    return 'This action adds a new section';
  }

  async findAll() {
    let sections = await this.sectionRepository.find({
      relations: ['children', 'parent'],
      order: {
        start: 'ASC',
        children: { start: 'ASC' }
      }
    }).catch(error => error);
    if(sections instanceof Error)
      throw new HttpException({error: 500, message: sections.message}, HttpStatus.INTERNAL_SERVER_ERROR);
    return sections.filter(section => section.parent == null).map(section => {delete section.parent; return section;});
  }

  findOne(id: number) {
    return `This action returns a #${id} section`;
  }

  update(id: number, updateSectionDto: UpdateSectionDto) {
    return `This action updates a #${id} section`;
  }

  remove(id: number) {
    return `This action removes a #${id} section`;
  }
}