Add Trabajadores module with controller, service, DTOs, and entity; integrate with TypeORM
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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<string>('DB_USERNAME'),
|
||||
password: configService.get<string>('DB_PASSWORD'),
|
||||
database: configService.get<string>('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<string>('ALUMNOS_DB_USERNAME'),
|
||||
password: configService.get<string>('ALUMNOS_DB_PASSWORD'),
|
||||
database: configService.get<string>('ALUMNOS_DB_DATABASE'),
|
||||
entities: [RegistroAlumno],
|
||||
synchronize: false,
|
||||
entities: [RegistroAlumno, RegistroTrabajador],
|
||||
retryAttempts: 10,
|
||||
retryDelay: 3000,
|
||||
connectTimeout: 30000,
|
||||
|
||||
synchronize: false,
|
||||
dropSchema: false,
|
||||
});
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateTrabajadoreDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateTrabajadoreDto } from './create-trabajadore.dto';
|
||||
|
||||
export class UpdateTrabajadoreDto extends PartialType(CreateTrabajadoreDto) {}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user