Loading backend/src/town/entities/town.entity.ts +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ export class Town { @PrimaryGeneratedColumn() townId: number; @ManyToOne(() => State, (state) => state.stateId, { nullable: false }) @ManyToOne(() => State, (state) => state.stateId, { nullable: false, eager: true }) state: State; @OneToMany(() => Place, (place) => place.idTown) Loading backend/src/town/town.controller.ts +9 −0 Original line number Diff line number Diff line Loading @@ -88,4 +88,13 @@ export class TownController { throw error; } } @Get('town/:idTown') async findOne(@Param('idTown') idTown: number) { try { return await this.townService.findOne(idTown); } catch (error) { throw error; } } } backend/src/town/town.service.ts +15 −0 Original line number Diff line number Diff line Loading @@ -93,4 +93,19 @@ export class TownService { await this.townTradRepository.update({ townId, language: LANGUAGES.ES }, createTownTradDtoES); await this.townTradRepository.update({ townId, language: LANGUAGES.EN }, createTownTradDtoEN); } async findOne(idTown: number) { const town = await this.townRepository.findOneByOrFail({ townId: idTown }); const tradEN = await this.townTradRepository.findOneByOrFail({ townId: idTown, language: LANGUAGES.EN }); const tradES = await this.townTradRepository.findOneByOrFail({ townId: idTown, language: LANGUAGES.ES }); console.log(town); return { townId: town.townId, name: town.name, descriptionEN: tradEN.description, descriptionES: tradES.description, imageName: `${ServerConstants.HOST}/towns/${town.imageName}`, stateId: town.state.stateId, }; } } Loading
backend/src/town/entities/town.entity.ts +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ export class Town { @PrimaryGeneratedColumn() townId: number; @ManyToOne(() => State, (state) => state.stateId, { nullable: false }) @ManyToOne(() => State, (state) => state.stateId, { nullable: false, eager: true }) state: State; @OneToMany(() => Place, (place) => place.idTown) Loading
backend/src/town/town.controller.ts +9 −0 Original line number Diff line number Diff line Loading @@ -88,4 +88,13 @@ export class TownController { throw error; } } @Get('town/:idTown') async findOne(@Param('idTown') idTown: number) { try { return await this.townService.findOne(idTown); } catch (error) { throw error; } } }
backend/src/town/town.service.ts +15 −0 Original line number Diff line number Diff line Loading @@ -93,4 +93,19 @@ export class TownService { await this.townTradRepository.update({ townId, language: LANGUAGES.ES }, createTownTradDtoES); await this.townTradRepository.update({ townId, language: LANGUAGES.EN }, createTownTradDtoEN); } async findOne(idTown: number) { const town = await this.townRepository.findOneByOrFail({ townId: idTown }); const tradEN = await this.townTradRepository.findOneByOrFail({ townId: idTown, language: LANGUAGES.EN }); const tradES = await this.townTradRepository.findOneByOrFail({ townId: idTown, language: LANGUAGES.ES }); console.log(town); return { townId: town.townId, name: town.name, descriptionEN: tradEN.description, descriptionES: tradES.description, imageName: `${ServerConstants.HOST}/towns/${town.imageName}`, stateId: town.state.stateId, }; } }