creacion de eventos, registro, eliminacion de eventos, login

This commit is contained in:
JorgeMike
2023-02-27 14:01:13 -06:00
parent 7abc8d0134
commit 8251599816
13 changed files with 190 additions and 148 deletions
+2 -1
View File
@@ -2,8 +2,9 @@ PORT=5089
DB_HOST=localhost
DB_USER=root
DB_PASS=password
DB_PASSWORD=Dosmiluno2001
DB_NAME=cedetec_proyectos
DB_PORT=3306
SALT_ROUNDS = 10
+20 -10
View File
@@ -11,19 +11,29 @@ import { UsuarioModule } from './usuario/usuario.module';
import { AuthModule } from './auth/auth.module';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { Evento } from './eventos/evento.entity';
import { Participante } from './participante/participante.entity';
import { EventoParticipante } from './evento-participante/evento-participante/eventoParticipante.entity';
import { Usuario } from './usuario/usuario.entity';
@Module({
imports: [
ConfigModule.forRoot({isGlobal: true}),
TypeOrmModule.forRoot({
type: 'mariadb',
host: 'localhost',
port: 3306,
username:'root',
password: 'password',
database: 'cedetec_proyectos',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true
ConfigModule.forRoot({
envFilePath: '.env',
isGlobal: true}),
TypeOrmModule.forRootAsync({
imports:[ConfigModule],
inject:[ConfigService],
useFactory: async (configService: ConfigService) => ({
type: 'mariadb',
host: configService.get('DB_HOST'),
port: configService.get('DB_PORT'),
username: configService.get('DB_USER'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
entities: [Evento, Participante, EventoParticipante, Usuario],
synchronize: true
})
}),
EventosModule,
ParticipanteModule,
+15 -7
View File
@@ -1,10 +1,18 @@
import { PartialType } from "@nestjs/swagger";
import { IsNotEmpty } from "class-validator";
import { LoginUsuarioDto } from "./loginUsuario.dto";
import { PartialType } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, MaxLength, MinLength } from 'class-validator';
import { LoginUsuarioDto } from './loginUsuario.dto';
export class RegistrarUsuarioDto extends PartialType(LoginUsuarioDto) {
@IsNotEmpty()
name: string;
export class RegistrarUsuarioDto extends PartialType(LoginUsuarioDto){
@IsNotEmpty()
name: string
@IsNotEmpty()
lastName: string;
}
@IsEmail()
email: string;
@MinLength(10)
@MaxLength(15)
password: string;
}
@@ -0,0 +1,15 @@
import { IsNotEmpty, IsNumber } from "class-validator"
export class registrarEnEvento {
@IsNumber()
@IsNotEmpty()
id_eventoParticipante: number
@IsNumber()
@IsNotEmpty()
id_evento: number
@IsNumber()
@IsNotEmpty()
id_participante: number
}
@@ -13,10 +13,10 @@ export class RegistrarParticipanteDto {
@IsNotEmpty()
apellido_materno: string;
@IsEmail()
correo: string;
@IsString()
@IsNotEmpty()
carrera: string;
@IsEmail()
correo: string;
}
@@ -7,9 +7,9 @@ import { EventoParticipante } from './eventoParticipante.entity';
export class EventoParticipanteController {
constructor(private readonly eventoParticipanteService: EventoParticipanteService){}
@Post()
regitrarParticipante(@Param()id_evento:number, @Body() datos: RegistrarParticipanteDto){
return this.eventoParticipanteService.registrarParticipante(id_evento, datos)
@Post(':id')
regitrarParticipante(@Param("id", ParseIntPipe)id: number, @Body() datos: RegistrarParticipanteDto){
return this.eventoParticipanteService.registrarParticipante(id, datos)
}
@@ -8,6 +8,7 @@ import { Evento } from 'src/eventos/evento.entity';
import { EventoParticipante } from './eventoParticipante.entity';
import { Participante } from 'src/participante/participante.entity';
import { info } from 'console';
import { registrarEnEvento } from './dto/registrarEnEvento.dto';
@Injectable()
export class EventoParticipanteService {
@@ -22,21 +23,22 @@ export class EventoParticipanteService {
return this.participanteRepository.findOne({ where: { correo } });
}
registrarEnEvento(
async registrarEnEvento(
id_evento: number,
registrarParticipanteDto: RegistrarParticipanteDto,
) {
this.participanteExiste(registrarParticipanteDto.correo).then(
(participante) => {
let info : EventoParticipante;
const participante = await this.participanteExiste(
registrarParticipanteDto.correo,
);
/* console.log(id_evento);
console.log(participante); */
info.id_evento = id_evento
info.id_participante = participante.id_participante
const registro = new EventoParticipante();
registro.id_evento = id_evento;
registro.id_participante = participante.id_participante;
this.eventoParticipanteRepository.save(
this.eventoParticipanteRepository.create(info),
);
},
return this.eventoParticipanteRepository.save(
this.eventoParticipanteRepository.create(registro),
);
}
@@ -44,15 +46,19 @@ export class EventoParticipanteService {
id_evento: number,
registrarParticipanteDto: RegistrarParticipanteDto,
) {
/* console.log(id_evento);
console.log(registrarParticipanteDto); */
return this.participanteExiste(registrarParticipanteDto.correo).then(
(participante) => {
if (participante) {
this.registrarEnEvento(id_evento, registrarParticipanteDto);
throw new ConflictException('Este Usuario ya existe');
(res) => {
if (res) {
this.registrarEnEvento(id_evento, res);
} else {
this.participanteRepository
.save(this.participanteRepository.create(registrarParticipanteDto))
.then((res) => {
this.registrarEnEvento(id_evento, res);
});
}
return this.participanteRepository.save(
this.participanteRepository.create(registrarParticipanteDto),
);
},
);
}
+14 -29
View File
@@ -1,31 +1,16 @@
export class actualizarEventoDto {
nombre?: string
evento_identificador ?: string
fecha_inicio?: Date
fecha_fin?: Date
horario?: string
requisitos?: string
modalidad?: string
lugar?: string
cuota_inscripcion ?: number
patrocinador ?: string
tipo_acreditacion?: string
fecha_limite_inscripcion?: Date
tipo_evento?: string
estado?: boolean
descripcion?: string
nombre?: string;
tipo_evento?: string;
organizadores?: string[];
proyecto?: string[];
modalidad?: string[];
lugar?: string;
requisitos?: string;
cuota_inscripcion?: number;
patrocinador?: string;
tipo_acreditacion?: string;
descripcion?: string;
fecha_inicio?: Date;
fecha_fin?: Date;
fecha_limite_inscripcion?: Date;
}
+14 -30
View File
@@ -1,32 +1,16 @@
export class crearEventoDto {
nombre: string
evento_identificador ?: string
fecha_inicio: Date
fecha_fin: Date
horario: string
requisitos: string
modalidad: string
lugar: string
cuota_inscripcion ?: number
patrocinador ?: string
tipo_acreditacion: string
fecha_limite_inscripcion: Date
tipo_evento: string
estado: boolean
descripcion: string
nombre: string;
tipo_evento: string;
organizadores: string[];
proyecto: string[];
modalidad: string[];
lugar: string;
requisitos: string;
cuota_inscripcion: number;
patrocinador: string;
tipo_acreditacion: string;
descripcion: string;
fecha_inicio: Date;
fecha_fin: Date;
fecha_limite_inscripcion: Date;
}
+30 -24
View File
@@ -14,49 +14,55 @@ export class Evento {
@Column({ nullable: false })
nombre: string;
@Column({ nullable: true })
evento_identificador: string;
@Column({ nullable: false, type: 'datetime' })
fecha_inicio: Date;
@Column({ nullable: false, type: 'datetime' })
fecha_fin: Date;
@Column({ nullable: false })
horario: string;
tipo_evento: string;
@Column("simple-array", {nullable: false})
organizadores: string[]
@Column("simple-array", {nullable: false})
proyecto: string[]
@Column("simple-array", {nullable: false})
modalidad: string[]
@Column({ nullable: false })
lugar: string;
@Column({ nullable: false })
requisitos: string;
@Column({ nullable: false })
modalidad: string;
@Column({ nullable: false })
lugar: string;
@Column({ nullable: true })
cuota_inscripcion: number;
@Column({ nullable: true })
patrocinador: string;
@Column({ nullable: false })
@Column({ nullable: true })
tipo_acreditacion: string;
@Column({nullable: false})
descripcion: string
@Column({ nullable: false, type: 'datetime' })
fecha_inicio: Date;
@Column({ nullable: false, type: 'datetime' })
fecha_fin: Date;
@Column({ nullable: false, type: 'datetime' })
fecha_limite_inscripcion: Date;
@Column({ nullable: false })
tipo_evento: string;
@Column({ nullable: true })
evento_identificador: string;
@Column({ nullable: false })
@Column({ nullable: true })
horario: string;
@Column({ nullable: true })
estado: boolean;
@Column({ nullable: false })
descripcion: string;
@OneToMany(
() => EventoParticipante,
(eventoParticipante) => eventoParticipante.evento,
+2 -2
View File
@@ -20,7 +20,7 @@ export class EventosController {
}
@Post()
postEvento(@Body() nuevoEvento: crearEventoDto): Promise<Evento>{
postEvento(@Body() nuevoEvento: crearEventoDto){
return this.eventoService.postEvento(nuevoEvento)
}
@@ -31,6 +31,6 @@ export class EventosController {
@Delete(':id')
deleteEvento(@Param('id', ParseIntPipe)id: number){
return this.eventoService.deleteEvento(id)
return this.eventoService.deleteEventoParticipante(id)
}
}
+2 -1
View File
@@ -1,11 +1,12 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EventoParticipante } from 'src/evento-participante/evento-participante/eventoParticipante.entity';
import { Evento } from './evento.entity';
import { EventosController } from './eventos.controller';
import { EventosService } from './eventos.service';
@Module({
imports:[TypeOrmModule.forFeature([Evento])],
imports:[TypeOrmModule.forFeature([Evento, EventoParticipante])],
controllers:[EventosController],
providers:[EventosService]
})
+47 -21
View File
@@ -1,37 +1,63 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { EventoParticipante } from 'src/evento-participante/evento-participante/eventoParticipante.entity';
import { Participante } from 'src/participante/participante.entity';
import { Repository } from 'typeorm';
import { actualizarEventoDto } from './dto/actualizarEvento.dto';
import { crearEventoDto } from './dto/crearEvento.dto';
import { Evento } from './evento.entity';
@Injectable()
export class EventosService {
constructor(@InjectRepository(Evento) private eventoRepository: Repository<Evento>){}
constructor(
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
@InjectRepository(EventoParticipante)
private eventoParticipanteRepository: Repository<EventoParticipante>,
) {}
getEventos(){
return this.eventoRepository.find()
}
getEventos() {
return this.eventoRepository.find();
}
getEventosPorId(id: number){
return this.eventoRepository.findOne({
where:{
id_evento: id
}
})
}
getEventosPorId(id: number) {
return this.eventoRepository.findOne({
where: {
id_evento: id,
},
});
}
postEvento(evento: crearEventoDto){
const nuevoEvento = this.eventoRepository.create(evento)
return this.eventoRepository.save(nuevoEvento)
}
postEvento(evento: crearEventoDto) {
const nuevoEvento = this.eventoRepository.create(evento);
return this.eventoRepository.save(nuevoEvento);
}
updateEvento(id: number, actualizacion: actualizarEventoDto){
return this.eventoRepository.update({id_evento: id}, actualizacion)
}
updateEvento(id: number, actualizacion: actualizarEventoDto) {
return this.eventoRepository.update({ id_evento: id }, actualizacion);
}
deleteEvento(id:number){
return this.eventoRepository.delete({id_evento:id})
deleteParticipantes(id: number) {
this.eventoParticipanteRepository.delete({ id_evento: id });
}
deleteEvento(id: number) {
this.eventoRepository.delete({ id_evento: id });
}
async deleteEventoParticipante(id: number) {
const queryRunner =
this.eventoRepository.manager.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
await this.deleteParticipantes(id);
await this.deleteEvento(id);
await queryRunner.commitTransaction();
} catch (err) {
await queryRunner.rollbackTransaction();
throw err;
} finally {
await queryRunner.release();
}
}
}