Commit 2083fd9d authored by Diego Iván's avatar Diego Iván
Browse files

agregando servicio que obtiene Points por su place

parent f1965d69
Loading
Loading
Loading
Loading
+38 −15
Original line number Diff line number Diff line
import { BadRequestException, Injectable } 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';

@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);
@@ -48,19 +51,39 @@ export class PointOfInterestService {
    await this.pointTraductionRepository.insert(createTradEn);
  }

  findAll() {
    return `This action returns all activity`;
  }

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

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

  remove(id: number) {
    return `This action removes 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;
  }
}