From 7d8c9e9ef49f32d4a86543abfdd5086c1fb4042c Mon Sep 17 00:00:00 2001 From: miguel Date: Wed, 18 Jun 2025 10:59:06 -0600 Subject: [PATCH] Add Trabajadores module with controller, service, DTOs, and entity; integrate with TypeORM --- src/app.module.ts | 2 + src/db/typeorm.config.ts | 51 +++++++++++++++++-- .../dto/create-trabajadore.dto.ts | 1 + .../dto/update-trabajadore.dto.ts | 4 ++ .../entities/trabajadore.entity.ts | 22 ++++++++ src/trabajadores/trabajadores.controller.ts | 34 +++++++++++++ src/trabajadores/trabajadores.module.ts | 13 +++++ src/trabajadores/trabajadores.service.ts | 26 ++++++++++ 8 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 src/trabajadores/dto/create-trabajadore.dto.ts create mode 100644 src/trabajadores/dto/update-trabajadore.dto.ts create mode 100644 src/trabajadores/entities/trabajadore.entity.ts create mode 100644 src/trabajadores/trabajadores.controller.ts create mode 100644 src/trabajadores/trabajadores.module.ts create mode 100644 src/trabajadores/trabajadores.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index 070febc..649d94d 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -27,6 +27,7 @@ import { AsistenciaModule } from './asistencia/asistencia.module'; import { ParticipanteEventoModule } from './participante_evento/participante_evento.module'; import { ValidacionesModule } from './validaciones/validaciones.module'; import { AlumnosModule } from './alumnos/alumnos.module'; +import { TrabajadoresModule } from './trabajadores/trabajadores.module'; @Module({ imports: [ @@ -65,6 +66,7 @@ import { AlumnosModule } from './alumnos/alumnos.module'; TipoUserModule, ValidacionesModule, QrModule, + TrabajadoresModule, ], controllers: [AppController], diff --git a/src/db/typeorm.config.ts b/src/db/typeorm.config.ts index e893aa4..8748b60 100644 --- a/src/db/typeorm.config.ts +++ b/src/db/typeorm.config.ts @@ -1,6 +1,25 @@ import { ConfigService } from '@nestjs/config'; import { TypeOrmModuleOptions } from '@nestjs/typeorm'; import { RegistroAlumno } from '../alumnos/entities/registro-alumno.entity'; +import { RegistroTrabajador } from 'src/trabajadores/entities/trabajadore.entity'; +import { Administrador } from 'src/administrador/entities/administrador.entity'; +import { Asistencia } from 'src/asistencia/entities/asistencia.entity'; +import { Cuestionario } from 'src/cuestionario/entities/cuestionario.entity'; +import { CuestionarioRespondido } from 'src/cuestionario_respondido/entities/cuestionario_respondido.entity'; +import { CuestionarioSeccion } from 'src/cuestionario_seccion/entities/cuestionario_seccion.entity'; +import { Evento } from 'src/evento/entities/evento.entity'; +import { Opcion } from 'src/opcion/entities/opcion.entity'; +import { Participante } from 'src/participante/entities/participante.entity'; +import { ParticipanteEvento } from 'src/participante_evento/entities/participante_evento.entity'; +import { Pregunta } from 'src/pregunta/entities/pregunta.entity'; +import { PreguntaOpcion } from 'src/pregunta_opcion/entities/pregunta_opcion.entity'; +import { RespuestaParticipanteAbierta } from 'src/respuesta_participante_abierta/entities/respuesta_participante_abierta.entity'; +import { RespuestaParticipanteCerrada } from 'src/respuesta_participante_cerrada/entities/respuesta_participante_cerrada.entity'; +import { Seccion } from 'src/seccion/entities/seccion.entity'; +import { SeccionPregunta } from 'src/seccion_pregunta/entities/seccion_pregunta.entity'; +import { TipoCuestionario } from 'src/tipo_cuestionario/entities/tipo_cuestionario.entity'; +import { TipoPregunta } from 'src/tipo_pregunta/entities/tipo_pregunta.entity'; +import { TipoUser } from 'src/tipo_user/entities/tipo_user.entity'; export const createMainDbConfig = async ( configService: ConfigService, @@ -11,11 +30,31 @@ export const createMainDbConfig = async ( username: configService.get('DB_USERNAME'), password: configService.get('DB_PASSWORD'), database: configService.get('DB_DATABASE'), - entities: [__dirname + '/../**/*.entity{.ts,.js}'], - autoLoadEntities: true, - synchronize: true, + entities: [ + Administrador, + Asistencia, + Cuestionario, + CuestionarioRespondido, + CuestionarioSeccion, + Evento, + Opcion, + Participante, + ParticipanteEvento, + Pregunta, + PreguntaOpcion, + RespuestaParticipanteAbierta, + RespuestaParticipanteCerrada, + Seccion, + SeccionPregunta, + TipoCuestionario, + TipoPregunta, + TipoUser + ], retryAttempts: 5, retryDelay: 3000, + connectTimeout: 30000, + + synchronize: false, dropSchema: false, }); @@ -29,9 +68,11 @@ export const createAlumnosDbConfig = async ( username: configService.get('ALUMNOS_DB_USERNAME'), password: configService.get('ALUMNOS_DB_PASSWORD'), database: configService.get('ALUMNOS_DB_DATABASE'), - entities: [RegistroAlumno], - synchronize: false, + entities: [RegistroAlumno, RegistroTrabajador], retryAttempts: 10, retryDelay: 3000, connectTimeout: 30000, + + synchronize: false, + dropSchema: false, }); diff --git a/src/trabajadores/dto/create-trabajadore.dto.ts b/src/trabajadores/dto/create-trabajadore.dto.ts new file mode 100644 index 0000000..1219a60 --- /dev/null +++ b/src/trabajadores/dto/create-trabajadore.dto.ts @@ -0,0 +1 @@ +export class CreateTrabajadoreDto {} diff --git a/src/trabajadores/dto/update-trabajadore.dto.ts b/src/trabajadores/dto/update-trabajadore.dto.ts new file mode 100644 index 0000000..dd69e6d --- /dev/null +++ b/src/trabajadores/dto/update-trabajadore.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/swagger'; +import { CreateTrabajadoreDto } from './create-trabajadore.dto'; + +export class UpdateTrabajadoreDto extends PartialType(CreateTrabajadoreDto) {} diff --git a/src/trabajadores/entities/trabajadore.entity.ts b/src/trabajadores/entities/trabajadore.entity.ts new file mode 100644 index 0000000..a2d1206 --- /dev/null +++ b/src/trabajadores/entities/trabajadore.entity.ts @@ -0,0 +1,22 @@ +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; + +@Entity('registro_trabajador') +export class RegistroTrabajador { + @PrimaryGeneratedColumn() + id_trabajador: number; + + @Column({ type: 'varchar', length: 20, unique: true }) + numero_trabajador: string; + + @Column({ type: 'varchar', length: 13, unique: true }) + rfc: string; + + @Column({ type: 'varchar', length: 100 }) + nombre: string; + + @Column({ type: 'varchar', length: 100 }) + apellidos: string; + + @Column({ type: 'char', length: 1 }) + genero: string; +} diff --git a/src/trabajadores/trabajadores.controller.ts b/src/trabajadores/trabajadores.controller.ts new file mode 100644 index 0000000..ab41cdb --- /dev/null +++ b/src/trabajadores/trabajadores.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { TrabajadoresService } from './trabajadores.service'; +import { CreateTrabajadoreDto } from './dto/create-trabajadore.dto'; +import { UpdateTrabajadoreDto } from './dto/update-trabajadore.dto'; + +@Controller('trabajadores') +export class TrabajadoresController { + constructor(private readonly trabajadoresService: TrabajadoresService) {} + + @Post() + create(@Body() createTrabajadoreDto: CreateTrabajadoreDto) { + return this.trabajadoresService.create(createTrabajadoreDto); + } + + @Get() + findAll() { + return this.trabajadoresService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.trabajadoresService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateTrabajadoreDto: UpdateTrabajadoreDto) { + return this.trabajadoresService.update(+id, updateTrabajadoreDto); + } + + @Delete(':id') + remove(@Param('id') id: string) { + return this.trabajadoresService.remove(+id); + } +} diff --git a/src/trabajadores/trabajadores.module.ts b/src/trabajadores/trabajadores.module.ts new file mode 100644 index 0000000..7f7d44c --- /dev/null +++ b/src/trabajadores/trabajadores.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common'; +import { TrabajadoresService } from './trabajadores.service'; +import { TrabajadoresController } from './trabajadores.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { RegistroTrabajador } from './entities/trabajadore.entity'; + +@Module({ + imports: [TypeOrmModule.forFeature([RegistroTrabajador], 'alumnosConnection')], + + controllers: [TrabajadoresController], + providers: [TrabajadoresService], +}) +export class TrabajadoresModule {} diff --git a/src/trabajadores/trabajadores.service.ts b/src/trabajadores/trabajadores.service.ts new file mode 100644 index 0000000..13a1aef --- /dev/null +++ b/src/trabajadores/trabajadores.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { CreateTrabajadoreDto } from './dto/create-trabajadore.dto'; +import { UpdateTrabajadoreDto } from './dto/update-trabajadore.dto'; + +@Injectable() +export class TrabajadoresService { + create(createTrabajadoreDto: CreateTrabajadoreDto) { + return 'This action adds a new trabajadore'; + } + + findAll() { + return `This action returns all trabajadores`; + } + + findOne(id: number) { + return `This action returns a #${id} trabajadore`; + } + + update(id: number, updateTrabajadoreDto: UpdateTrabajadoreDto) { + return `This action updates a #${id} trabajadore`; + } + + remove(id: number) { + return `This action removes a #${id} trabajadore`; + } +}