Agregar funcionalidad para agregar almacenamiento en la base de cedetec de T&L
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user