falta update
This commit is contained in:
@@ -7,6 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InstitucionPrograma } from './entity/institucion-programa.entity';
|
||||
import { Programa } from './entity/programa.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionProgramaService {
|
||||
@@ -15,6 +16,7 @@ export class InstitucionProgramaService {
|
||||
private institucionProgramaRepository: Repository<InstitucionPrograma>,
|
||||
@InjectRepository(Programa)
|
||||
private programaRepository: Repository<Programa>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
create(programa: string) {
|
||||
@@ -27,25 +29,52 @@ export class InstitucionProgramaService {
|
||||
this.programaRepository.create({ programa }),
|
||||
);
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente el programa.' }));
|
||||
.then(async (programa) => {
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionProgramaRepository.save(
|
||||
this.institucionProgramaRepository.create({
|
||||
programa,
|
||||
institucion: instituciones[i],
|
||||
}),
|
||||
);
|
||||
return { message: 'Se creó correctamente el programa.' };
|
||||
});
|
||||
}
|
||||
|
||||
findAll() {
|
||||
findAllProgramas() {
|
||||
return this.programaRepository.find();
|
||||
}
|
||||
|
||||
findById(id_programa: number) {
|
||||
findProgramaById(id_programa: number) {
|
||||
return this.programaRepository.findOne({ id_programa }).then((programa) => {
|
||||
if (!programa) throw new NotFoundException('No existe este programa.');
|
||||
return programa;
|
||||
});
|
||||
}
|
||||
|
||||
findByPrograma(programa: string, validarNoExiste = true) {
|
||||
findProgramaByPrograma(programa: string, validarNoExiste = true) {
|
||||
return this.programaRepository.findOne({ programa }).then((programa) => {
|
||||
if (validarNoExiste && !programa)
|
||||
throw new NotFoundException('No existe este programa.');
|
||||
return programa;
|
||||
});
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.institucionProgramaRepository.find({ institucion }),
|
||||
);
|
||||
}
|
||||
|
||||
findAllByIdInstitucionMostrar(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.institucionProgramaRepository.find({ institucion, mostrar: true }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user