Commit 3907cb3c authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Corrigiendo url de endpoint de place,  agregando endpoint para obtener Point por su place, endpoint para obtener audio de un Point

See merge request ltrpro/pueblosmagicosconia!30
parents 04730163 a86138a3
Loading
Loading
Loading
Loading
+2 −24
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';
@@ -38,7 +26,7 @@ export class PlaceController {

  @ApiQuery({ name: 'lang', type: String })
  @ApiParam({ name: 'idTown', type: Number })
  @Get('/town/:idTown/activity')
  @Get('/town/:idTown/place')
  async findAll(@Param('idTown') idTown: number, @Query('lang') lang: string) {
    try {
      return this.placeService.findAllByTown(idTown, lang as LANGUAGES);
@@ -51,14 +39,4 @@ export class PlaceController {
  findOne(@Param('id') id: string) {
    return this.placeService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updatePlaceDto: UpdatePlaceDto) {
    return this.placeService.update(+id, updatePlaceDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.placeService.remove(+id);
  }
}
+0 −9
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';
@@ -107,12 +106,4 @@ export class PlaceService {
    const place = await this.placeRepository.findOneBy({ idPlace: id });
    return place;
  }

  update(id: number, updatePlaceDto: UpdatePlaceDto) {
    return `This action updates a #${id} place`;
  }

  remove(id: number) {
    return `This action removes a #${id} place`;
  }
}
+17 −21
Original line number Diff line number Diff line
import { Controller, Get, Post, Body, Patch, Param, Delete, UseInterceptors, UploadedFile } from '@nestjs/common';
import { Controller, Get, Post, Body, Param, UseInterceptors, UploadedFile, Query } from '@nestjs/common';
import { PointOfInterestService } from './PointOfInterest.service';
import { CreatePointAndTradDto } from './dto/create-pointAndTraduction.dto';
import { UpdatePointDto } from './dto/update-point.dto';
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Roles } from 'src/auth/role.decorator';
import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
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) {}
@@ -16,7 +16,7 @@ export class PointOfInterestController {
  @ApiConsumes('multipart/form-data')
  @Roles(ADMIN_ROLES)
  @ApiBearerAuth('jwt')
  @Post()
  @Post('point')
  @UseInterceptors(fileInterceptor('image', 'static/points/', ['.jpg', '.jpeg', '.png']))
  async create(@UploadedFile(new FileValidationPipe()) file, @Body() createActivityDto: CreatePointAndTradDto) {
    try {
@@ -27,23 +27,19 @@ export class PointOfInterestController {
    }
  }

  @Get()
  findAll() {
    return this.activityService.findAll();
  @ApiQuery({ name: 'lang', type: String })
  @ApiParam({ name: 'idPlace', type: Number })
  @Get('/place/:idPlace/point')
  async findAllByPlace(@Param('idPlace') idPlace: number, @Query('lang') lang: string) {
    return this.activityService.findAllByPlace(idPlace, lang as LANGUAGES);
  }

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

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateActivityDto: UpdatePointDto) {
    return this.activityService.update(+id, updateActivityDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.activityService.remove(+id);
  @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);
  }
}
+49 −17
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 { UpdatePointDto } from './dto/update-point.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { PointOfInterest } from './entities/PointOfInterest.entity';
import { Repository } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { PointOfInterestTraduction } from './entities/PointOfInterestTraduction.entity';
import { CreatePointDto } from './dto/create-point.dto';
import { PlaceService } from 'src/place/place.service';
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 {
@@ -16,6 +18,7 @@ export class PointOfInterestService {
    @InjectRepository(PointOfInterest) private pointRepository: Repository<PointOfInterest>,
    @InjectRepository(PointOfInterestTraduction) private pointTraductionRepository,
    private readonly placeService: PlaceService,
    @InjectDataSource() private dataSource: DataSource,
  ) {}
  async create(createPointAndTradDto: CreatePointAndTradDto) {
    const place = await this.placeService.findOne(createPointAndTradDto.idPlace);
@@ -33,7 +36,7 @@ export class PointOfInterestService {
      idPoint: insertedId,
      language: LANGUAGES.EN,
      content: createPointAndTradDto.contentEN,
      audioName: 'audioName',
      audioName: 'default.mp3',
      directions: createPointAndTradDto.directionsEN,
    };

@@ -41,26 +44,55 @@ export class PointOfInterestService {
      idPoint: insertedId,
      language: LANGUAGES.ES,
      content: createPointAndTradDto.contentES,
      audioName: 'audioName',
      audioName: 'default.mp3',
      directions: createPointAndTradDto.directionsES,
    };
    await this.pointTraductionRepository.insert(createTradEs);
    await this.pointTraductionRepository.insert(createTradEn);
  }

  findAll() {
    return `This action returns all activity`;
  async findAllByPlace(idPlace: number, lang: LANGUAGES): Promise<getPointDto[]> {
    const place = await this.placeService.findOne(idPlace);
    if (!place) {
      throw new BadRequestException('Place not found');
    }
    let points: getPointDto[] = await this.dataSource
      .getRepository(PointOfInterestTraduction)
      .createQueryBuilder('pointTrad')
      .leftJoin('pointTrad.idPoint', 'point')
      .select([
        'point.idPoint as idPoint',
        'point.name as name',
        'point.imageName as imageName',
        'pointTrad.content as content',
        'pointTrad.directions as directions',
        'pointTrad.audioName as audioName',
        'point.idPlace as idPlace',
      ])
      .where('point.idPlace = :idPlace', { idPlace })
      .andWhere('pointTrad.language = :lang', { lang })
      .getRawMany();

  findOne(id: number) {
    return `This action returns a #${id} activity`;
    points = points.map((point) => {
      return {
        idPoint: point.idPoint,
        idPlace: point.idPlace,
        name: point.name,
        imageName: `${ServerConstants.HOST}/points/${point.imageName}`,
        content: point.content,
        directions: point.directions,
        audioName: `${ServerConstants.HOST}/audios/${point.audioName}`,
      };
    });
    return points;
  }

  update(id: number, updateActivityDto: UpdatePointDto) {
    return `This action updates a #${id} activity`;
  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');
    }

  remove(id: number) {
    return `This action removes a #${id} activity`;
    const filePath = `${ServerConstants.HOST}/audios/${pointTrad.audioName}`;
    return createReadStream(filePath);
  }
}
+9 −0
Original line number Diff line number Diff line
export class getPointDto {
  idPoint: number;
  idPlace: number;
  name: string;
  imageName: string;
  content: string;
  directions: string;
  audioName: string;
}
Loading