muchos cambios :'v
This commit is contained in:
+27
-32
@@ -1,23 +1,22 @@
|
||||
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';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
const configService = app.get(ConfigService);
|
||||
|
||||
// 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: '*',
|
||||
@@ -25,34 +24,30 @@ async function bootstrap() {
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
});
|
||||
|
||||
// Swagger setup
|
||||
DocsModule.setupSwagger(app);
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Formularios API')
|
||||
.setDescription(
|
||||
`Esta es la API del sistema de registros para eventos de la FES Acatlán. Permite gestionar eventos académicos y sus formularios asociados.
|
||||
|
||||
// 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');
|
||||
}
|
||||
Flujo de creación:
|
||||
|
||||
1. Primero, se debe crear un evento usando **POST /evento**.
|
||||
2. Luego, se crea un formulario y se relaciona con el evento usando **POST /cuestionario**.
|
||||
3. (Opcional) También se puede crear un formulario y un evento al mismo tiempo usando **POST /cuestionario/evento**, lo cual genera automáticamente ambos y los relaciona.`,
|
||||
)
|
||||
.setVersion('1.0')
|
||||
.addBearerAuth()
|
||||
.addTag('Evento')
|
||||
.addTag('Cuestionario')
|
||||
.addTag('Cuestionario Respondido')
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('api-docs', app, document);
|
||||
|
||||
// Start the server
|
||||
await app.listen(process.env.PORT ?? 4200);
|
||||
console.log('API en ejecución en http://localhost:4200');
|
||||
await app.listen(configService.get<number>('API_PORT') || 4200);
|
||||
console.log('\nAPI en ejecución en http://localhost:4200');
|
||||
console.log('Swagger disponible en http://localhost:4200/api-docs');
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user