creacion de dto para event y algunos servicios

This commit is contained in:
jorge alvarado
2023-02-13 13:24:30 -06:00
parent d88679f854
commit bc84b7d63d
9 changed files with 307 additions and 69 deletions
-22
View File
@@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
+4 -5
View File
@@ -1,12 +1,11 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { EventsController } from './events/events.controller';
import { EventsService } from './events/events.service';
import { eventsModule } from './events/events.module';
@Module({
imports: [],
controllers: [AppController, EventsController],
providers: [AppService, EventsService],
imports: [eventsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
+55
View File
@@ -0,0 +1,55 @@
import { IsString } from "class-validator";
import { IsBoolean, IsDate, IsNumber } from "class-validator";
export class CreateEventDto {
@IsNumber()
id_event: number
@IsString()
event_name: string
@IsString()
desciption:string
@IsNumber()
limit: number
@IsDate()
start_date:Date
@IsDate()
end_date:Date
@IsDate()
regitration_deadline:Date
@IsString()
start_time:string
@IsString()
end_time:string
@IsString()
requirements: string
@IsString()
modality: string
@IsString()
place: string
@IsNumber()
registration_fee: number
@IsString()
sponsor: string
@IsString()
type_acreditation: string
@IsString()
event_type: string
@IsBoolean()
active: boolean
}
+50 -16
View File
@@ -1,18 +1,52 @@
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class event {
//evento_identificador:string
id_event: number //id_evento
event_name: string //nombre
desciption:string //descripcion
start_date:Date //fecha_inicio
end_date:Date //fecha_fin
regitration_deadline:Date //fecha_limite_inscripcionme
schedule:Date //horarior
requirements: string
modality: string //modalidad
place: string //lugar
registration_fee: string //cuota_inscripcionl
sponsor: string //patrocinador
type_acreditation: string //tipo_acreditacion
event_type: string //tipo_evento
state: boolean //estado
@PrimaryGeneratedColumn()
id_evento: number
@Column()
evento_identificador: string
@Column()
nombre: string
@Column()
fecha_inicio: Date
@Column()
fecha_fin: Date
@Column()
horario: string
@Column()
requisitos: string
@Column()
modalidad: string
@Column()
lugar: string
@Column()
cuota_inscripcion: number
@Column()
patrocinador: string
@Column()
tipo_acreditacion: string
@Column()
fecha_limite_inscripcion: string
@Column()
tipo_evento: string
@Column()
estado: boolean
@Column()
descripcion: string
}
+39 -24
View File
@@ -1,35 +1,50 @@
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post } from '@nestjs/common';
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Patch,
Post,
} from '@nestjs/common';
import { CreateEventDto } from './dto/create-event.dto';
import { event } from './event.entity';
import { EventsService } from './events.service';
@Controller('events')
export class EventsController {
@Get()
getEvents(): string{
return "Aqui irán los eventos"
}
constructor(private readonly eventsServices: EventsService) {}
/* @Get(':id')
@Get()
getEvents(): event[] {
return this.eventsServices.getEvents();
}
/* @Get(':id')
getEvent(@Param() params){
return `El evento que estamos llamando es: ${params.id}`
} */
@Get(':id')
getEvent(@Param('id') id: string): string{
return `El evento que estamos llamando es: ${id}`
}
@Get(':id')
getEvent(@Param('id') id: string): event {
return this.eventsServices.getEvent(parseInt(id));
}
@Post()
/* @HttpCode(HttpStatus.NO_CONTENT) esta linea es para no teornar nada*/
createEvent(@Body('message') message: string){
return `el evento creado es: ${message}`
}
@Post()
createEvent(@Body() body: CreateEventDto): string {
this.eventsServices.createEvent(body);
return 'evento creado con exito';
}
@Delete(':id')
deleteEvent(@Param('id') id:string): string{
return `Estamos borrando el evento: ${id}`
}
@Delete(':id')
deleteEvent(@Param('id') id: string) {
return this.eventsServices.deleteEvent(parseInt(id));
}
@Patch(':id')
updateEvent(@Param('id') id:string, @Body() body){
return `Actualizando el evento: ${id}`
}
}
@Patch(':id')
updateEvent(@Param('id') id: string, @Body() body) {
return `Actualizando el evento: ${id}`;
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { EventsController } from "./events.controller";
import { EventsService } from "./events.service";
@Module({
controllers: [EventsController],
providers: [EventsService],
})
export class eventsModule {}
+67 -2
View File
@@ -1,6 +1,71 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { event } from './event.entity';
import * as moment from 'moment';
import { CreateEventDto } from './dto/create-event.dto';
@Injectable()
export class EventsService {
private events: event[] = [
{
id_event: 1, //id_evento
event_name: 'Platica de ejemplo', //nombre
desciption: 'Esta platica servira como ejemplo', //descripcion
limit: 30, //limite
start_date: new Date('2023-02-20'), //fecha_inicio
end_date: new Date('2023-02-20'), //fecha_fin
regitration_deadline: new Date('2023-02-19'), //fecha_limite_inscripcionme
start_time: '13:00', //hora de inicio
end_time: '14:00', //hora de fin
requirements: 'Sin requerimientos de hardware ni conocimiento',
modality: 'mixta', //modalidad
place: 'CEDETEC', //lugar
registration_fee: 0.0, //cuota_inscripcionl
sponsor: 'CIDWA', //patrocinador
type_acreditation: 'nose', //tipo_acreditacion
event_type: 'Platica', //tipo_evento
active: true, //estado
}
];
getEvents(): event[]{
return this.events
}
getEvent(id: number): event{
const eventGetting = this.events.find((item) => item.id_event === id);
if(!eventGetting){
throw new NotFoundException("Evento no encontrado")
}
return eventGetting
}
createEvent(body: CreateEventDto){
this.events.push({
id_event: (Math.floor(Math.random()*20000) + 1 ),
event_name: body.event_name,
desciption: body.desciption,
limit: body.limit,
start_date: body.start_date,
end_date: body.end_date,
regitration_deadline: body.regitration_deadline,
start_time: body.start_time,
end_time: body.end_time,
requirements: body.requirements,
modality: body.modality,
place: body.place,
registration_fee: body.registration_fee,
sponsor: body.sponsor,
type_acreditation: body.type_acreditation,
event_type: body.event_type,
active: body.active,
})
}
deleteEvent(id: number){
const index = this.events.findIndex((event) => event.id_event === id);
if(index >= 0){
this.events.splice(index, 1)
}
}
}