diff --git a/src/alumno_inscrito/alumno_inscrito.service.ts b/src/alumno_inscrito/alumno_inscrito.service.ts index 7e1926a..e2d1a2a 100644 --- a/src/alumno_inscrito/alumno_inscrito.service.ts +++ b/src/alumno_inscrito/alumno_inscrito.service.ts @@ -37,7 +37,7 @@ export class AlumnoInscritoService { async findByAlumno(id_cuenta: number): Promise { return this.alumnoInscritoRepo.find({ - where: { alumno: { id_cuenta } }, + where: { alumno: { id_cuenta }, periodo:{id_periodo:24}}, relations: ['alumno', 'periodo', 'plataforma'], }); } diff --git a/src/alumno_sancion/alumno_sancion.controller.ts b/src/alumno_sancion/alumno_sancion.controller.ts index 3589235..248f809 100644 --- a/src/alumno_sancion/alumno_sancion.controller.ts +++ b/src/alumno_sancion/alumno_sancion.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Post } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common'; import { AlumnoSancionService } from './alumno_sancion.service'; import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto'; @@ -11,14 +11,14 @@ export class AlumnoSancionController { return this.alumnoSancionService.create(createAlumnoSancionDto); } - @Get() - findAll() { - return this.alumnoSancionService.findAll(); + @Get(':id') + findbyStudent(@Param('id') id: number) { + return this.alumnoSancionService.findbyStudent(+id); } - @Get(':id') - findOne(@Param('id') id: number) { - return this.alumnoSancionService.findOne(+id); + @Delete() + deleteSancion(){ + } } //IO \ No newline at end of file diff --git a/src/alumno_sancion/alumno_sancion.service.ts b/src/alumno_sancion/alumno_sancion.service.ts index b41c0f7..88c2efd 100644 --- a/src/alumno_sancion/alumno_sancion.service.ts +++ b/src/alumno_sancion/alumno_sancion.service.ts @@ -36,16 +36,25 @@ export class AlumnoSancionService { return await this.alumnosancionRepository.save(alumnosancion); } - findAll() { - return `This action returns all alumnoSancion`; - } - - async findOne(id_cuenta: number): Promise { - const alusancion = await this.alumnosancionRepository.findOne({ + async findbyStudent(id_cuenta: number): Promise { + const alusancion = await this.alumnosancionRepository.find({ where: { alumno: { id_cuenta } }, + select:{ + id_alumno_sancion:true, + fecha_inicio:true, + alumno:{ + id_cuenta:true, + nombre:true + }, + sancion:{ + id_sancion:true, + sancion:true, + duracion:true + } + } }); if (!alusancion) { - throw new NotFoundException(`Student with ID ${id_cuenta} not found`); + throw new NotFoundException(`student without sancion`); } return alusancion; } diff --git a/src/app.module.ts b/src/app.module.ts index f1f5a31..7c3223c 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -30,6 +30,12 @@ import { import { EquipoModule } from './equipo/equipo.module'; import { CarreraModule } from './carrera/carrera.module'; import { Carrera } from './carrera/entities/carrera.entity'; +import { Equipo } from './equipo/entities/equipo.entity'; +import { AreaUbicacionModule } from './area_ubicacion/area_ubicacion.module'; +import { ProgramaModule } from './programa/programa.module'; +import { AreaUbicacion } from './area_ubicacion/entities/area_ubicacion.entity'; +import { Programa } from './programa/entities/programa.entity'; +import { ProgramaEquipoModule } from './programa_equipo/programa_equipo.module'; @Module({ imports: [ @@ -60,6 +66,9 @@ import { Carrera } from './carrera/entities/carrera.entity'; Mesa, AlumnoInscrito, Plataforma, + Equipo, + AreaUbicacion, + Programa, ], synchronize: false, //Never change to true in production! }), @@ -77,6 +86,9 @@ import { Carrera } from './carrera/entities/carrera.entity'; AlumnoInscritoModule, EquipoModule, CarreraModule, + AreaUbicacionModule, + ProgramaModule, + ProgramaEquipoModule, ], controllers: [AppController], providers: [AppService], diff --git a/src/area_ubicacion/area_ubicacion.controller.ts b/src/area_ubicacion/area_ubicacion.controller.ts new file mode 100644 index 0000000..966749f --- /dev/null +++ b/src/area_ubicacion/area_ubicacion.controller.ts @@ -0,0 +1,18 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { AreaUbicacionService } from './area_ubicacion.service'; + +@Controller('area-ubicacion') +export class AreaUbicacionController { + constructor(private readonly areaUbicacionService: AreaUbicacionService) {} + + @Get() + findAll() { + return this.areaUbicacionService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.areaUbicacionService.findOne(+id); + } +} +//IO diff --git a/src/area_ubicacion/area_ubicacion.module.ts b/src/area_ubicacion/area_ubicacion.module.ts new file mode 100644 index 0000000..147d28b --- /dev/null +++ b/src/area_ubicacion/area_ubicacion.module.ts @@ -0,0 +1,13 @@ +import { Module } from '@nestjs/common'; +import { AreaUbicacionService } from './area_ubicacion.service'; +import { AreaUbicacionController } from './area_ubicacion.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { AreaUbicacion } from './entities/area_ubicacion.entity'; + +@Module({ + imports:[TypeOrmModule.forFeature([AreaUbicacion])], + controllers: [AreaUbicacionController], + providers: [AreaUbicacionService], +}) +export class AreaUbicacionModule {} +//IO \ No newline at end of file diff --git a/src/area_ubicacion/area_ubicacion.service.ts b/src/area_ubicacion/area_ubicacion.service.ts new file mode 100644 index 0000000..65279ab --- /dev/null +++ b/src/area_ubicacion/area_ubicacion.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { AreaUbicacion } from './entities/area_ubicacion.entity'; +import { Repository } from 'typeorm'; + +@Injectable() +export class AreaUbicacionService { + constructor( + @InjectRepository(AreaUbicacion) + private readonly areaUbicacionRepository: Repository, + ) {} + findAll() { + return this.areaUbicacionRepository.find(); + } + + findOne(id_area_ubicacion: number) { + const area = this.areaUbicacionRepository.findOne({ + where: { id_area_ubicacion }, + }); + + if(!area){ + return "this area dosnt exist" + } + + return area + } +} +//IO diff --git a/src/area_ubicacion/entities/area_ubicacion.entity.ts b/src/area_ubicacion/entities/area_ubicacion.entity.ts new file mode 100644 index 0000000..eab5fc0 --- /dev/null +++ b/src/area_ubicacion/entities/area_ubicacion.entity.ts @@ -0,0 +1,18 @@ +import { Equipo } from 'src/equipo/entities/equipo.entity'; +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'; + +@Entity({ name: 'area_ubicacion' }) +export class AreaUbicacion { + @PrimaryGeneratedColumn({ name: 'id_area_ubicacion' }) + id_area_ubicacion: number; + + @Column({ type: 'varchar', length: 45, nullable: false }) + area: string; + + @Column({ type: 'char', length: 1, default: '0', nullable: false }) + extra: string; + + @OneToMany(() => Equipo, (equipo) => equipo.areaUbicacion) + equipos: Equipo[]; +} +//IO diff --git a/src/equipo/entities/equipo.entity.ts b/src/equipo/entities/equipo.entity.ts index 3e819ef..d8faee5 100644 --- a/src/equipo/entities/equipo.entity.ts +++ b/src/equipo/entities/equipo.entity.ts @@ -1,3 +1,5 @@ +import { AreaUbicacion } from 'src/area_ubicacion/entities/area_ubicacion.entity'; +import { ProgramaEquipo } from 'src/programa_equipo/entities/programa_equipo.entity'; import { Entity, PrimaryGeneratedColumn, @@ -21,22 +23,6 @@ export class Plataforma { equipos: Equipo[]; } -@Entity({ name: 'area_ubicacion' }) -export class AreaUbicacion { - @PrimaryGeneratedColumn({ name: 'id_area_ubicacion', type: 'int' }) - id_area_ubicacion: number; - - @Column({ name: 'area', type: 'varchar', length: 45 }) - area: string; - - @Column({ name: 'extra', type: 'char', length: 1, default: '0' }) - extra: string; - - // Relación con equipos - @OneToMany(() => Equipo, (equipo) => equipo.areaUbicacion) - equipos: Equipo[]; -} - @Entity({ name: 'equipo' }) @Unique('indice_unico_ubicacion', ['ubicacion']) export class Equipo { @@ -77,4 +63,7 @@ export class Equipo { }) @JoinColumn({ name: 'id_area_ubicacion' }) areaUbicacion: AreaUbicacion; + + @OneToMany(() => ProgramaEquipo, (programaEquipo) => programaEquipo.equipo) + programaEquipos: ProgramaEquipo[]; } diff --git a/src/equipo/equipo.controller.ts b/src/equipo/equipo.controller.ts index ccd3841..6bb6675 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -1,7 +1,5 @@ import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; import { EquipoService } from './equipo.service'; -import { CreateEquipoDto } from './dto/create-equipo.dto'; -import { UpdateEquipoDto } from './dto/update-equipo.dto'; @Controller('equipo') export class EquipoController { @@ -13,7 +11,8 @@ export class EquipoController { } @Get(':id') - findOne(@Param('id') id: string) { + findOne(@Param('id') id: number) { return this.equipoService.findOne(+id); } } +//IO \ No newline at end of file diff --git a/src/equipo/equipo.module.ts b/src/equipo/equipo.module.ts index 2b3b33e..2b98b19 100644 --- a/src/equipo/equipo.module.ts +++ b/src/equipo/equipo.module.ts @@ -10,3 +10,4 @@ import { Equipo } from './entities/equipo.entity'; providers: [EquipoService], }) export class EquipoModule {} +//IO \ No newline at end of file diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index a697f12..80bdd02 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@nestjs/common'; -import { CreateEquipoDto } from './dto/create-equipo.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Equipo } from './entities/equipo.entity'; @@ -17,3 +16,4 @@ private readonly equipoRepository: Repository){} return this.equipoRepository.findOne({where:{id_equipo}}); } } +//IO \ No newline at end of file diff --git a/src/programa/dto/create-programa.dto.ts b/src/programa/dto/create-programa.dto.ts new file mode 100644 index 0000000..3b00753 --- /dev/null +++ b/src/programa/dto/create-programa.dto.ts @@ -0,0 +1 @@ +export class CreateProgramaDto {} diff --git a/src/programa/dto/update-programa.dto.ts b/src/programa/dto/update-programa.dto.ts new file mode 100644 index 0000000..1ab1cec --- /dev/null +++ b/src/programa/dto/update-programa.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateProgramaDto } from './create-programa.dto'; + +export class UpdateProgramaDto extends PartialType(CreateProgramaDto) {} diff --git a/src/programa/entities/programa.entity.ts b/src/programa/entities/programa.entity.ts new file mode 100644 index 0000000..1238c7a --- /dev/null +++ b/src/programa/entities/programa.entity.ts @@ -0,0 +1,14 @@ +import { ProgramaEquipo } from 'src/programa_equipo/entities/programa_equipo.entity'; +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'; + +@Entity({ name: 'programa' }) +export class Programa { + @PrimaryGeneratedColumn({ name: 'id_programa' }) + id_programa: number; + + @Column({ type: 'varchar', length: 45, nullable: false }) + programa: string; + + @OneToMany(() => ProgramaEquipo, (programaEquipo) => programaEquipo.programa) + programaEquipos: ProgramaEquipo[]; +} diff --git a/src/programa/programa.controller.ts b/src/programa/programa.controller.ts new file mode 100644 index 0000000..f5a0974 --- /dev/null +++ b/src/programa/programa.controller.ts @@ -0,0 +1,30 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { ProgramaService } from './programa.service'; +import { CreateProgramaDto } from './dto/create-programa.dto'; +import { UpdateProgramaDto } from './dto/update-programa.dto'; + +@Controller('programa') +export class ProgramaController { + constructor(private readonly programaService: ProgramaService) {} + + @Post() + create(@Body() createProgramaDto: CreateProgramaDto) { + return this.programaService.create(createProgramaDto); + } + + @Get() + findAll() { + return this.programaService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.programaService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) { + return this.programaService.update(+id, updateProgramaDto); + } + +} diff --git a/src/programa/programa.module.ts b/src/programa/programa.module.ts new file mode 100644 index 0000000..24fd0dc --- /dev/null +++ b/src/programa/programa.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ProgramaService } from './programa.service'; +import { ProgramaController } from './programa.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Programa } from './entities/programa.entity'; + +@Module({ + imports:[TypeOrmModule.forFeature([Programa])], + controllers: [ProgramaController], + providers: [ProgramaService], +}) +export class ProgramaModule {} diff --git a/src/programa/programa.service.ts b/src/programa/programa.service.ts new file mode 100644 index 0000000..26a6214 --- /dev/null +++ b/src/programa/programa.service.ts @@ -0,0 +1,36 @@ +import { Injectable } from '@nestjs/common'; +import { CreateProgramaDto } from './dto/create-programa.dto'; +import { UpdateProgramaDto } from './dto/update-programa.dto'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Programa } from './entities/programa.entity'; +import { Repository } from 'typeorm'; + +@Injectable() +export class ProgramaService { + constructor( + @InjectRepository(Programa) + private readonly programaRepository:Repository + ){} + create(createProgramaDto: CreateProgramaDto) { + return 'This action adds a new programa'; + } + + findAll() { + return this.programaRepository.find(); + } + + findOne(id_programa: number) { + const programa = this.programaRepository.findOne({where:{id_programa}}) + + if(!programa){ + return "this program dosnt exist" + } + + return programa; + } + + update(id: number, updateProgramaDto: UpdateProgramaDto) { + return `This action updates a #${id} programa`; + } + +} diff --git a/src/programa_equipo/dto/create-programa_equipo.dto.ts b/src/programa_equipo/dto/create-programa_equipo.dto.ts new file mode 100644 index 0000000..cc87c0e --- /dev/null +++ b/src/programa_equipo/dto/create-programa_equipo.dto.ts @@ -0,0 +1 @@ +export class CreateProgramaEquipoDto {} diff --git a/src/programa_equipo/dto/update-programa_equipo.dto.ts b/src/programa_equipo/dto/update-programa_equipo.dto.ts new file mode 100644 index 0000000..9eacc8b --- /dev/null +++ b/src/programa_equipo/dto/update-programa_equipo.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateProgramaEquipoDto } from './create-programa_equipo.dto'; + +export class UpdateProgramaEquipoDto extends PartialType(CreateProgramaEquipoDto) {} diff --git a/src/programa_equipo/entities/programa_equipo.entity.ts b/src/programa_equipo/entities/programa_equipo.entity.ts new file mode 100644 index 0000000..0927390 --- /dev/null +++ b/src/programa_equipo/entities/programa_equipo.entity.ts @@ -0,0 +1,24 @@ +import { Equipo } from "src/equipo/entities/equipo.entity"; +import { Programa } from "src/programa/entities/programa.entity"; +import { Entity, PrimaryColumn, ManyToOne, JoinColumn } from "typeorm"; + +@Entity("programa_equipo") +export class ProgramaEquipo { + @PrimaryColumn({ name: "id_programa", type: "int" }) + id_programa: number; + + @PrimaryColumn({ name: "id_equipo", type: "int" }) + id_equipo: number; + + @ManyToOne(() => Programa, (programa) => programa.programaEquipos, { + onUpdate: "CASCADE", + }) + @JoinColumn({ name: "id_programa" }) + programa: Programa; + + @ManyToOne(() => Equipo, (equipo) => equipo.programaEquipos, { + onUpdate: "CASCADE", + }) + @JoinColumn({ name: "id_equipo" }) + equipo: Equipo; +} diff --git a/src/programa_equipo/programa_equipo.controller.ts b/src/programa_equipo/programa_equipo.controller.ts new file mode 100644 index 0000000..21d10f2 --- /dev/null +++ b/src/programa_equipo/programa_equipo.controller.ts @@ -0,0 +1,24 @@ +import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { ProgramaEquipoService } from './programa_equipo.service'; +import { CreateProgramaEquipoDto } from './dto/create-programa_equipo.dto'; +import { UpdateProgramaEquipoDto } from './dto/update-programa_equipo.dto'; + +@Controller('programa-equipo') +export class ProgramaEquipoController { + constructor(private readonly programaEquipoService: ProgramaEquipoService) {} + + @Get() + findAll() { + return this.programaEquipoService.findAll(); + } + + @Get(':id') + findOne(@Param('id') id: string) { + return this.programaEquipoService.findOne(+id); + } + + @Patch(':id') + update(@Param('id') id: string, @Body() updateProgramaEquipoDto: UpdateProgramaEquipoDto) { + return this.programaEquipoService.update(+id, updateProgramaEquipoDto); + } +} diff --git a/src/programa_equipo/programa_equipo.module.ts b/src/programa_equipo/programa_equipo.module.ts new file mode 100644 index 0000000..0e1d104 --- /dev/null +++ b/src/programa_equipo/programa_equipo.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ProgramaEquipoService } from './programa_equipo.service'; +import { ProgramaEquipoController } from './programa_equipo.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { ProgramaEquipo } from './entities/programa_equipo.entity'; + +@Module({ + imports:[TypeOrmModule.forFeature([ProgramaEquipo])], + controllers: [ProgramaEquipoController], + providers: [ProgramaEquipoService], +}) +export class ProgramaEquipoModule {} diff --git a/src/programa_equipo/programa_equipo.service.ts b/src/programa_equipo/programa_equipo.service.ts new file mode 100644 index 0000000..74d0796 --- /dev/null +++ b/src/programa_equipo/programa_equipo.service.ts @@ -0,0 +1,34 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { CreateProgramaEquipoDto } from './dto/create-programa_equipo.dto'; +import { UpdateProgramaEquipoDto } from './dto/update-programa_equipo.dto'; +import { InjectRepository } from '@nestjs/typeorm'; +import { ProgramaEquipo } from './entities/programa_equipo.entity'; +import { Repository } from 'typeorm'; + +@Injectable() +export class ProgramaEquipoService { + constructor( + @InjectRepository(ProgramaEquipo) + private readonly ProgramaEquipoRepository: Repository, + ) {} + + findAll() { + return `This action returns all programaEquipo`; + } + + async findOne(id_equipo: number) { + const equipo = await this.ProgramaEquipoRepository.find({ + where: { id_equipo }, + }); + + if (equipo.length === 0) { + throw new NotFoundException(`machine without programs`); + } + + return equipo; + } + + update(id: number, updateProgramaEquipoDto: UpdateProgramaEquipoDto) { + return `This action updates a #${id} programaEquipo`; + } +} diff --git a/src/recibo/dto/create-recibo.dto.ts b/src/recibo/dto/create-recibo.dto.ts index 9cfa372..71e59fd 100644 --- a/src/recibo/dto/create-recibo.dto.ts +++ b/src/recibo/dto/create-recibo.dto.ts @@ -1,5 +1,5 @@ import { Type } from 'class-transformer'; -import { IsDate, IsNumber, IsString } from 'class-validator'; +import { IsDate, IsDateString, IsNumber, IsString } from 'class-validator'; export class CreateReciboDto { @@ -13,3 +13,11 @@ export class CreateReciboDto { @Type(() => Date) fecha_recibo: Date; } + +export class FindReciboByRangeDto { + @IsDateString() + desde: string; + + @IsDateString() + hasta: string; +} \ No newline at end of file diff --git a/src/recibo/entities/recibo.entity.ts b/src/recibo/entities/recibo.entity.ts index 1609f67..293b0fc 100644 --- a/src/recibo/entities/recibo.entity.ts +++ b/src/recibo/entities/recibo.entity.ts @@ -29,13 +29,13 @@ export class Recibo { monto: number; @Column({ name: 'fecha_recibo', type: 'date', nullable: false }) - fecha_recibo: Date ; + fecha_recibo: Date; - @ManyToOne(() => Alumno, (alum) => alum.id_cuenta, {}) + @ManyToOne(() => Alumno, (alum) => alum.id_cuenta, { eager: true }) @JoinColumn({ name: 'id_cuenta' }) alum: Alumno; - @ManyToOne(() => User, (user) => user.id_usuario, {}) + @ManyToOne(() => User, (user) => user.id_usuario, { eager: true }) @JoinColumn({ name: 'id_usuario' }) user: User; } diff --git a/src/recibo/recibo.controller.ts b/src/recibo/recibo.controller.ts index 57c0747..2185030 100644 --- a/src/recibo/recibo.controller.ts +++ b/src/recibo/recibo.controller.ts @@ -6,10 +6,15 @@ import { Req, } from '@nestjs/common'; import { ReciboService } from './recibo.service'; +import { FindReciboByRangeDto } from './dto/create-recibo.dto'; @Controller('recibo') export class ReciboController { constructor(private readonly reciboService: ReciboService) {} + @Post('rango') + async findByDateRange(@Body() data: FindReciboByRangeDto) { + return this.reciboService.findByDateRange(data.desde, data.hasta); + } } //IO diff --git a/src/recibo/recibo.service.ts b/src/recibo/recibo.service.ts index 9dd5344..ed419f4 100644 --- a/src/recibo/recibo.service.ts +++ b/src/recibo/recibo.service.ts @@ -1,7 +1,7 @@ -import { ConflictException, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Recibo } from './entities/recibo.entity'; -import { EntityManager, Repository } from 'typeorm'; +import { Between, EntityManager, Repository } from 'typeorm'; import { CreateReciboDto } from './dto/create-recibo.dto'; @Injectable() @@ -23,5 +23,17 @@ export class ReciboService { const details = repo.create(data); return await repo.save(details); } + + async findByDateRange(desde: string, hasta: string) { + // Convertimos strings a objetos Date + const fechaDesde = new Date(desde); + const fechaHasta = new Date(hasta); + + return await this.reciboRepository.find({ + where: { + fecha_recibo: Between(fechaDesde, fechaHasta), + }, + }); + } } //IO