intento de registrar a un participante a un evento
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Param, ParseIntPipe, Post } from '@nestjs/common';
|
||||
import { RegistrarParticipanteDto } from './dto/registrarParticipanteDto.dto';
|
||||
import { EventoParticipanteService } from './evento-participante.service';
|
||||
import { EventoParticipante } from './eventoParticipante.entity';
|
||||
|
||||
@Controller('evento-participante')
|
||||
export class EventoParticipanteController {
|
||||
constructor(private readonly eventoParticipanteService: EventoParticipanteService){}
|
||||
|
||||
@Post()
|
||||
regitrarParticipante(@Body() datos: RegistrarParticipanteDto){
|
||||
return this.eventoParticipanteService.registrarParticipante(datos)
|
||||
regitrarParticipante(@Param()id_evento:number, @Body() datos: RegistrarParticipanteDto){
|
||||
return this.eventoParticipanteService.registrarParticipante(id_evento, datos)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import { Body, ConflictException, Injectable, Param } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@@ -7,26 +7,51 @@ import { RegistrarParticipanteDto } from './dto/registrarParticipanteDto.dto';
|
||||
import { Evento } from 'src/eventos/evento.entity';
|
||||
import { EventoParticipante } from './eventoParticipante.entity';
|
||||
import { Participante } from 'src/participante/participante.entity';
|
||||
import { info } from 'console';
|
||||
|
||||
@Injectable()
|
||||
export class EventoParticipanteService {
|
||||
constructor(
|
||||
@InjectRepository(Participante)
|
||||
private participanteRepository: Repository<Participante>,
|
||||
@InjectRepository(EventoParticipante)
|
||||
private eventoParticipanteRepository: Repository<EventoParticipante>,
|
||||
) {}
|
||||
|
||||
participanteExiste(correo: string): Promise<Participante> {
|
||||
participanteExiste(correo: string) {
|
||||
return this.participanteRepository.findOne({ where: { correo } });
|
||||
}
|
||||
|
||||
registrarParticipante(registrarParticipanteDto: RegistrarParticipanteDto) {
|
||||
registrarEnEvento(
|
||||
id_evento: number,
|
||||
registrarParticipanteDto: RegistrarParticipanteDto,
|
||||
) {
|
||||
this.participanteExiste(registrarParticipanteDto.correo).then(
|
||||
(participante) => {
|
||||
let info : EventoParticipante;
|
||||
|
||||
info.id_evento = id_evento
|
||||
info.id_participante = participante.id_participante
|
||||
|
||||
this.eventoParticipanteRepository.save(
|
||||
this.eventoParticipanteRepository.create(info),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
registrarParticipante(
|
||||
id_evento: number,
|
||||
registrarParticipanteDto: RegistrarParticipanteDto,
|
||||
) {
|
||||
return this.participanteExiste(registrarParticipanteDto.correo).then(
|
||||
(participante) => {
|
||||
if (participante) {
|
||||
this.registrarEnEvento(id_evento, registrarParticipanteDto);
|
||||
throw new ConflictException('Este Usuario ya existe');
|
||||
}
|
||||
return this.participanteRepository.save(
|
||||
this.participanteRepository.create(registrarParticipanteDto)
|
||||
this.participanteRepository.create(registrarParticipanteDto),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Evento } from 'src/eventos/evento.entity';
|
||||
import { Entity, JoinColumn, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Participante } from '../../participante/participante.entity';
|
||||
|
||||
@Entity()
|
||||
@@ -7,6 +7,12 @@ export class EventoParticipante {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_eventoParticipante: number
|
||||
|
||||
@Column({type: Number, nullable:false})
|
||||
id_evento: number
|
||||
|
||||
@Column({type:Number, nullable:false})
|
||||
id_participante: number
|
||||
|
||||
@ManyToOne(() => Evento, (evento) => evento.eventoParticipantes)
|
||||
@JoinColumn({ name: 'id_evento' })
|
||||
evento: Evento;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableCors()
|
||||
await app.listen(AppModule.port);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user