This commit is contained in:
evenegas
2025-08-07 15:27:13 -06:00
commit 55a7081818
23 changed files with 12170 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
+12
View File
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TestModule } from './test/test.module';
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [TestModule,
ConfigModule.forRoot({ isGlobal: true }),],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
+8
View File
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
+30
View File
@@ -0,0 +1,30 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('API de Funcionarios')
.setDescription('Consulta de funcionarios por nombre y unidad')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('documentation', app, document); // http://localhost:3000/api
app.enableCors({ exposedHeaders: ['Content-Disposition'] });
app.useGlobalPipes(
new ValidationPipe({
transform: true,
}),
);
await app.listen(process.env.PORT ?? 3001);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
+13
View File
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
export class BuscarFuncionarioDto {
@ApiProperty({ example: 'Juan', description: 'Nombre del funcionario' })
Nombre: string;
@ApiProperty({ example: 'Pérez López', description: 'Apellidos del funcionario' })
Apellidos: string;
@ApiProperty({ example: 123, description: 'ID de la unidad responsable' })
IdUnidadResponsable: number;
}
View File
+1
View File
@@ -0,0 +1 @@
export class Test {}
+17
View File
@@ -0,0 +1,17 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { TestService } from './test.service';
import { SwaggerBuscarFuncionario } from './test.swagger';
@Controller('test')
export class TestController {
constructor(private readonly testService: TestService) { }
@Post()
@SwaggerBuscarFuncionario()
findOne(@Body() ususario: { Nombre: string, Apellidos: string, IdUnidadResponsable: number }) {
return this.testService.buscarFuncionario(ususario);
}
}
+11
View File
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { TestService } from './test.service';
import { TestController } from './test.controller';
import { HttpModule } from '@nestjs/axios';
@Module({
imports: [HttpModule],
controllers: [TestController],
providers: [TestService],
})
export class TestModule { }
+68
View File
@@ -0,0 +1,68 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';
interface DatosEntradaDirectorio {
Nombre: string;
Apellidos: string;
IdUnidadResponsable: number;
}
@Injectable()
export class TestService {
findAll() {
return `This action returns all test`;
}
findOne(id: number) {
return `This action returns a #${id} test`;
}
async buscarFuncionario(entrada: DatosEntradaDirectorio) {
const url = process.env.NEXT_PUBLIC_API_WEB1;
try {
interface DatosRespuestaDirectorio {
IdUnidadResponsable: number;
UnidadResponsable: string;
Cargo: string;
Titulo: string;
Nombre: string;
Apellidos: string;
Telefono: string;
Correo: string;
Nivel: number;
IdUnidadResponsablePapa: number;
UnidadResponsablePapa: string;
}
if (!url) {
throw new Error('La URL del servicio no está definida en las variables de entorno.');
}
const response = await axios.post(url, entrada, {
headers: {
'Content-Type': 'application/json',
},
});
console.log('Respuesta del servicio:', response);
return response
} catch (error) {
console.error('Error al consultar directorio:', error.message);
throw error;
}
}
remove(id: number) {
return `This action removes a #${id} test`;
}
}
+13
View File
@@ -0,0 +1,13 @@
// src/test/docs/test.swagger.ts
import { applyDecorators } from '@nestjs/common';
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { BuscarFuncionarioDto } from './dto/create-test.dto';
export function SwaggerBuscarFuncionario() {
return applyDecorators(
ApiTags('Test'),
ApiOperation({ summary: 'Buscar funcionario', description: 'Busca un funcionario por nombre, apellidos e ID de unidad responsable' }),
ApiBody({ type: BuscarFuncionarioDto }),
);
}