import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import 'dotenv/config'; import { DocsModule } from './docs/docs.module'; import { DataSource } from 'typeorm'; import { TipoPregunta } from './tipo_pregunta/entities/tipo_pregunta.entity'; import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); // Configuración de validación global app.useGlobalPipes( new ValidationPipe({ whitelist: true, // Elimina propiedades no decoradas forbidNonWhitelisted: true, // Arroja error si hay propiedades no decoradas transform: true, // Transforma los datos recibidos al tipo definido en el DTO }) ); // CORS configuration app.enableCors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], allowedHeaders: ['Content-Type', 'Authorization'], }); // Swagger setup DocsModule.setupSwagger(app); // Seed TipoPregunta data const dataSource = app.get(DataSource); const tiposPreguntaRepository = dataSource.getRepository(TipoPregunta); // Check if data exists const count = await tiposPreguntaRepository.count(); if (count === 0) { // Create default tipos de pregunta const tiposPregunta = [ { tipo_pregunta: 'Texto' }, { tipo_pregunta: 'Numero' }, { tipo_pregunta: 'Radio' }, { tipo_pregunta: 'Multiple' }, { tipo_pregunta: 'Abierto' }, { tipo_pregunta: 'Fecha' }, ]; await tiposPreguntaRepository.save(tiposPregunta); console.log('Tipos de pregunta creados'); } // Start the server await app.listen(process.env.PORT ?? 4200); console.log('API en ejecución en http://localhost:4200'); console.log('Swagger disponible en http://localhost:4200/api-docs'); } bootstrap();