full project: admin panel, backend modules, docs

This commit is contained in:
Lizandro Guarnizo
2026-06-03 22:11:01 -05:00
parent 1635723035
commit afc096d552
94 changed files with 15994 additions and 240 deletions
+10 -2
View File
@@ -1,6 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Controller, Get, Post, Param, Body, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { LocationsService } from './locations.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@ApiTags('Locations')
@Controller('locations')
@@ -21,4 +22,11 @@ export class LocationsController {
getCities(@Param('regionId') id: string) {
return this.locations.getCities(id);
}
@Post('cities')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
createCity(@Body() body: { region_id: string; name: string; latitude?: number; longitude?: number }) {
return this.locations.createCity(body);
}
}
+15 -1
View File
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
@@ -16,4 +16,18 @@ export class LocationsService {
getCities(regionId: string) {
return this.prisma.cities.findMany({ where: { region_id: regionId } });
}
async createCity(data: { region_id: string; name: string; latitude?: number; longitude?: number }) {
const region = await this.prisma.regions.findUnique({ where: { id: data.region_id } });
if (!region) throw new NotFoundException('Región no encontrada');
const existing = await this.prisma.cities.findFirst({
where: { region_id: data.region_id, name: data.name },
});
if (existing) throw new ConflictException('Ya existe esta ciudad en la región');
return this.prisma.cities.create({
data: { region_id: data.region_id, name: data.name, latitude: data.latitude, longitude: data.longitude },
});
}
}