import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common'; import { RealIp } from 'src/decorators/real-ip.decorator'; import { OptionalAuthGuard } from 'src/jwt-auth/optional-auth.guard'; import { RealIpInfo } from 'src/models/main.model'; import { CountyRequest } from 'src/models/server.model'; import { GeoService } from './geo.service'; @Controller('geo') export class GeoController { constructor(private geoService: GeoService) {} @UseGuards(OptionalAuthGuard) @Get(':prefix') findByPrefix(@Param('prefix') prefix: string): any { return this.geoService.findCitiesStartingWith(prefix); } @UseGuards(OptionalAuthGuard) @Get('citiesandstates/:prefix') findByCitiesAndStatesByPrefix(@Param('prefix') prefix: string): any { return this.geoService.findCitiesAndStatesStartingWith(prefix); } @UseGuards(OptionalAuthGuard) @Get(':prefix/:state') findByPrefixAndState(@Param('prefix') prefix: string, @Param('state') state: string): any { return this.geoService.findCitiesStartingWith(prefix, state); } @UseGuards(OptionalAuthGuard) @Post('counties') findByPrefixAndStates(@Body() countyRequest: CountyRequest): any { return this.geoService.findCountiesStartingWith(countyRequest.prefix, countyRequest.states); } @UseGuards(OptionalAuthGuard) @Get('ipinfo/georesult/wysiwyg') async fetchIpAndGeoLocation(@RealIp() ipInfo: RealIpInfo): Promise { return await this.geoService.fetchIpAndGeoLocation(ipInfo); } }