fixed create alumno inscrito
This commit is contained in:
@@ -35,7 +35,7 @@ export class AlumnoService {
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student not found`);
|
||||
throw new NotFoundException(`Numero de cuenta ${id_cuenta} no existente`);
|
||||
}
|
||||
|
||||
return student;
|
||||
|
||||
@@ -28,8 +28,8 @@ export class AlumnoInscritoController {
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findById(id_cuenta);
|
||||
}
|
||||
//pruebas borrar
|
||||
@Patch('platica/:idCuenta/:idPeriodo/:idPlataforma')
|
||||
//pruebas borrar
|
||||
@Patch('platica/:idCuenta/:idPeriodo/:idPlataforma')
|
||||
marcarPlatica(
|
||||
@Param('idCuenta') idCuenta: number,
|
||||
@Param('idPeriodo') idPeriodo: number,
|
||||
|
||||
@@ -4,9 +4,10 @@ import { AlumnoInscritoController } from './alumno_inscrito.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { BitacoraMesa } from 'src/bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
import { PeriodoModule } from 'src/periodo/periodo.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito,Plataforma,BitacoraMesa])],
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito,Plataforma,BitacoraMesa]),PeriodoModule],
|
||||
controllers: [AlumnoInscritoController],
|
||||
providers: [AlumnoInscritoService],
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CreateAlumnoInscritoDto } from './dto/create-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { PeriodoService } from 'src/periodo/periodo.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoInscritoService {
|
||||
@@ -15,13 +16,16 @@ export class AlumnoInscritoService {
|
||||
private readonly alumnoInscritoRepo: Repository<AlumnoInscrito>,
|
||||
@InjectRepository(Plataforma)
|
||||
private readonly plataformaRepo: Repository<Plataforma>,
|
||||
private readonly periodoService:PeriodoService
|
||||
) {}
|
||||
|
||||
async create(dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
const periodoActivo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const existing = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta: dto.id_cuenta },
|
||||
periodo: { id_periodo: dto.id_periodo },
|
||||
periodo: { id_periodo: periodoActivo.id_periodo },
|
||||
plataforma: { id_plataforma: dto.id_plataforma },
|
||||
},
|
||||
});
|
||||
@@ -32,7 +36,13 @@ export class AlumnoInscritoService {
|
||||
);
|
||||
}
|
||||
|
||||
const alumnoInscrito = this.alumnoInscritoRepo.create(dto);
|
||||
const alumnoInscrito = this.alumnoInscritoRepo.create({
|
||||
realizo_pago: dto.realizo_pago ?? false,
|
||||
alumno: { id_cuenta: dto.id_cuenta },
|
||||
plataforma: { id_plataforma: dto.id_plataforma },
|
||||
periodo: periodoActivo,
|
||||
});
|
||||
|
||||
return this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,10 @@ export class CreateAlumnoInscritoDto {
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_periodo: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_plataforma: number;
|
||||
|
||||
@IsBoolean()
|
||||
realizo_pago?: boolean;
|
||||
|
||||
@IsNumber()
|
||||
tiempo_disponible?: number;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ import { Periodo } from './entities/periodo.entity';
|
||||
imports:[TypeOrmModule.forFeature([Periodo])],
|
||||
controllers: [PeriodoController],
|
||||
providers: [PeriodoService],
|
||||
exports:[PeriodoService]
|
||||
})
|
||||
export class PeriodoModule {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Periodo } from './entities/periodo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -14,7 +14,20 @@ export class PeriodoService {
|
||||
return this.periodoRepository.findOne({ where: {} });
|
||||
}
|
||||
|
||||
async findAll(){
|
||||
async findAll() {
|
||||
return this.periodoRepository.find();
|
||||
}
|
||||
|
||||
async getPeriodoActivo(): Promise<Periodo> {
|
||||
const periodo = await this.periodoRepository.findOne({
|
||||
where: { activo: true },
|
||||
order: { id_periodo: 'DESC' },
|
||||
});
|
||||
|
||||
if (!periodo) {
|
||||
throw new NotFoundException('No hay periodos activos');
|
||||
}
|
||||
|
||||
return periodo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user