diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index 70a9d11745bf87e78749ebbcca59959364a23cab..072625aac40ed453adac01de5cb8d3e945a78dc4 100644 --- a/backend/src/admin/admin.controller.ts +++ b/backend/src/admin/admin.controller.ts @@ -1,7 +1,25 @@ -import { Controller } from '@nestjs/common'; +import { Controller, Get, Req } from '@nestjs/common'; import { AdminService } from './admin.service'; +import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { ADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; +import { Roles } from 'src/auth/role.decorator'; +import { CustomAdminRequest } from 'src/auth/admin/interface/customAdminReq'; -@Controller('admin') +@Controller('') +@ApiTags('Admin') export class AdminController { constructor(private readonly adminService: AdminService) {} + + @Roles(ADMIN_ROLES) + @ApiBearerAuth('jwt') + @Get('admin/whoami') + async whoAmI(@Req() req: CustomAdminRequest) { + return { + email: req.admin.email, + name: req.admin.name, + lastName: req.admin.lastName, + role: req.admin.role, + idTown: req.admin?.idTown?.townId || null, + }; + } } diff --git a/backend/src/town/entities/town.entity.ts b/backend/src/town/entities/town.entity.ts index bfe8a378d1fc2f4f414671f12bbe92fd9ceee9c8..4b6a569f0186e796ce47315b82ad2fe637479c22 100644 --- a/backend/src/town/entities/town.entity.ts +++ b/backend/src/town/entities/town.entity.ts @@ -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) diff --git a/backend/src/town/town.controller.ts b/backend/src/town/town.controller.ts index 79a817372a63276af69a2d42779d5eb8706ee4f2..34a17eef9a5113a72b514c4822980af719f3b571 100644 --- a/backend/src/town/town.controller.ts +++ b/backend/src/town/town.controller.ts @@ -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; + } + } } diff --git a/backend/src/town/town.service.ts b/backend/src/town/town.service.ts index 59fc928bed9f51209afc008b28d11066630e07b9..4ec2d9f65de06282fabcdd7f64c7197b0f8eced0 100644 --- a/backend/src/town/town.service.ts +++ b/backend/src/town/town.service.ts @@ -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, + }; + } }