Commit a3f0834c authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Agregando endpoint para saber los datos del admin actual y agregnando endpoint para obtener un solo pueblo

See merge request ltrpro/pueblosmagicosconia!39
parents c8bc80c7 af6fa4ac
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
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,
    };
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -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)
+9 −0
Original line number Diff line number Diff line
@@ -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;
    }
  }
}
+15 −0
Original line number Diff line number Diff line
@@ -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,
    };
  }
}