Files
formularios_api/src/main.ts
T

60 lines
2.1 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
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<NestExpressApplication>(AppModule);
const configService = app.get(ConfigService);
// Configuración de validación global
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // Elimina propiedades no decoradas
transform: true, // Transforma los datos recibidos al tipo definido en el DTO
}),
);
app.useStaticAssets(join(__dirname, '..', 'uploads'), {
index: false,
prefix: '/',
});
// CORS configuration
app.enableCors({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: ['Content-Type', 'Authorization'],
});
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.
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(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();