Agregar funcionalidad para agregar almacenamiento en la base de cedetec de T&L

This commit is contained in:
santiago
2025-07-30 14:16:14 -06:00
parent a5da262469
commit 5c68472a85
7 changed files with 71 additions and 31 deletions
@@ -6,12 +6,11 @@ export class AlmacenamientoController {
constructor(private readonly almacenamientoService: AlmacenamientoService) {}
@Post()
async create(@Body() body: { email: string; agree: boolean }) {
// Save only if agree is true
async create(@Body() body: { correo: string; agree: boolean }) {
if (!body.agree) {
return { message: 'User did not agree', data: body };
}
const saved = await this.almacenamientoService.create(body.email);
const saved = await this.almacenamientoService.create(body.correo);
return { message: 'Data saved', data: saved };
}
+3 -2
View File
@@ -15,12 +15,13 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
name: 'almacenamiento',
type: 'mariadb',
host: configService.get('HOST_TYL'),
port: configService.get('PORT_TYL'),
port: Number(configService.get('PORT_TYL')),
username: configService.get('USUARIO_TYL'),
password: configService.get('CONTRASENA_TYL'),
database: configService.get('DATABASE_TYL'),
entities: [Almacenamiento],
synchronize: false,
synchronize: true,
ssl: false, // <- importante
}),
}),
TypeOrmModule.forFeature([Almacenamiento], 'almacenamiento'),
+6 -2
View File
@@ -12,8 +12,12 @@ export class AlmacenamientoService {
// Example method to create a new record
async create(correo: string): Promise<Almacenamiento> {
const nuevo = this.almacenamientoRepository.create({ correo });
return this.almacenamientoRepository.save(nuevo);
const existente = await this.almacenamientoRepository.findOneBy({ correo });
if (existente) {
return existente; // o lanzar un error si prefieres
}
const nuevo = this.almacenamientoRepository.create({ correo });
return this.almacenamientoRepository.save(nuevo);
}
// Example method to get all records
+1
View File
@@ -75,6 +75,7 @@ import { Almacenamiento } from './entities/almacenamiento.entity';
username: configService.get('DB_USER'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
synchronize: true,
entities: [
Evento,
Participante,