Loading backend/src/place/place.service.ts +11 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { Town } from 'src/town/entities/town.entity'; import { GetPlaceDto } from './dto/get-place.dto'; import { ServerConstants } from 'src/constants/server.contants'; import { Available } from 'src/activity/enum/available.enum'; @Injectable() export class PlaceService { Loading Loading @@ -55,10 +56,13 @@ export class PlaceService { idPlace: insertedId, description: createPlaceDto.descriptionES, }; // TODO: add transaction to rollback if one of the inserts fails await this.placeTraductionRepository.insert(createTradEs); await this.placeTraductionRepository.insert(createTradEn); await this.availableDateRepository.insert(createDate); if (createPlaceDto.available === Available.CUSTOM) { await this.availableDateRepository.insert({ ...createDate, idPlace: insertedId }); } } async findAllByTown(idTown: number, lang: LANGUAGES) { Loading @@ -66,6 +70,7 @@ export class PlaceService { .getRepository(PlaceTraduction) .createQueryBuilder('placeTrad') .leftJoin('placeTrad.idPlace', 'place') .leftJoin('place.availableDates', 'availableDate') .select([ 'place.idPlace AS idPlace', 'place.name AS name', Loading @@ -75,8 +80,10 @@ export class PlaceService { 'place.coords AS coords', 'place.openAt AS openAt', 'place.closeAt AS closeAt', 'availableDate.startDate AS startDate', 'availableDate.endDate AS endDate', ]) .where('place.idTown = :idTown', { idTown }) .where('place.idTown = :idTown', { idTown: idTown }) .andWhere('placeTrad.language = :language', { language: lang }) .getRawMany(); const places: GetPlaceDto[] = res.map((place) => { Loading @@ -89,6 +96,8 @@ export class PlaceService { name: place.name, openAt: place.openAt, closeAt: place.closeAt, startDate: place.startDate, endDate: place.endDate, }; }); return places; Loading Loading
backend/src/place/place.service.ts +11 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { Town } from 'src/town/entities/town.entity'; import { GetPlaceDto } from './dto/get-place.dto'; import { ServerConstants } from 'src/constants/server.contants'; import { Available } from 'src/activity/enum/available.enum'; @Injectable() export class PlaceService { Loading Loading @@ -55,10 +56,13 @@ export class PlaceService { idPlace: insertedId, description: createPlaceDto.descriptionES, }; // TODO: add transaction to rollback if one of the inserts fails await this.placeTraductionRepository.insert(createTradEs); await this.placeTraductionRepository.insert(createTradEn); await this.availableDateRepository.insert(createDate); if (createPlaceDto.available === Available.CUSTOM) { await this.availableDateRepository.insert({ ...createDate, idPlace: insertedId }); } } async findAllByTown(idTown: number, lang: LANGUAGES) { Loading @@ -66,6 +70,7 @@ export class PlaceService { .getRepository(PlaceTraduction) .createQueryBuilder('placeTrad') .leftJoin('placeTrad.idPlace', 'place') .leftJoin('place.availableDates', 'availableDate') .select([ 'place.idPlace AS idPlace', 'place.name AS name', Loading @@ -75,8 +80,10 @@ export class PlaceService { 'place.coords AS coords', 'place.openAt AS openAt', 'place.closeAt AS closeAt', 'availableDate.startDate AS startDate', 'availableDate.endDate AS endDate', ]) .where('place.idTown = :idTown', { idTown }) .where('place.idTown = :idTown', { idTown: idTown }) .andWhere('placeTrad.language = :language', { language: lang }) .getRawMany(); const places: GetPlaceDto[] = res.map((place) => { Loading @@ -89,6 +96,8 @@ export class PlaceService { name: place.name, openAt: place.openAt, closeAt: place.closeAt, startDate: place.startDate, endDate: place.endDate, }; }); return places; Loading