diff --git a/package-lock.json b/package-lock.json index 4e4a26b..cd34f6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@nestjs/mapped-types": "*", "@nestjs/passport": "^11.0.5", "@nestjs/platform-express": "^11.0.1", + "@nestjs/serve-static": "^5.0.3", "@nestjs/swagger": "^11.2.0", "@nestjs/typeorm": "^11.0.0", "@types/bcrypt": "^5.0.2", @@ -2540,6 +2541,33 @@ "tslib": "^2.1.0" } }, + "node_modules/@nestjs/serve-static": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/serve-static/-/serve-static-5.0.3.tgz", + "integrity": "sha512-0jFjTlSVSLrI+mot8lfm+h2laXtKzCvgsVStv9T1ZBZTDwS26gM5czIhIESmWAod0PfrbCDFiu9C1MglObL8VA==", + "license": "MIT", + "dependencies": { + "path-to-regexp": "8.2.0" + }, + "peerDependencies": { + "@fastify/static": "^8.0.4", + "@nestjs/common": "^11.0.2", + "@nestjs/core": "^11.0.2", + "express": "^5.0.1", + "fastify": "^5.2.1" + }, + "peerDependenciesMeta": { + "@fastify/static": { + "optional": true + }, + "express": { + "optional": true + }, + "fastify": { + "optional": true + } + } + }, "node_modules/@nestjs/swagger": { "version": "11.2.0", "resolved": "https://registry.npmjs.org/@nestjs/swagger/-/swagger-11.2.0.tgz", diff --git a/package.json b/package.json index 9d5c151..89f9c62 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@nestjs/mapped-types": "*", "@nestjs/passport": "^11.0.5", "@nestjs/platform-express": "^11.0.1", + "@nestjs/serve-static": "^5.0.3", "@nestjs/swagger": "^11.2.0", "@nestjs/typeorm": "^11.0.0", "@types/bcrypt": "^5.0.2", diff --git a/src/app.module.ts b/src/app.module.ts index 7496496..070febc 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -31,7 +31,6 @@ import { AlumnosModule } from './alumnos/alumnos.module'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true }), - TypeOrmModule.forRootAsync({ imports: [ConfigModule], useFactory: createMainDbConfig, diff --git a/src/cuestionario/cuestionario.controller.ts b/src/cuestionario/cuestionario.controller.ts index a88662a..c7e5314 100644 --- a/src/cuestionario/cuestionario.controller.ts +++ b/src/cuestionario/cuestionario.controller.ts @@ -46,7 +46,7 @@ export class CuestionarioController { @UseInterceptors( FileInterceptor('banner', { storage: diskStorage({ - destination: './public/banners', // Asegúrate de que esta carpeta exista + destination: './uploads/banners', // Asegúrate de que esta carpeta exista filename: (req, file, cb) => { const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9); diff --git a/src/cuestionario/docs/cuestionario.documentation.ts b/src/cuestionario/docs/cuestionario.documentation.ts index cf8884f..b4a8550 100644 --- a/src/cuestionario/docs/cuestionario.documentation.ts +++ b/src/cuestionario/docs/cuestionario.documentation.ts @@ -6,7 +6,7 @@ import { ApiTags, getSchemaPath, } from '@nestjs/swagger'; -import { feriaSexualidad } from '../../../utils/crear_formulario_feria'; +/* import { feriaSexualidad } from '../../../utils/crear_formulario_feria'; */ import { applyDecorators } from '@nestjs/common'; import { FormularioDto } from '../dto/formulario.schema'; import { @@ -47,7 +47,7 @@ export class CuestionarioApiDocumentation { type: 'number', example: 1, }), - ApiResponse({ +/* ApiResponse({ status: 200, description: 'Formulario completo con todas sus secciones, preguntas y opciones. Las preguntas incluyen el atributo "validacion" si tienen reglas de validación específicas (como "correo", "cuenta_alumno", "telefono", "nombre", etc.)', @@ -58,7 +58,7 @@ export class CuestionarioApiDocumentation { example: feriaSexualidad, }, }, - }), + }), */ ApiResponse({ status: 404, description: 'Cuestionario no encontrado' }), ); diff --git a/src/db/typeorm.config.ts b/src/db/typeorm.config.ts index 7bef1a2..e893aa4 100644 --- a/src/db/typeorm.config.ts +++ b/src/db/typeorm.config.ts @@ -16,7 +16,7 @@ export const createMainDbConfig = async ( synchronize: true, retryAttempts: 5, retryDelay: 3000, - dropSchema: true, + dropSchema: false, }); export const createAlumnosDbConfig = async ( diff --git a/src/evento/evento.controller.ts b/src/evento/evento.controller.ts index 3592062..60cdb66 100644 --- a/src/evento/evento.controller.ts +++ b/src/evento/evento.controller.ts @@ -49,7 +49,7 @@ export class EventoController { @UseInterceptors( FileInterceptor('banner', { storage: diskStorage({ - destination: './public/banners', // Asegúrate de que esta carpeta exista + destination: './uploads/banners', // Asegúrate de que esta carpeta exista filename: (req, file, cb) => { const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9); diff --git a/src/main.ts b/src/main.ts index 1e616e4..528f3a9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,11 @@ import { AppModule } from './app.module'; import { ValidationPipe } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; +import { NestExpressApplication } from '@nestjs/platform-express'; +import { join } from 'path'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule); const configService = app.get(ConfigService); // Configuración de validación global @@ -17,6 +19,11 @@ async function bootstrap() { }), ); + app.useStaticAssets(join(__dirname, '..', 'uploads'), { + index: false, + prefix: '/', + }); + // CORS configuration app.enableCors({ origin: '*', diff --git a/uploads/banners/banner-1750103174963-705371719.jpeg b/uploads/banners/banner-1750103174963-705371719.jpeg new file mode 100644 index 0000000..b99380a Binary files /dev/null and b/uploads/banners/banner-1750103174963-705371719.jpeg differ diff --git a/uploads/banners/banner-1750103308438-995542211.jpeg b/uploads/banners/banner-1750103308438-995542211.jpeg new file mode 100644 index 0000000..b99380a Binary files /dev/null and b/uploads/banners/banner-1750103308438-995542211.jpeg differ diff --git a/utils/crear_formulario_feria.ts b/utils/crear_formulario_feria.ts deleted file mode 100644 index 0b2d77d..0000000 --- a/utils/crear_formulario_feria.ts +++ /dev/null @@ -1,68 +0,0 @@ -export const feriaSexualidad = { - nombre_form: 'Registro para la Feria de la Sexualidad - FES Acatlán', - descripcion: - 'La Feria de la Sexualidad es un espacio seguro e informativo dirigido a toda la comunidad universitaria. Este registro nos ayudará a organizar mejor las actividades, talleres y charlas, así como conocer tus intereses. Por favor, completa el siguiente formulario para confirmar tu participación.', - fecha_inicio: '2025-03-07T00:00:01', - fecha_fin: '2025-03-18T23:59:59', - id_tipo_cuestionario: 1, - evento: 'Feria de la Sexualidad', - secciones: [ - { - titulo: 'Información Personal', - descripcion: - 'Proporciona tus datos personales para poder contactarte y enviarte información relevante sobre la Feria de la Sexualidad.', - preguntas: [ - { - titulo: '¿Eres parte de la comunidad de la FES Acatlán?', - tipo: 'Cerrada', - opciones: [{ valor: 'Si' }, { valor: 'No' }], - obligatoria: true, - }, - { - titulo: 'Correo electrónico', - obligatoria: true, - tipo: 'Abierta', - limite: 250, - validacion: 'correo', - }, - { - titulo: 'Numero de cuenta', - obligatoria: true, - tipo: 'Abierta', - limite: 250, - validacion: 'cuenta_alumno', - }, - { - titulo: 'Nombre(s)', - obligatoria: true, - tipo: 'Abierta', - limite: 250, - validacion: 'nombre', - }, - { - titulo: 'Apellidos', - obligatoria: true, - tipo: 'Abierta', - limite: 250, - validacion: 'nombre', - }, - { - titulo: 'Género', - obligatoria: true, - tipo: 'Cerrada', - opciones: [ - { valor: 'Masculino' }, - { valor: 'Femenino' }, - { valor: 'Prefiero no decirlo' }, - ], - }, - { - titulo: 'Institución de procedencia', - tipo: 'Abierta', - obligatoria: true, - limite: 250, - }, - ], - }, - ], - }; \ No newline at end of file diff --git a/utils/get_formulario_feria.ts b/utils/get_formulario_feria.ts deleted file mode 100644 index e84abf2..0000000 --- a/utils/get_formulario_feria.ts +++ /dev/null @@ -1,193 +0,0 @@ -export const cuestionario_feria = { - tipo_cuestionario: { - id_tipo_cuestionario: 1, - tipo_cuestionario: 'Encuesta', - }, - cuestionario: { - id_cuestionario: 10, - nombre_form: - 'Registro para la Feria de la Sexualidad - Comunidad FES Acatlán', - contador_secciones: 2, - descripcion: - 'La Feria de la Sexualidad es un espacio seguro e informativo dirigido a toda la comunidad universitaria. Este registro nos ayudará a organizar mejor las actividades, talleres y charlas, así como conocer tus intereses. Por favor, completa el siguiente formulario para confirmar tu participación.', - editable: true, - fecha_inicio: '2025-03-26T00:00:00', - fecha_fin: '2025-03-31T23:59:59', - id_cuestionario_original: null, - id_tipo_cuestionario: 1, - secciones: [ - { - id_cuestionario_seccion: 1, - posicion: 1, - seccion: { - id_seccion: 100, - contador_pregunta: 2, - descripcion: 'Preguntas generales', - titulo: 'General', - }, - preguntas: [ - { - id_seccion_pregunta: 1000, - posicion: 1, - pregunta: { - id_pregunta: 10000, - pregunta: '¿Cómo calificaría nuestro servicio?', - contador_opcion: 4, - obligatoria: true, - id_tipo_pregunta: 1, - tipo_pregunta: { - id_tipo: 1, - tipo_pregunta: 'Cerrada', - }, - opciones: [ - { - id_pregunta_opcion: 50000, - posicion: 1, - id_opcion: 90000, - opcion: { - id_opcion: 90000, - opcion: 'Excelente', - }, - }, - { - id_pregunta_opcion: 50001, - posicion: 2, - id_opcion: 90001, - opcion: { - id_opcion: 90001, - opcion: 'Bueno', - }, - }, - { - id_pregunta_opcion: 50002, - posicion: 3, - id_opcion: 90002, - opcion: { - id_opcion: 90002, - opcion: 'Regular', - }, - }, - { - id_pregunta_opcion: 50003, - posicion: 4, - id_opcion: 90003, - opcion: { - id_opcion: 90003, - opcion: 'Malo', - }, - }, - ], - }, - }, - { - id_seccion_pregunta: 1001, - posicion: 2, - pregunta: { - id_pregunta: 10001, - pregunta: '¿Recomendaría nuestro servicio?', - contador_opcion: 2, - obligatoria: true, - id_tipo_pregunta: 1, - tipo_pregunta: { - id_tipo: 1, - tipo_pregunta: 'Cerrada', - }, - opciones: [ - { - id_pregunta_opcion: 50004, - posicion: 1, - id_opcion: 90004, - opcion: { - id_opcion: 90004, - opcion: 'Sí', - }, - }, - { - id_pregunta_opcion: 50005, - posicion: 2, - id_opcion: 90005, - opcion: { - id_opcion: 90005, - opcion: 'No', - }, - }, - ], - }, - }, - ], - }, - { - id_cuestionario_seccion: 2, - posicion: 2, - seccion: { - id_seccion: 101, - contador_pregunta: 1, - descripcion: 'Preguntas adicionales para conocer más detalles', - titulo: 'Adicionales', - }, - preguntas: [ - { - id_seccion_pregunta: 1002, - posicion: 1, - pregunta: { - id_pregunta: 10002, - pregunta: '¿Qué mejorarías en nuestro servicio?', - contador_opcion: 0, - obligatoria: false, - id_tipo_pregunta: 2, - tipo_pregunta: { - id_tipo: 2, - tipo_pregunta: 'Abierta', - }, - opciones: [], - }, - }, - { - id_seccion_pregunta: 1003, - posicion: 3, - pregunta: { - id_pregunta: 10003, - pregunta: '¿Qué aspectos del servicio fueron de tu agrado?', - contador_opcion: 3, - obligatoria: false, - id_tipo_pregunta: 3, // Puedes usar este ID para distinguir múltiples - tipo_pregunta: { - id_tipo: 3, - tipo_pregunta: 'Multiple', - }, - opciones: [ - { - id_pregunta_opcion: 50006, - posicion: 1, - id_opcion: 90006, - opcion: { - id_opcion: 90006, - opcion: 'Rapidez', - }, - }, - { - id_pregunta_opcion: 50007, - posicion: 2, - id_opcion: 90007, - opcion: { - id_opcion: 90007, - opcion: 'Atención al cliente', - }, - }, - { - id_pregunta_opcion: 50008, - posicion: 3, - id_opcion: 90008, - opcion: { - id_opcion: 90008, - opcion: 'Facilidad de uso', - }, - }, - ], - }, - }, - ], - }, - ], - }, - }; \ No newline at end of file diff --git a/utils/load-form.js b/utils/load-form.js deleted file mode 100644 index 9489b53..0000000 --- a/utils/load-form.js +++ /dev/null @@ -1,46 +0,0 @@ -// Script para cargar un formulario desde un archivo JSON - -const axios = require('axios'); -const fs = require('fs'); -const path = require('path'); - -const API_URL = 'http://localhost:4200'; - -async function loadFormFromFile(filePath) { - try { - // Leer el archivo JSON - const formData = require(filePath); - - console.log('Enviando datos del formulario al servidor...'); - console.log('Datos:', JSON.stringify(formData, null, 2)); - - // Enviar los datos al endpoint - const response = await axios.post(`${API_URL}/cuestionario`, formData); - - console.log('Formulario creado exitosamente:'); - console.log(JSON.stringify(response.data, null, 2)); - - return response.data; - } catch (error) { - console.error('Error al crear el formulario:'); - if (error.response) { - console.error('Status:', error.response.status); - console.error('Data:', JSON.stringify(error.response.data, null, 2)); - } else { - console.error(error.message); - } - throw error; - } -} - -// Verificar si se proporcionó un argumento de archivo -const args = process.argv.slice(2); -const filePath = args[0] || './crear_formulario_feria'; - -// Ejecutar la función -loadFormFromFile(filePath) - .then(() => console.log('Proceso completado')) - .catch(() => { - console.log('Proceso fallido'); - process.exit(1); - }); \ No newline at end of file diff --git a/utils/mandar_formulario.json b/utils/mandar_formulario.json deleted file mode 100644 index e69de29..0000000 diff --git a/utils/respuesta_1.json b/utils/respuesta_1.json deleted file mode 100644 index e69de29..0000000 diff --git a/utils/respuesta_2.json b/utils/respuesta_2.json deleted file mode 100644 index e69de29..0000000 diff --git a/utils/respuesta_formulario_feria.ts b/utils/respuesta_formulario_feria.ts deleted file mode 100644 index 0a2b5fe..0000000 --- a/utils/respuesta_formulario_feria.ts +++ /dev/null @@ -1,21 +0,0 @@ -const comunidad = { - id_formulario: 1, - respuestas: [ - { id_pregunta: 101, valor: 'Si' }, // ¿Eres parte de la comunidad de la FES Acatlán? - { id_pregunta: 102, valor: '123456789' }, // Numero de cuenta - { id_pregunta: 106, valor: 'Prefiero no decirlo' }, - ], - fecha_envio: '2025-04-02T13:45:00', - }; - - const externos = { - id_formulario: 1, - respuestas: [ - { id_pregunta: 101, valor: 'No' }, // ¿Eres parte de la comunidad de la FES Acatlán? - { id_pregunta: 103, valor: 'Juan Carlos' }, // Nombre(s) - { id_pregunta: 104, valor: 'Ramírez López' }, // Apellidos - { id_pregunta: 106, valor: 'Prefiero no decirlo' }, // genero - { id_pregunta: 107, valor: 'UAM Azcapotzalco' }, // Institución de procedencia - ], - fecha_envio: '2025-04-02T13:45:00', - }; \ No newline at end of file diff --git a/utils/test-crear-formulario.ts b/utils/test-crear-formulario.ts deleted file mode 100644 index 62b9ada..0000000 --- a/utils/test-crear-formulario.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { feriaSexualidad } from './crear_formulario_feria'; -import axios from 'axios'; - -// Asumiendo que el servidor está corriendo en localhost:4200 -const API_URL = 'http://localhost:4200'; - -async function crearFormulario() { - try { - const response = await axios.post(`${API_URL}/cuestionario`, feriaSexualidad); - console.log('Formulario creado exitosamente:'); - console.log(JSON.stringify(response.data, null, 2)); - return response.data; - } catch (error) { - console.error('Error al crear el formulario:'); - if (error.response) { - console.error('Status:', error.response.status); - console.error('Data:', error.response.data); - } else { - console.error(error.message); - } - throw error; - } -} - -// Ejecutar la función -crearFormulario() - .then(() => console.log('Proceso completado')) - .catch(() => console.log('Proceso fallido')); \ No newline at end of file