diff --git a/.env b/.env index d989a38..c8879e3 100644 --- a/.env +++ b/.env @@ -1,16 +1,16 @@ PORT=5089 - DB_HOST=132.248.180.82 - DB_USER=user_cedetec - DB_PASSWORD=c3t3d3c - DB_NAME=Betelgeuse_Cedetec_Prueba - DB_PORT= +# DB_HOST=132.248.180.82 +# DB_USER=user_cedetec +# DB_PASSWORD=c3t3d3c +# DB_NAME=Betelgeuse_Cedetec_Prueba +# DB_PORT= -# DB_HOST=localhost -# DB_USER=root -# DB_PASSWORD=Dosmiluno2001 -# DB_NAME=cedetec_proyectos -# DB_PORT=3306 + DB_HOST=localhost + DB_USER=root + DB_PASSWORD=Dosmiluno2001 + DB_NAME=cedetec_proyectos + DB_PORT=3306 DB_HOST_DSC = 132.248.180.82 DB_USER_DSC = sites_user diff --git a/public/1366_2000.jpg b/public/1366_2000.jpg deleted file mode 100644 index 0dde5ef..0000000 Binary files a/public/1366_2000.jpg and /dev/null differ diff --git a/public/cedetec_1.webp b/public/cedetec_1.webp deleted file mode 100644 index 227a9f6..0000000 Binary files a/public/cedetec_1.webp and /dev/null differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e69de29 diff --git a/src/app.module.ts b/src/app.module.ts index 2ca6c5c..e89639a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -53,6 +53,10 @@ import { join } from 'path'; @Module({ imports: [ + ServeStaticModule.forRoot({ + rootPath: join(__dirname, '..', 'public'), + exclude: ['/api*'], // Excluir la ruta "/api" de servir archivos estáticos + }), ConfigModule.forRoot({ envFilePath: '.env', isGlobal: true, diff --git a/src/carousel/carousel.controller.ts b/src/carousel/carousel.controller.ts index ce22973..3f670d0 100644 --- a/src/carousel/carousel.controller.ts +++ b/src/carousel/carousel.controller.ts @@ -1,4 +1,5 @@ import { + BadRequestException, Controller, Delete, Get, @@ -26,13 +27,40 @@ export class CarouselController { storage: diskStorage({ destination: './public', filename: function (req, file, cb) { - cb(null, file.originalname); + const directory = './public'; + const filePath = `${directory}/${file.originalname}`; + if (fs.existsSync(filePath)) { + cb( + new BadRequestException( + `Ya existe un archivo con el nombre: '${file.originalname}'. Si está seguro de que no es el mismo, cambie el nombre del archivo.`, + ), + null, + ); + } else { + cb(null, file.originalname); + } }, }), + fileFilter: function (req, file, cb) { + const filetypes = /jpeg|jpg|webp|png/; + const extname = filetypes.test( + path.extname(file.originalname).toLowerCase(), + ); + const mimetype = filetypes.test(file.mimetype); + if (mimetype && extname) { + return cb(null, true); + } + cb( + new BadRequestException( + 'Lo sentimos, para mejorar la calidad de las imagenes en el carousel solo se aceptan imagenes con terminación: .jpeg .jpg .png .webp', + ), + false, + ); + }, }), ) async addImage(@UploadedFile() file) { - return {msg: 'Imagen guardada con exito :)'} + return { msg: 'Imagen guardada con exito :)' }; } @Delete('/imagenes/:nombreArchivo') @@ -48,12 +76,16 @@ export class CarouselController { @Get('/imagenes') async getImages(@Res() res: Response) { // Leer el directorio 'public' para obtener el nombre de todos los archivos + const fileNames = await fs.promises.readdir('./public'); // Generar la URL para cada archivo y agregarla a un arreglo - const baseUrl = 'http://localhost:5089'; // reemplaza con la URL de tu servidor - const imageUrls = fileNames.map( - (fileName) => `${baseUrl}/public/${fileName}`, + + // Filtrar solo las imágenes con las terminaciones "jpg", "webp" y "png" + const imageNames = fileNames.filter((fileName) => + ['.jpg', '.webp', '.png'].includes(path.extname(fileName)), ); + + const imageUrls = imageNames.map((imageName) => `public/${imageName}`); // Devolver el arreglo de URLs como respuesta return res.json(imageUrls); } diff --git a/src/carousel/carousel.service.ts b/src/carousel/carousel.service.ts index b7c996a..a6c6fbb 100644 --- a/src/carousel/carousel.service.ts +++ b/src/carousel/carousel.service.ts @@ -4,6 +4,6 @@ import { Injectable } from '@nestjs/common'; export class CarouselService { uploadImage(file){ - console.log(file) + /* console.log(file) */ } } diff --git a/src/email/email.controller.ts b/src/email/email.controller.ts index 78b49b0..d958447 100644 --- a/src/email/email.controller.ts +++ b/src/email/email.controller.ts @@ -35,7 +35,7 @@ export class EmailController { if(!file) { throw new HttpException("No se ha cargado ningun archivo", HttpStatus.BAD_REQUEST) } - console.log(file) + /* console.log(file) */ return this.emailService.sendConstancias(file, nombreEvento); } } diff --git a/src/email/email.service.ts b/src/email/email.service.ts index e2363d9..3ec96e4 100644 --- a/src/email/email.service.ts +++ b/src/email/email.service.ts @@ -58,7 +58,7 @@ export class EmailService { } async sendConstancias(file, nombreEvento) { - console.log(file) + /* console.log(file) */ const workbook = xlsx.read(file.buffer); const worksheet = workbook.Sheets[workbook.SheetNames[0]]; const data = xlsx.utils.sheet_to_json(worksheet); @@ -68,22 +68,6 @@ export class EmailService { const page = pdfDoc.addPage(); page.setSize(792, 612); - page.drawRectangle({ - x: 0, - y: page.getHeight() - 60, - width: page.getWidth(), - height: 60, - color: rgb(0 / 255, 61 / 255, 121 / 255), - }); - - page.drawRectangle({ - x: 0, - y: 0, - width: page.getWidth(), - height: 60, - color: rgb(213 / 255, 159 / 255, 15 / 255), - }); - const font = await pdfDoc.embedFont(StandardFonts.HelveticaBold); const fontSize = 30; const text = 'Constancia de asistencia'; @@ -126,8 +110,8 @@ export class EmailService { const url = URL.createObjectURL(blob); */ this.transporter.sendMail({ to: row.Email, - subject: 'Constancia de asistencia', - text: 'Hola', + subject: `Constancia de asistencia a "${nombreEvento}"`, + text: `¡Un saludo ${row.Nombre}! Aquí está tu constancia de asistencia por el evento "${nombreEvento}". Agradecemos tu asistencia y constancia, esperamos seguir viéndote en eventos futuros.`, attachments: [attachment], }); } diff --git a/src/evento-participante/evento-participante/evento-participante.service.ts b/src/evento-participante/evento-participante/evento-participante.service.ts index 327d555..c6be9a1 100644 --- a/src/evento-participante/evento-participante/evento-participante.service.ts +++ b/src/evento-participante/evento-participante/evento-participante.service.ts @@ -46,12 +46,25 @@ export class EventoParticipanteService { id_evento: number, registrarParticipanteDto: RegistrarParticipanteDto, ) { -/* console.log(id_evento); - console.log(registrarParticipanteDto); */ return this.participanteExiste(registrarParticipanteDto.email).then( (res) => { if (res) { - this.registrarEnEvento(id_evento, res); + + res.nombre = registrarParticipanteDto.nombre; + res.apellido_paterno = registrarParticipanteDto.apellido_paterno; + res.apellido_materno = registrarParticipanteDto.apellido_materno; + res.carrera = registrarParticipanteDto.carrera; + res.institucion_procedencia = + registrarParticipanteDto.institucion_procedencia; + +//si el correo ya existe en la base de datos solo se le cambia el nombre, apellidos, carrera e institucion + + return this.participanteRepository + .save(res) + .then((participanteActualizado) => { + this.registrarEnEvento(id_evento, participanteActualizado); + return participanteActualizado; + }); } else { this.participanteRepository .save(this.participanteRepository.create(registrarParticipanteDto)) diff --git a/src/eventos/eventos.service.ts b/src/eventos/eventos.service.ts index dd41556..e322a52 100644 --- a/src/eventos/eventos.service.ts +++ b/src/eventos/eventos.service.ts @@ -162,7 +162,7 @@ export class EventosService { }); }); - console.log(workbook.description); + /* console.log(workbook.description); */ // Generar el archivo Excel y guardarlo en el servidor const fileName = `participantes-${idEvento}.xlsx`; @@ -190,7 +190,7 @@ export class EventosService { geteventosDisponiblesMasDosDias(){ const hoy = new Date(); return this.eventoRepository.createQueryBuilder("evento") - .where(`DATE_ADD(evento.fecha_fin, INTERVAL 2 DAY) >= :hoy`, { hoy }) + .where(`DATE_ADD(evento.fecha_fin, INTERVAL 3 DAY) >= :hoy`, { hoy }) .andWhere('fecha_fin <= :hoy', {hoy}) .getMany(); }