Cambios en las relaciones de evento, participante_evento y participante.

This commit is contained in:
santiago
2025-04-02 09:15:14 -06:00
parent fbd753d27e
commit 7b72ee4ec6
18 changed files with 305 additions and 39 deletions
+32 -3
View File
@@ -1,3 +1,4 @@
//import { Module } from '@nestjs/common;
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@@ -15,14 +16,22 @@ import { CuestionarioRespondidoModule } from './cuestionario_respondido/cuestion
import { RespuestaParticipanteAbiertaModule } from './respuesta_participante_abierta/respuesta_participante_abierta.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import { EventoModule } from './evento/evento.module';
import { TipoUserModule } from './tipo_user/tipo_user.module';
import { ParticipanteModule } from './participante/participante.module';
import { QrModule } from './qr/qr.module';
import { AdministradorModule } from './administrador/administrador.module';
import { AsistenciaModule } from './asistencia/asistencia.module';
import { ParticipanteEventoModule } from './participante_evento/participante_evento.module';
@Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
/*
type: 'mysql',
host: process.env.db_host,
host: process.env.db_host, //process.env.db_host
username: process.env.db_username,
database: process.env.db_database,
password: process.env.db_password,
@@ -31,7 +40,19 @@ import { ConfigModule } from '@nestjs/config';
dropSchema: true, // elimina la base de datos
// logging: true, // Habilita los logs para depuración
autoLoadEntities: true, // Carga automáticamente las entidades
*/
//esta es mi base de datos local
type: 'mysql',
host: 'localhost',
port: 3306, //3306
username: 'root',
password: 'admin', //admin
database: 'cidwa', //nestdb
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
//extra
retryAttempts: 10, // Intentos para reconectar
retryDelay: 3000, // Tiempo entre reintentos
}),
CuestionarioModule,
TipoCuestionarioModule,
@@ -43,7 +64,15 @@ import { ConfigModule } from '@nestjs/config';
OpcionModule, PreguntaOpcionModule,
RespuestaParticipanteCerradaModule,
CuestionarioRespondidoModule,
RespuestaParticipanteAbiertaModule],
RespuestaParticipanteAbiertaModule,
EventoModule,
TipoUserModule,
ParticipanteModule,
QrModule,
AdministradorModule,
AsistenciaModule,
ParticipanteEventoModule,
],
controllers: [AppController],
providers: [AppService],
@@ -3,6 +3,7 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany, JoinColum
import { Cuestionario } from 'src/cuestionario/entities/cuestionario.entity';
import { RespuestaParticipanteCerrada } from 'src/respuesta_participante_cerrada/entities/respuesta_participante_cerrada.entity';
import { RespuestaParticipanteAbierta } from 'src/respuesta_participante_abierta/entities/respuesta_participante_abierta.entity';
import { Participante } from 'src/participante/participante.entity';
@Entity('cuestionario_respondido')
export class CuestionarioRespondido {
+8 -5
View File
@@ -1,5 +1,6 @@
import { Participante } from "src/participante/participante.entity";
import { ParticipanteEvento } from "src/participante_evento/participante_evento.entity";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, ManyToMany, OneToMany, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Evento {
@@ -26,13 +27,15 @@ export class Evento {
@JoinColumn({ name: "id_administrador" })
administrador: Administrador;
@OneToMany(() => ParticipanteEvento, (pe) => pe.evento)
participantes: ParticipanteEvento[];
@OneToMany(() => Asistencia, (asistencia) => asistencia.evento)
asistencias: Asistencia[];
*/
@OneToMany(() => ParticipanteEvento, (participanteEvento) => participanteEvento.evento)
participantes: ParticipanteEvento[];
@OneToMany(() => ParticipanteEvento, participanteEvento => participanteEvento.evento)
participanteEventos: ParticipanteEvento[];
}
+2 -1
View File
@@ -7,6 +7,7 @@ import { Evento } from './evento.entity';
@Module({
imports: [TypeOrmModule.forFeature([Evento])],
controllers: [EventoController],
providers: [EventoService]
providers: [EventoService],
exports: [EventoService]
})
export class EventoModule {}
+9 -1
View File
@@ -1,8 +1,16 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import 'dotenv/config';
import { DocsModule } from './docs/docs.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env.PORT ?? 3000);
//await app.listen(process.env.PORT ?? 3000);
DocsModule.setupSwagger(app);
await app.listen(3000);
console.log('API en ejecución en http://localhost:3000');
console.log('Swagger disponible en http://localhost:3000/api-docs');
}
bootstrap();
-2
View File
@@ -1,8 +1,6 @@
import { IsString, MaxLength } from "class-validator";
export class CreateOpcionDto {
@IsString()
@MaxLength(50)
opcion: string;
+4
View File
@@ -1,9 +1,13 @@
import { Module } from '@nestjs/common';
import { OpcionService } from './opcion.service';
import { OpcionController } from './opcion.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Opcion } from './entities/opcion.entity';
@Module({
imports: [TypeOrmModule.forFeature([Opcion])], // Importa el repositorio de Opcion
controllers: [OpcionController],
providers: [OpcionService],
exports: [OpcionService]
})
export class OpcionModule {}
+6 -2
View File
@@ -12,12 +12,16 @@ export class OpcionService {
private repository: Repository<Opcion>,
){}
create(createOpcionDto: CreateOpcionDto) {
return this.repository.save(createOpcionDto);
}
/*
create():Promise<Opcion> {
return this.repository.save(this.repository.create());
}
*/
findAll() {
return `This action returns all opcion`;
}
+19 -4
View File
@@ -1,6 +1,8 @@
import { CuestionarioRespondido } from "src/cuestionario_respondido/entities/cuestionario_respondido.entity";
import { Evento } from "src/evento/evento.entity";
import { ParticipanteEvento } from "src/participante_evento/participante_evento.entity";
import { TipoUser } from "src/tipo_user/tipo_user.entity";
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Participante {
@@ -16,19 +18,32 @@ export class Participante {
//Relacion con tipo usuario
@ManyToOne(() => TipoUser, tipoUser => tipoUser.participante)
@JoinColumn({ name: 'participante_id' }) //nombre de la relacion
tipo_user: TipoUser[]
tipo_user: TipoUser
/*
@ManyToOne(() => Administrador, (admin) => admin.eventos)
@JoinColumn({ name: "id_administrador" })
administrador: Administrador;
@OneToMany(() => ParticipanteEvento, (pe) => pe.evento)
participantes: ParticipanteEvento[];
@ManyToMany(() => Evento, evento => evento.participantes)
@JoinTable({
name: "participante_evento",
joinColumn: { name: "id_participante", referencedColumnName: "id_participante" },
inverseJoinColumn: { name: "id_evento", referencedColumnName: "id_evento" }
})
eventos: Evento[];
@OneToMany(() => Asistencia, (asistencia) => asistencia.evento)
asistencias: Asistencia[];
*/
@OneToMany(() => CuestionarioRespondido, cuestionario => cuestionario.id_participante)
cuestionariosRespondidos: CuestionarioRespondido[];
@OneToMany(() => ParticipanteEvento, participanteEvento => participanteEvento.participante)
participanteEventos: ParticipanteEvento[];
}
+3 -3
View File
@@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Participante } from './participante.entity';
import { Repository } from 'typeorm';
import { CreateParticipanteDto } from './dto/create-participante.dto';
import { UpdateAdminDto } from 'src/admin/dto/update.admin.dto';
//import { UpdateAdminDto } from 'src/admin/dto/update.admin.dto';
import { UpdateParticipanteDto } from './dto/update.participante.dto';
@Injectable()
@@ -28,7 +28,7 @@ export class ParticipanteService {
getParticipantes() {
return this.participanteRepository.find({
relations: ['tipo_user']
relations: ['tipo_user', 'participanteEventos']
})
}
@@ -37,7 +37,7 @@ export class ParticipanteService {
where: {
id_participante
},
relations: ['tipo_user']
relations: ['tipo_user', 'participanteEventos']
})
if (!participanteFound)
@@ -1,4 +1,5 @@
import { Evento } from "src/evento/evento.entity";
import { Participante } from "src/participante/participante.entity";
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
@Entity()
@@ -17,17 +18,21 @@ export class ParticipanteEvento {
/*
@OneToOne(() => Qr, (qr) => qr.participanteEvento)
qr: Qr;
@ManyToOne(() => Participante, (participante) => participante.eventos)
@JoinColumn({ name: "id_participante" })
participante: Participante;
@OneToMany(() => ParticipanteEvento, (pe) => pe.evento)
participantes: ParticipanteEvento[];
@ManyToOne(() => Evento, (evento) => evento.participantes)
@JoinColumn({ name: "id_evento" })
evento: Evento;
*/
@ManyToOne(() => Evento, (evento) => evento.participantes)
@ManyToOne(() => Participante, participante => participante.participanteEventos)
@JoinColumn({ name: "id_participante" })
participante: Participante;
@ManyToOne(() => Evento, evento => evento.participanteEventos)
@JoinColumn({ name: "id_evento" })
evento: Evento;
}
@@ -4,10 +4,12 @@ import { ParticipanteEventoController } from './participante_evento.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ParticipanteEvento } from './participante_evento.entity';
import { Evento } from 'src/evento/evento.entity';
import { Participante } from 'src/participante/participante.entity';
@Module({
imports: [TypeOrmModule.forFeature([ParticipanteEvento]), Evento],
imports: [TypeOrmModule.forFeature([ParticipanteEvento, Evento, Participante])],
controllers: [ParticipanteEventoController],
providers: [ParticipanteEventoService]
providers: [ParticipanteEventoService],
exports: [ParticipanteEventoService],
})
export class ParticipanteEventoModule {}
@@ -4,12 +4,16 @@ import { ParticipanteEvento } from './participante_evento.entity';
import { Repository } from 'typeorm';
import { CreateParticipanteEventoDto } from './dto/create-participante_evento.dto';
import { UpdateParticipanteEventoDto } from './dto/update.participante_evento.dto';
import { Evento } from 'src/evento/evento.entity';
import { Participante } from 'src/participante/participante.entity';
@Injectable()
export class ParticipanteEventoService {
constructor(
@InjectRepository(ParticipanteEvento) private participanteEventoRepository: Repository<ParticipanteEvento>
@InjectRepository(ParticipanteEvento) private participanteEventoRepository: Repository<ParticipanteEvento>,
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
@InjectRepository(Participante) private participanteRepository: Repository<Participante>
) {}
async createParticipanteEvento(participanteEvento: CreateParticipanteEventoDto) {
@@ -30,7 +34,7 @@ export class ParticipanteEventoService {
getParticipantesEvento() {
return this.participanteEventoRepository.find({
relations: ['evento']
relations: ['evento', 'participante']
})
}
@@ -39,7 +43,7 @@ export class ParticipanteEventoService {
where: {
id_participante
},
relations: ['evento']
relations: ['evento', 'participante']
})
if (!participante_eventoFound) {
@@ -13,11 +13,11 @@ export class PreguntaOpcion {
posicion: number;
@ManyToOne(() => Pregunta, pregunta => pregunta.id_pregunta)
@Column()
//@Column()
id_pregunta: Pregunta;
@ManyToOne(() => Opcion, opcion => opcion.id_opcion)
@Column()
//@Column()
id_opcion: Opcion;
@OneToMany(()=> RespuestaParticipanteCerrada, respuestaParticipanteCerrada=>respuestaParticipanteCerrada.id_pregunta_opcion)
@@ -0,0 +1,6 @@
import { Controller } from '@nestjs/common';
@Controller('tipo_pregunta')
export class TipoPreguntaController {
// Métodos del controlador
}
@@ -0,0 +1,6 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class TipoPreguntaService {
// Métodos del servicio
}