Subir carpetas con las nuevas tablas
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export class CreateEventoDto {
|
||||
tipo_evento: string;
|
||||
|
||||
nombre_evento: string;
|
||||
|
||||
fecha_inicio: Date;
|
||||
|
||||
fecha_fin: Date;
|
||||
|
||||
//agregar el id del administrador
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export class UpdateEventoDto {
|
||||
tipo_evento?: string
|
||||
nombre_evento: string
|
||||
fecha_inicio?: Date
|
||||
fecha_fin?: Date
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post } from '@nestjs/common';
|
||||
import { EventoService } from './evento.service';
|
||||
import { Evento } from './evento.entity';
|
||||
import { CreateEventoDto } from './dto/create-evento.dto';
|
||||
import { UpdateEventoDto } from './dto/update.evento.dto';
|
||||
|
||||
@Controller('evento')
|
||||
export class EventoController {
|
||||
constructor(private eventoService: EventoService) {}
|
||||
|
||||
@Get()
|
||||
getEventos(): Promise<Evento[]> {
|
||||
return this.eventoService.getEventos()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
getEvento(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.eventoService.getEvento(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
createEvento(@Body() newEvento: CreateEventoDto) {
|
||||
return this.eventoService.createEvento(newEvento)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
deleteEvento(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.eventoService.deleteEvento(id)
|
||||
}
|
||||
//@Param(':id', ParseIntPipe) id: number, @Body() tipoUser: UpdateTipoUserDto
|
||||
@Patch()
|
||||
updateEvento(@Param(':id', ParseIntPipe) id: number, @Body() evento: UpdateEventoDto) {
|
||||
return this.eventoService.updateEvento(id, evento)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ParticipanteEvento } from "src/participante_evento/participante_evento.entity";
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class Evento {
|
||||
@PrimaryGeneratedColumn()
|
||||
id_evento: number
|
||||
|
||||
@Column()
|
||||
tipo_evento: string
|
||||
|
||||
@Column()
|
||||
nombre_evento: string
|
||||
|
||||
@Column({type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
fecha_inicio: Date
|
||||
|
||||
@Column({type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
fecha_fin: Date
|
||||
|
||||
/* falta hacer la relacion
|
||||
@Column()
|
||||
id_administrador: number
|
||||
|
||||
@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[];
|
||||
*/
|
||||
|
||||
@OneToMany(() => ParticipanteEvento, (participanteEvento) => participanteEvento.evento)
|
||||
participantes: ParticipanteEvento[];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EventoService } from './evento.service';
|
||||
import { EventoController } from './evento.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Evento } from './evento.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Evento])],
|
||||
controllers: [EventoController],
|
||||
providers: [EventoService]
|
||||
})
|
||||
export class EventoModule {}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Evento } from './evento.entity';
|
||||
import { CreateEventoDto } from './dto/create-evento.dto';
|
||||
import { UpdateEventoDto } from './dto/update.evento.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EventoService {
|
||||
constructor(
|
||||
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
|
||||
) {}
|
||||
|
||||
async createEvento(evento: CreateEventoDto) {
|
||||
const eventoFound = await this.eventoRepository.findOne({
|
||||
where: {
|
||||
nombre_evento: evento.nombre_evento,
|
||||
tipo_evento: evento.tipo_evento
|
||||
}
|
||||
})
|
||||
|
||||
if (eventoFound)
|
||||
return new HttpException('Evento already exists', HttpStatus.CONFLICT)
|
||||
|
||||
const createEvento = this.eventoRepository.create(evento)
|
||||
|
||||
return this.eventoRepository.save(createEvento)
|
||||
}
|
||||
|
||||
getEventos() {
|
||||
return this.eventoRepository.find({
|
||||
relations: ['participantes']
|
||||
})
|
||||
}
|
||||
|
||||
async getEvento(id_evento: number) {
|
||||
const eventoFound = await this.eventoRepository.findOne({
|
||||
where: {
|
||||
id_evento
|
||||
},
|
||||
relations: ['participantes']
|
||||
})
|
||||
|
||||
if (!eventoFound)
|
||||
return new HttpException('Evento not found', HttpStatus.NOT_FOUND);
|
||||
|
||||
return eventoFound
|
||||
}
|
||||
|
||||
async deleteEvento(id_evento: number) {
|
||||
const result = await this.eventoRepository.delete({ id_evento })
|
||||
|
||||
if (result.affected === 0) {
|
||||
return new HttpException('Evento not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
async updateEvento(id_evento: number, evento: UpdateEventoDto) {
|
||||
const eventoFound = await this.eventoRepository.findOne({
|
||||
where: {
|
||||
id_evento
|
||||
}
|
||||
})
|
||||
|
||||
if (!eventoFound)
|
||||
return new HttpException('Evento not found', HttpStatus.NOT_FOUND)
|
||||
|
||||
const updateEvento = Object.assign(eventoFound, evento)
|
||||
return this.eventoRepository.save(updateEvento)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user