Commit 98ec7708 authored by Diego Iván's avatar Diego Iván
Browse files

agregando endpoint para obtener audio de un point

parent d4f82cac
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseInterceptors,
  UploadedFile,
  Query,
} from '@nestjs/common';
import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common';
import { PlaceService } from './place.service';
import { CreatePlaceDateTradDto } from './dto/create-place-date.dto';
import { UpdatePlaceDto } from './dto/update-place.dto';
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Roles } from 'src/auth/role.decorator';
import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
+0 −1
Original line number Diff line number Diff line
import { BadRequestException, Injectable } from '@nestjs/common';
import { CreatePlaceDateTradDto } from './dto/create-place-date.dto';
import { UpdatePlaceDto } from './dto/update-place.dto';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { Place } from './entities/place.entity';
import { DataSource, Repository } from 'typeorm';
+10 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor';
import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe';
import { LANGUAGES } from 'src/shared/enum/languages.enum';

@Controller('point')
@Controller('')
@ApiTags('Point of interest')
export class PointOfInterestController {
  constructor(private readonly activityService: PointOfInterestService) {}
@@ -33,4 +33,13 @@ export class PointOfInterestController {
  async findAllByPlace(@Param('idPlace') idPlace: number, @Query('lang') lang: string) {
    return this.activityService.findAllByPlace(idPlace, lang as LANGUAGES);
  }

  @ApiQuery({ name: 'lang', type: String })
  @Get('point/:idPoint/audio')
  async getAudio(
    @Param('idPoint') idPoint: number,
    @Query('lang') lang: string,
  ): Promise<Promise<NodeJS.ReadableStream>> {
    return this.activityService.getAudio(idPoint, lang as LANGUAGES);
  }
}
+11 −1
Original line number Diff line number Diff line
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { PointOfInterest } from './entities/PointOfInterest.entity';
@@ -10,6 +10,7 @@ import { CreatePointTradDto } from './dto/create-pointTrad.dto';
import { LANGUAGES } from 'src/shared/enum/languages.enum';
import { getPointDto } from './dto/getPoint.dto';
import { ServerConstants } from 'src/constants/server.contants';
import { createReadStream } from 'fs';

@Injectable()
export class PointOfInterestService {
@@ -85,4 +86,13 @@ export class PointOfInterestService {
    });
    return points;
  }

  async getAudio(idPoint: number, lang: LANGUAGES): Promise<NodeJS.ReadableStream> {
    const pointTrad = await this.pointTraductionRepository.findOneBy({ idPoint, language: lang });
    if (!pointTrad) {
      throw new NotFoundException('Point not found');
    }
    const filePath = `${ServerConstants.HOST}/audios/${pointTrad.audioName}`;
    return createReadStream(filePath);
  }
}