Skip to content
Snippets Groups Projects
structures.controller.ts 1.94 KiB
Newer Older
Hugo SUBTIL's avatar
Hugo SUBTIL committed
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { CreateStructureDto } from './dto/create-structure.dto';
import { Structure } from './schemas/structure.schema';
import { StructuresService } from './structures.service';
Hugo SUBTIL's avatar
Hugo SUBTIL committed

@Controller('structures')
export class StructuresController {
  constructor(private readonly structureService: StructuresService) {}

  @Post()
  async create(@Body() createStructureDto: CreateStructureDto) {
    await this.structureService.create(createStructureDto);
  }

  @Get()
  async findAll(): Promise<Structure[]> {
    return this.structureService.findAll();
  }
Hugo SUBTIL's avatar
Hugo SUBTIL committed
  @Get(':text')
  async search(@Param('text') text: string): Promise<Structure[]> {
    return this.structureService.search(text);
  }

Hugo SUBTIL's avatar
Hugo SUBTIL committed
  @Get('count')
  async countCategories(): Promise<Array<{ id: string; count: number }>> {
    const data = await Promise.all([
      this.structureService.countByStructureKey('accesAuxDroits'),
      this.structureService.countByStructureKey('aideALaParentalite'),
      this.structureService.countByStructureKey('cultureEtSecuriteNumerique'),
      this.structureService.countByStructureKey('insertionSocialeEtProfessionnelle'),
      this.structureService.countByStructureKey('accompagnementDesDemarches'),
      this.structureService.countByStructureKey('labelsEtQualifications'),
      this.structureService.countByStructureKey('publicsAcceptes'),
      this.structureService.countByStructureKey('modalitesDacces'),
      this.structureService.countByStructureKey('lesCompetencesDeBase'),
      this.structureService.countByEquipmentsKey('wifiEnAccesLibre'),
      this.structureService.countByEquipmentsKey('ordinateurs'),
      this.structureService.countByEquipmentsKey('tablettes'),
      this.structureService.countByEquipmentsKey('bornesNumeriques'),
      this.structureService.countByEquipmentsKey('imprimantes'),
    ]);
    // Return a concat of all arrays
    return data.reduce((a, b) => [...a, ...b]);
  }