diff --git a/src/app.module.ts b/src/app.module.ts index 52a4042..07d553e 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -50,6 +50,8 @@ import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; import { CarruselModule } from './carrusel/carrusel.module'; import { Carrusel } from './entities/carrusel.entity'; +import { ComentariosModule } from './comentarios/comentarios.module'; +import { Comentarios } from './comentarios/entity/comentarios.entity'; @Module({ imports: [ @@ -94,7 +96,9 @@ import { Carrusel } from './entities/carrusel.entity'; EquipoEvento, EquipoMiembro, /* Agregado el 2 de junio */ - Carrusel + Carrusel, + /* No recuerdo porque empece a ponerle fechas */ + Comentarios, ], synchronize: true, }), @@ -117,10 +121,12 @@ import { Carrusel } from './entities/carrusel.entity'; ProyectoActividadModule, ActividadModule, EmailModule, + ComentariosModule, MulterModule.register({ dest: './uploads', // directorio de destino para guardar los archivos cargados }), CarruselModule, + ComentariosModule, ], controllers: [ AppController, @@ -132,6 +138,7 @@ import { Carrusel } from './entities/carrusel.entity'; export class AppModule { static port: number; constructor(private readonly configService: ConfigService) { + console.log('PORT', this.configService.get('PORT')); AppModule.port = this.configService.get('PORT'); } } diff --git a/src/comentarios/comentario.dto.ts b/src/comentarios/comentario.dto.ts new file mode 100644 index 0000000..6aebf45 --- /dev/null +++ b/src/comentarios/comentario.dto.ts @@ -0,0 +1,4 @@ +export class ComentarioDto { + from: string; + comentario: string; +} diff --git a/src/comentarios/comentarios.controller.ts b/src/comentarios/comentarios.controller.ts new file mode 100644 index 0000000..b38d3b4 --- /dev/null +++ b/src/comentarios/comentarios.controller.ts @@ -0,0 +1,43 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + ParseIntPipe, + Post, + Query, + } from '@nestjs/common'; + import { ComentariosService } from './comentarios.service'; + import { ComentarioDto } from './comentario.dto'; + + @Controller('comentarios') + export class ComentariosController { + constructor(private comentariosService: ComentariosService) {} + + @Post() + postComentario(@Body() comentario: ComentarioDto) { + return this.comentariosService.postComentario(comentario); + } + + @Get() + getComentarios() { + return this.comentariosService.getComentarios(); + } + + @Get('by-date') + getComentariosByDate( + @Query('before') before?: string, + @Query('after') after?: string, + @Query('from') from?: string, + @Query('to') to?: string, + ) { + return this.comentariosService.getComentariosByDate(before, after, from, to); + } + + @Delete(':id') + deleteComentario(@Param('id', ParseIntPipe) id: number) { + return this.comentariosService.deleteComentario(id); + } + } + \ No newline at end of file diff --git a/src/comentarios/comentarios.module.ts b/src/comentarios/comentarios.module.ts new file mode 100644 index 0000000..26d536d --- /dev/null +++ b/src/comentarios/comentarios.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ComentariosController } from './comentarios.controller'; +import { ComentariosService } from './comentarios.service'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Comentarios } from './entity/comentarios.entity'; + +@Module({ + imports: [TypeOrmModule.forFeature([Comentarios])], + controllers: [ComentariosController], + providers: [ComentariosService], +}) +export class ComentariosModule {} diff --git a/src/comentarios/comentarios.service.ts b/src/comentarios/comentarios.service.ts new file mode 100644 index 0000000..f654940 --- /dev/null +++ b/src/comentarios/comentarios.service.ts @@ -0,0 +1,55 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Comentarios } from './entity/comentarios.entity'; +import { Repository } from 'typeorm'; +import { ComentarioDto } from './comentario.dto'; + +@Injectable() +export class ComentariosService { + constructor( + @InjectRepository(Comentarios) + private comentariosRepository: Repository, + ) {} + + postComentario(comentario: ComentarioDto) { + const nuevoComentario = this.comentariosRepository.create(comentario); + return this.comentariosRepository.save(nuevoComentario); + } + + getComentarios() { + return this.comentariosRepository.find(); + } + + async getComentariosByDate( + before?: string, + after?: string, + from?: string, + to?: string, + ) { + const query = this.comentariosRepository.createQueryBuilder('comentarios'); + + if (before) { + query.andWhere('comentarios.fecha_registro < :before', { + before: new Date(before), + }); + } + + if (after) { + query.andWhere('comentarios.fecha_registro > :after', { after: new Date(after) }); + } + + if (from) { + query.andWhere('comentarios.fecha_registro >= :from', { from: new Date(from) }); + } + + if (to) { + query.andWhere('comentarios.fecha_registro <= :to', { to: new Date(to) }); + } + + return await query.getMany(); + } + + deleteComentario(id: number) { + return this.comentariosRepository.delete({ id_comentario: id }); + } +} diff --git a/src/comentarios/entity/comentarios.entity.ts b/src/comentarios/entity/comentarios.entity.ts new file mode 100644 index 0000000..71a216e --- /dev/null +++ b/src/comentarios/entity/comentarios.entity.ts @@ -0,0 +1,16 @@ +import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm'; + +@Entity() +export class Comentarios { + @PrimaryGeneratedColumn() + id_comentario: number; + + @Column() + from: string; + + @Column() + comentario: string; + + @CreateDateColumn({ type: 'timestamp' }) + fecha_registro: Date; +} diff --git a/src/eventos/dto/actualizarEvento.dto.ts b/src/eventos/dto/actualizarEvento.dto.ts index dbdbe7e..51d9425 100644 --- a/src/eventos/dto/actualizarEvento.dto.ts +++ b/src/eventos/dto/actualizarEvento.dto.ts @@ -5,7 +5,7 @@ export class actualizarEventoDto { proyecto?: string; modalidad?: string; lugar?: string; - requisitos?: string; + observaciones?: string; cuota_inscripcion?: number; patrocinador?: string; tipo_acreditacion?: string; diff --git a/src/eventos/dto/crearEvento.dto.ts b/src/eventos/dto/crearEvento.dto.ts index 53387e3..5a2cac6 100644 --- a/src/eventos/dto/crearEvento.dto.ts +++ b/src/eventos/dto/crearEvento.dto.ts @@ -6,7 +6,7 @@ export class crearEventoDto { modalidad: string; lugar: string; cupo: number; - requisitos: string; + observaciones: string; cuota_inscripcion: number; patrocinador: string; tipo_acreditacion: string; diff --git a/src/eventos/evento.entity.ts b/src/eventos/evento.entity.ts index 0b8bedd..e4abbcc 100644 --- a/src/eventos/evento.entity.ts +++ b/src/eventos/evento.entity.ts @@ -14,52 +14,52 @@ export class Evento { @PrimaryGeneratedColumn() id_evento: number; - @Column({length: 70, nullable: false }) + @Column({ length: 70, nullable: false }) nombre: string; - - @Column({length: 15, nullable: false }) + + @Column({ length: 15, nullable: false }) tipo_evento: string; - @Column({length: 100,nullable: false}) - organizadores: string + @Column({ length: 100, nullable: false }) + organizadores: string; - @Column({length:30 ,nullable: true}) - proyecto: string - - @Column({length: 40,nullable: false}) - modalidad: string - - @Column({length: 60,nullable: false }) + @Column({ length: 30, nullable: true }) + proyecto: string; + + @Column({ length: 40, nullable: false }) + modalidad: string; + + @Column({ length: 60, nullable: false }) lugar: string; - @Column({nullable: false}) + @Column({ nullable: false }) cupo: number; - @Column({length: 60, nullable: false }) - requisitos: string; + @Column({ length: 300, nullable: false }) + observaciones: string; - @Column({type:'decimal', precision: 7, scale: 2, nullable: true }) + @Column({ type: 'decimal', precision: 7, scale: 2, nullable: true }) cuota_inscripcion: number; - @Column({length: 50, nullable: true }) + @Column({ length: 50, nullable: true }) patrocinador: string; - @Column({length: 40, nullable: true }) + @Column({ length: 40, nullable: true }) tipo_acreditacion: string; - @Column({length: 200 ,nullable: false}) - objetivo: string + @Column({ length: 200, nullable: false }) + objetivo: 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({length:40 ,nullable: true }) + @Column({ length: 40, nullable: true }) horario: string; @Column({ nullable: true }) @@ -71,9 +71,6 @@ export class Evento { ) eventoParticipantes: EventoParticipante[]; - @OneToMany( - () => EquipoEvento, (equipoEvento) => equipoEvento.evento - ) - equipoEvento: EquipoEvento - + @OneToMany(() => EquipoEvento, (equipoEvento) => equipoEvento.evento) + equipoEvento: EquipoEvento; }