feat: backend API NestJS + Prisma + JWT auth + todos los módulos
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { LocationsService } from './locations.service';
|
||||
|
||||
@ApiTags('Locations')
|
||||
@Controller('locations')
|
||||
export class LocationsController {
|
||||
constructor(private locations: LocationsService) {}
|
||||
|
||||
@Get('countries')
|
||||
getCountries() {
|
||||
return this.locations.getCountries();
|
||||
}
|
||||
|
||||
@Get('countries/:countryId/regions')
|
||||
getRegions(@Param('countryId') id: string) {
|
||||
return this.locations.getRegions(id);
|
||||
}
|
||||
|
||||
@Get('regions/:regionId/cities')
|
||||
getCities(@Param('regionId') id: string) {
|
||||
return this.locations.getCities(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { LocationsService } from './locations.service';
|
||||
import { LocationsController } from './locations.controller';
|
||||
|
||||
@Module({
|
||||
providers: [LocationsService],
|
||||
controllers: [LocationsController],
|
||||
})
|
||||
export class LocationsModule {}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class LocationsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
getCountries() {
|
||||
return this.prisma.countries.findMany({ include: { regions: { include: { cities: true } } } });
|
||||
}
|
||||
|
||||
getRegions(countryId: string) {
|
||||
return this.prisma.regions.findMany({ where: { country_id: countryId }, include: { cities: true } });
|
||||
}
|
||||
|
||||
getCities(regionId: string) {
|
||||
return this.prisma.cities.findMany({ where: { region_id: regionId } });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user