Subir carpetas con las nuevas tablas

This commit is contained in:
santiago
2025-04-01 15:07:11 -06:00
parent 1520825ad3
commit fbd753d27e
45 changed files with 1452 additions and 0 deletions
@@ -0,0 +1,7 @@
import { IsEmail } from "class-validator";
export class CreateParticipanteDto {
@IsEmail()
correo: string
id_tipo_user: number
}
@@ -0,0 +1,3 @@
export class UpdateParticipanteDto {
correo: string
}
@@ -0,0 +1,60 @@
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from '@nestjs/common';
import { Participante } from './participante.entity';
import { ParticipanteService } from './participante.service';
import { CreateParticipanteDto } from './dto/create-participante.dto';
import { UpdateParticipanteDto } from './dto/update.participante.dto';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('Participantes') // Agrupa los endpoints en Swagger
@Controller('participante')
export class ParticipanteController {
constructor(private participanteService: ParticipanteService) {}
@ApiOperation({ summary: 'Obtener todos los participantes' })
@ApiResponse({ status: 200, description: 'Lista de participantes obtenida correctamente.' })
@Get()
getParticipantes(): Promise<Participante[]> {
return this.participanteService.getParticipantes()
}
@Get(':id')
@ApiOperation({ summary: 'Obtener un participante por ID' })
@ApiParam({ name: 'id', description: 'ID del participante', example: 1 })
@ApiResponse({ status: 200, description: 'Participante obtenido correctamente.' })
@ApiResponse({ status: 404, description: 'Participante no encontrado.' })
getParticipante(@Param('id', ParseIntPipe) id: number) {
return this.participanteService.getParticipante(id);
}
@Post()
@ApiOperation({ summary: 'Registrar un nuevo participante' })
@ApiBody({
description: 'Datos del participante a registrar',
schema: {
type: 'object',
properties: {
correo: { type: 'string', example: 'user@example.com' },
id_tipo_user: { type: 'integer', example: 2 }
}
}
})
@ApiResponse({ status: 201, description: 'Participante registrado exitosamente.' })
@ApiResponse({ status: 400, description: 'Datos inválidos.' })
createParticipante(@Body() newParticipante: CreateParticipanteDto) {
return this.participanteService.createParticipante(newParticipante);
}
@Delete(':id')
deleteParticipante(@Param('id', ParseIntPipe) id: number) {
return this.participanteService.deleteParticipante(id)
}
@Patch(':id')
updateParticipante(@Param('correo') id: number, @Body() participante: UpdateParticipanteDto) {
return this.participanteService.updateParticipante(id, participante);
}
}
+34
View File
@@ -0,0 +1,34 @@
import { ParticipanteEvento } from "src/participante_evento/participante_evento.entity";
import { TipoUser } from "src/tipo_user/tipo_user.entity";
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Participante {
@PrimaryGeneratedColumn()
id_participante: number
@Column()
correo: string
@Column()
id_tipo_user: number
//Relacion con tipo usuario
@ManyToOne(() => TipoUser, tipoUser => tipoUser.participante)
@JoinColumn({ name: 'participante_id' }) //nombre de la relacion
tipo_user: TipoUser[]
/*
@ManyToOne(() => Administrador, (admin) => admin.eventos)
@JoinColumn({ name: "id_administrador" })
administrador: Administrador;
@OneToMany(() => ParticipanteEvento, (pe) => pe.evento)
participantes: ParticipanteEvento[];
@OneToMany(() => Asistencia, (asistencia) => asistencia.evento)
asistencias: Asistencia[];
*/
}
+13
View File
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { ParticipanteService } from './participante.service';
import { ParticipanteController } from './participante.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Participante } from './participante.entity';
@Module({
imports: [TypeOrmModule.forFeature([Participante])],
controllers: [ParticipanteController],
providers: [ParticipanteService],
exports: [ParticipanteService],
})
export class ParticipanteModule {}
+74
View File
@@ -0,0 +1,74 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Participante } from './participante.entity';
import { Repository } from 'typeorm';
import { CreateParticipanteDto } from './dto/create-participante.dto';
import { UpdateAdminDto } from 'src/admin/dto/update.admin.dto';
import { UpdateParticipanteDto } from './dto/update.participante.dto';
@Injectable()
export class ParticipanteService {
constructor(
@InjectRepository(Participante) private participanteRepository: Repository<Participante>
) {}
async createParticipante(participante: CreateParticipanteDto) {
const participanteFound = await this.participanteRepository.findOne({
where: {
correo: participante.correo
}
})
if (participanteFound)
return new HttpException('Participante already exists', HttpStatus.CONFLICT)
return this.participanteRepository.save(participante)
}
getParticipantes() {
return this.participanteRepository.find({
relations: ['tipo_user']
})
}
async getParticipante(id_participante: number) {
const participanteFound = await this.participanteRepository.findOne({
where: {
id_participante
},
relations: ['tipo_user']
})
if (!participanteFound)
return new HttpException('Participante not found', HttpStatus.NOT_FOUND);
return participanteFound;
}
async deleteParticipante(id_participante: number) {
const result = await this.participanteRepository.delete({ id_participante })
if (result.affected === 0) {
return new HttpException('Participante not found', HttpStatus.NOT_FOUND);
}
return result;
}
async updateParticipante(id_participante: number, participante: UpdateParticipanteDto) {
const participanteFound = await this.participanteRepository.findOne({
where: {
id_participante
}
});
if (!participanteFound) {
return new HttpException('Participante not found', HttpStatus.NOT_FOUND)
}
const updateParticipante = Object.assign(participanteFound, participante)
return this.participanteRepository.save(updateParticipante)
}
}