Mandar modificaciones a produccion

This commit is contained in:
santiago
2025-09-12 20:09:28 -06:00
20 changed files with 2496 additions and 1679 deletions
+16 -1
View File
@@ -12,4 +12,19 @@ DB_NAME_DSC=
NODEMAILER_SERVICE=
NODEMAILER_USER=
NODEMAILER_PASWORD=
NODEMAILER_PASWORD=
#132.248.180.82
#3306
#usr_tl
#A1m_p@$
#Betelgeuse_TL_test
HOST_TYL=132.248.180.82
PORT_TYL=3306
USUARIO_TYL=usr_tl
CONTRASENA_TYL=A1m_p@$
DATABASE_TYL=Betelgeuse_TL_test
#Funciones para la api
API_URL=
TOKEN=
+2211 -1661
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -35,10 +35,10 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"date-fns": "^2.30.0",
"exceljs": "^4.3.0",
"exceljs": "^4.4.0",
"moment": "^2.29.4",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.1.2",
"mysql2": "^3.14.3",
"nodemailer": "^6.9.1",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
@@ -0,0 +1,18 @@
import { Controller, Post, Get, Body } from '@nestjs/common';
import { AlmacenamientoService } from './almacenamiento.service';
@Controller('almacenamiento')
export class AlmacenamientoController {
constructor(private readonly almacenamientoService: AlmacenamientoService) {}
@Post()
async create(@Body() body: { correo: string; agree: boolean }) {
return this.almacenamientoService.create(body.correo);
}
@Get()
async findAll() {
const data = await this.almacenamientoService.findAll();
return { message: 'GET endpoint reached', data };
}
}
@@ -0,0 +1,32 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Almacenamiento } from './entity/almacenamiento.entity';
import { AlmacenamientoService } from './almacenamiento.service';
import { AlmacenamientoController } from './almacenamiento.controller';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
TypeOrmModule.forRootAsync({
name: 'almacenamiento',
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
name: 'almacenamiento',
type: 'mariadb',
host: configService.get('HOST_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: true,
ssl: false, // <- importante
}),
}),
TypeOrmModule.forFeature([Almacenamiento], 'almacenamiento'),
],
providers: [AlmacenamientoService],
controllers: [AlmacenamientoController],
})
export class AlmacenamientoModule {}
@@ -0,0 +1,33 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Almacenamiento } from './entity/almacenamiento.entity';
@Injectable()
export class AlmacenamientoService {
constructor(
@InjectRepository(Almacenamiento, 'almacenamiento')
private readonly almacenamientoRepository: Repository<Almacenamiento>,
) {}
// Example method to create a new record
async create(correo: string): Promise<any> {
console.log(correo)
const existente = await this.almacenamientoRepository.findOne({ where:{correo} });
console.log(existente)
if (!existente) {
// Maneja el error aquí mismo
throw new HttpException(
{ error: 'Este usuario no tiene acceso' },
HttpStatus.NOT_FOUND
);
}
return { mensaje: 'Usuario verificado correctamente' };
}
// Example method to get all records
async findAll(): Promise<Almacenamiento[]> {
return this.almacenamientoRepository.find();
}
}
@@ -0,0 +1,16 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity('almacenamiento')
export class Almacenamiento {
@PrimaryGeneratedColumn({ type: 'int', name: 'id_almacenamiento' })
idAlmacenamiento: number;
@Column('varchar', { name: 'correo', length: 100 })
correo: string;
@Column('timestamp', {
name: 'fecha_ampliacion',
})
fechaConsulta: Date;
}
+5 -3
View File
@@ -49,9 +49,11 @@ import { MulterModule } from '@nestjs/platform-express';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { CarruselModule } from './carrusel/carrusel.module';
import { Carrusel } from './entities/carrusel.entity';
import { Carrusel } from './carrusel/entity/carrusel.entity';
import { ComentariosModule } from './comentarios/comentarios.module';
import { Comentarios } from './comentarios/entity/comentarios.entity';
import { AlmacenamientoModule } from './almacenamiento/almacenamiento.module';
import { Almacenamiento } from './almacenamiento/entity/almacenamiento.entity';
@Module({
imports: [
@@ -73,6 +75,7 @@ import { Comentarios } from './comentarios/entity/comentarios.entity';
username: configService.get('DB_USER'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
synchronize: true,
entities: [
Evento,
Participante,
@@ -100,7 +103,6 @@ import { Comentarios } from './comentarios/entity/comentarios.entity';
/* No recuerdo porque empece a ponerle fechas */
Comentarios,
],
synchronize: true,
}),
}),
EventosModule,
@@ -127,10 +129,10 @@ import { Comentarios } from './comentarios/entity/comentarios.entity';
}),
CarruselModule,
ComentariosModule,
AlmacenamientoModule,
],
controllers: [
AppController,
ParticipanteController,
InscripcionStatusController,
],
providers: [AppService, InscripcionStatusService],
+8 -1
View File
@@ -1,15 +1,17 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Param, Post } from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginMiembroDto } from './dto/loginMiembro.dto';
import { RegistrarMiembroDto } from './dto/registrarMiembro.dto';
import { ApiTags } from '@nestjs/swagger';
import { ApiPostRegistro } from './auth.docs';
import { jwtStrategy } from './jwt.strategy';
@Controller('auth')
@ApiTags('auth')
export class AuthController {
constructor(
private authService: AuthService,
private authValidar: jwtStrategy,
) /* @InjectRepository(Usuario) private usuarioRepository: Repository<Usuario> */ {}
@Post('registro')
@@ -22,4 +24,9 @@ export class AuthController {
login(@Body() LoginUsuario: LoginMiembroDto) {
return this.authService.login(LoginUsuario);
}
@Post('validate')
validar(@Param() token: any) {
return this.authValidar.validate
}
}
+5
View File
@@ -57,4 +57,9 @@ export class CarruselController {
getAllImagenes() {
return this.carruselService.getAllImages();
}
@Delete('deleteAll')
deleteAllCarrusel() {
return this.carruselService.deleteAllCarrusel();
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
import { CarruselController } from './carrusel.controller';
import { CarruselService } from './carrusel.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Carrusel } from 'src/entities/carrusel.entity';
import { Carrusel } from 'src/carrusel/entity/carrusel.entity';
@Module({
imports: [TypeOrmModule.forFeature([Carrusel])],
+49 -3
View File
@@ -1,10 +1,14 @@
import { BadRequestException, Injectable, InternalServerErrorException } from '@nestjs/common';
import {
BadRequestException,
Injectable,
InternalServerErrorException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Carrusel } from 'src/entities/carrusel.entity';
import { Carrusel } from 'src/carrusel/entity/carrusel.entity';
import { Repository } from 'typeorm';
import { carruselDto } from './dto/carruselDto.dto';
import * as fs from 'fs';
import { Response } from 'express';
import * as path from 'path';
@Injectable()
export class CarruselService {
@@ -74,4 +78,46 @@ export class CarruselService {
getAllImages(): Promise<Carrusel[]> {
return this.carruselRepository.find();
}
async deleteAllCarrusel(): Promise<{ message: string }> {
try {
// Obtener todas las imágenes del carrusel
const images = await this.carruselRepository.find();
// Eliminar archivos físicos de la carpeta public/carrusel
const carruselDir = './public/carrusel';
if (fs.existsSync(carruselDir)) {
// Leer todos los archivos en el directorio
const files = await fs.promises.readdir(carruselDir);
// Eliminar cada archivo
for (const file of files) {
const filePath = path.join(carruselDir, file);
try {
await fs.promises.unlink(filePath);
console.log(`✅ Archivo eliminado: ${filePath}`);
} catch (fileError) {
console.warn(
`⚠️ No se pudo eliminar el archivo: ${filePath}`,
fileError.message,
);
}
}
}
// Eliminar todos los registros de la base de datos
await this.carruselRepository.delete({});
return {
message: `Carrusel limpiado exitosamente. Se eliminaron ${images.length} imágenes y registros.`,
};
} catch (error) {
console.error('❌ Error al limpiar el carrusel:', error);
throw new InternalServerErrorException({
message: 'Ocurrió un error inesperado al limpiar el carrusel',
error: error.message,
});
}
}
}
+15 -1
View File
@@ -1,6 +1,7 @@
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
@@ -20,7 +21,7 @@ import { AuthGuard } from '@nestjs/passport';
@Controller('email')
export class EmailController {
constructor(private readonly emailService: EmailService) {}
constructor(private readonly emailService: EmailService) { }
@UseGuards(AuthGuard('jwt'))
@Post('/evento/:id')
@@ -48,4 +49,17 @@ export class EmailController {
}
return this.emailService.sendConstancias(file, id, res);
}
//@UseGuards(AuthGuard('jwt'))
@Get(':id/participantes/xlsx')
async descargarExcel(
@Param('id') idEvento: number,
@Res() res: Response,
) {
console.log('entro en el controller')
return this.emailService.getParticipantesExcel(idEvento, res);
}
}
+60
View File
@@ -22,6 +22,7 @@ import * as path from 'path';
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
import { Response } from 'express';
import { format } from 'date-fns';
import * as ExcelJS from 'exceljs';
@Injectable()
export class EmailService {
@@ -67,6 +68,64 @@ export class EmailService {
return participantes;
}
async getParticipantesExcel(idEvento: number, res: Response) {
console.log('entro a la funcion')
const participantes = await this.participanteRepository
.createQueryBuilder('participante')
.innerJoin('participante.eventosParticipante', 'eventoParticipante')
.innerJoin('eventoParticipante.evento', 'evento')
.where('evento.id_evento = :idEvento', { idEvento })
.select(['participante'])
.getMany();
// 1. Crear workbook y worksheet
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Participantes');
// 2. Definir encabezados
worksheet.columns = [
{ header: 'ID', key: 'id', width: 10 },
{ header: 'Nombre', key: 'nombre', width: 30 },
{ header: 'Correo', key: 'correo', width: 30 },
{ header: 'Teléfono', key: 'telefono', width: 20 },
{ header: 'Carrera', key: 'carrera', width: 20 },
{ header: 'Institución', key: 'institucion_procedencia', width: 30 },
{ header: 'Apellido Paterno', key: 'apellido_paterno', width: 20 },
{ header: 'Apellido Materno', key: 'apellido_materno', width: 20 },
];
console.log(participantes);
// 3. Insertar datos
participantes.forEach((p) => {
worksheet.addRow({
nombre: p.nombre,
apellido_paterno: p.apellido_paterno,
apellido_materno: p.apellido_materno,
carrera: p.carrera,
institucion_procedencia: p.institucion_procedencia,
correo: p.email,
telefono: p.telefono,
});
});
// 4. Preparar la respuesta HTTP para enviar el Excel
res.setHeader(
'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
);
res.setHeader(
'Content-Disposition',
'attachment; filename=participantes.xlsx',
);
await workbook.xlsx.write(res);
res.end();
}
async sendConstancias(file, id_evento, res: Response) {
//traemos la info del evento
const evento = await this.eventoService.getEventosPorId(id_evento);
@@ -172,6 +231,7 @@ export class EmailService {
return res.status(200).json({ message: 'Constancias enviadas con éxito' });
}
formatoFecha(fecha: Date) {
const fechaLimpia = format(fecha, 'dd/MM/yyyy');
return fechaLimpia;
@@ -1,4 +1,4 @@
import { Body, Controller, Param, ParseIntPipe, Post } from '@nestjs/common';
import { Body, Controller, Get, Param, ParseIntPipe, Post } from '@nestjs/common';
import { RegistrarParticipanteDto } from './dto/registrarParticipanteDto.dto';
import { EventoParticipanteService } from './evento-participante.service';
import { EventoParticipante } from './eventoParticipante.entity';
@@ -12,5 +12,8 @@ export class EventoParticipanteController {
return this.eventoParticipanteService.registrarParticipante(id, datos)
}
@Get()
getEventoParticipante(): Promise<EventoParticipante[]> {
return this.eventoParticipanteService.getEventoParticipantes();
}
}
@@ -75,4 +75,8 @@ export class EventoParticipanteService {
},
);
}
getEventoParticipantes() {
return this.eventoParticipanteRepository.find()
}
}
+2 -2
View File
@@ -32,7 +32,7 @@ export class EventosController {
@UseGuards(AuthGuard('jwt'))
@Post()
postEvento(@Body() nuevoEvento: crearEventoDto){
return this.eventoService.postEvento(nuevoEvento)
return this.eventoService.postEvento(nuevoEvento)
}
@UseGuards(AuthGuard('jwt'))
@@ -44,7 +44,7 @@ export class EventosController {
@UseGuards(AuthGuard('jwt'))
@Delete(':id')
deleteEvento(@Param('id', ParseIntPipe)id: number){
return this.eventoService.deleteEventoParticipante(id)
return this.eventoService.deleteEventoParticipante(id)
}
@Get(':id/cupos')
+10 -2
View File
@@ -1,5 +1,13 @@
import { Controller, Post } from '@nestjs/common';
import { Controller, Get, Post } from '@nestjs/common';
import { ParticipanteService } from './participante.service';
import { Participante } from './participante.entity';
@Controller('participante')
export class ParticipanteController {}
export class ParticipanteController {
constructor(private participanteService: ParticipanteService) {}
@Get()
getParticipantes(): Promise<Participante[]> {
return this.participanteService.getParticipantes();
}
}
+4
View File
@@ -31,4 +31,8 @@ export class ParticipanteService {
},
);
}
getParticipantes() {
return this.participanteRepository.find();
}
}