muchos cambios :'v

This commit is contained in:
jorgemike
2025-06-13 22:41:20 -06:00
parent 0dddfce887
commit d652f9f012
83 changed files with 3289 additions and 2261 deletions
+95 -52
View File
@@ -1,73 +1,116 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import {
HttpException,
HttpStatus,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Evento } from './evento.entity';
import { MoreThan, Repository } from 'typeorm';
import { Evento } from './entities/evento.entity';
import { CreateEventoDto } from './dto/create-evento.dto';
import { UpdateEventoDto } from './dto/update.evento.dto';
@Injectable()
export class EventoService {
constructor(
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
) {}
constructor(
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
) {}
async createEvento(evento: CreateEventoDto) {
const eventoFound = await this.eventoRepository.findOne({
where: {
nombre_evento: evento.nombre_evento,
tipo_evento: evento.tipo_evento
}
})
async createEvento(evento: CreateEventoDto) {
const eventoFound = await this.eventoRepository.findOne({
where: {
nombre_evento: evento.nombre_evento,
tipo_evento: evento.tipo_evento,
},
});
if (eventoFound)
return new HttpException('Evento already exists', HttpStatus.CONFLICT)
const createEvento = this.eventoRepository.create(evento)
if (eventoFound)
throw new HttpException(
'Ya existe un evento con el mismo nombre y tipo, puede agregar el periodo al nombre del evento para diferenciarlos',
HttpStatus.BAD_REQUEST,
);
return this.eventoRepository.save(createEvento)
const createEvento = this.eventoRepository.create(evento);
return this.eventoRepository.save(createEvento);
}
// evento.service.ts
async asociarBanner(id: number, filename: string) {
const evento = await this.getEventoOrFail(id);
evento.banner = filename;
return this.eventoRepository.save(evento);
}
getEventos() {
return this.eventoRepository.find();
}
async getCuestionariosEvento(id_evento: number) {
const evento = await this.eventoRepository.findOne({
where: { id_evento },
relations: ['cuestionarios'], // solo los cuestionarios, sin secciones
});
if (!evento) {
throw new NotFoundException(`Evento con ID ${id_evento} no encontrado.`);
}
getEventos() {
return this.eventoRepository.find({
relations: ['participantes']
})
return evento;
}
async getEvento(id_evento: number) {
return await this.eventoRepository.findOne({
where: {
id_evento,
},
});
}
async getEventoOrFail(id_evento: number): Promise<Evento> {
const eventoFound = await this.eventoRepository.findOne({
where: {
id_evento,
},
});
if (!eventoFound) {
throw new HttpException(
'El evento buscado no existe',
HttpStatus.NOT_FOUND,
);
}
async getEvento(id_evento: number) {
const eventoFound = await this.eventoRepository.findOne({
where: {
id_evento
},
relations: ['participantes']
})
return eventoFound;
}
if (!eventoFound)
return new HttpException('Evento not found', HttpStatus.NOT_FOUND);
async deleteEvento(id_evento: number) {
await this.getEventoOrFail(id_evento);
return eventoFound
const result = await this.eventoRepository.delete(id_evento);
if (result.affected === 0) {
throw new HttpException('Evento not found', HttpStatus.NOT_FOUND);
}
async deleteEvento(id_evento: number) {
const result = await this.eventoRepository.delete({ id_evento })
return { message: 'Evento eliminado exitosamente' };
}
if (result.affected === 0) {
return new HttpException('Evento not found', HttpStatus.NOT_FOUND);
}
async updateEvento(id_evento: number, evento: UpdateEventoDto) {
const eventoFound = await this.getEventoOrFail(id_evento);
return result
}
const updateEvento = Object.assign(eventoFound, evento);
return this.eventoRepository.save(updateEvento);
}
async updateEvento(id_evento: number, evento: UpdateEventoDto) {
const eventoFound = await this.eventoRepository.findOne({
where: {
id_evento
}
})
if (!eventoFound)
return new HttpException('Evento not found', HttpStatus.NOT_FOUND)
const updateEvento = Object.assign(eventoFound, evento)
return this.eventoRepository.save(updateEvento)
}
async getEventosActivos() {
const now = new Date();
return this.eventoRepository.find({
where: {
fecha_fin: MoreThan(now),
},
});
}
}