modulo institución tipo entrada final
This commit is contained in:
@@ -11,11 +11,9 @@ export class EquipoTipoEntrada {
|
||||
@JoinColumn({ name: 'id_equipo' })
|
||||
equipo: Equipo;
|
||||
|
||||
@ManyToOne(
|
||||
() => TipoEntrada,
|
||||
(tipoEntrada) => tipoEntrada.equiposTipoEntrada,
|
||||
{ eager: true },
|
||||
)
|
||||
@ManyToOne(() => TipoEntrada, (tipoEntrada) => tipoEntrada.equipos, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_tipo_entrada' })
|
||||
tipoEntrada: TipoEntrada;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Not, Repository } from 'typeorm';
|
||||
import { Carrera } from '../institucion-carrera/entity/carrera.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionCarrera } from './entity/institucion-carrera.entity';
|
||||
import { Nivel } from './entity/nivel.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -13,7 +12,6 @@ export class InstitucionCarreraService {
|
||||
@InjectRepository(Carrera) private carreraRepository: Repository<Carrera>,
|
||||
@InjectRepository(InstitucionCarrera)
|
||||
private institucionCarreraRepository: Repository<InstitucionCarrera>,
|
||||
@InjectRepository(Carrera) private nivelRepository: Repository<Nivel>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
|
||||
@@ -13,50 +13,50 @@ import { InstitucionService } from '../institucion/institucion.service';
|
||||
export class InstitucionInfraccionService {
|
||||
constructor(
|
||||
@InjectRepository(Infraccion)
|
||||
private repositoryInfraccion: Repository<Infraccion>,
|
||||
private infraccionRepository: Repository<Infraccion>,
|
||||
@InjectRepository(InstitucionInfraccion)
|
||||
private repositoryInstitucionInfraccion: Repository<InstitucionInfraccion>,
|
||||
private institucionInfraccionRepository: Repository<InstitucionInfraccion>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
create(infraccion: string) {
|
||||
return this.repositoryInfraccion
|
||||
return this.infraccionRepository
|
||||
.findOne({ infraccion })
|
||||
.then((existeInfraccion) => {
|
||||
if (existeInfraccion)
|
||||
throw new ConflictException('Ya existe esta infracción.');
|
||||
return this.repositoryInfraccion.save(
|
||||
this.repositoryInfraccion.create({ infraccion }),
|
||||
return this.infraccionRepository.save(
|
||||
this.infraccionRepository.create({ infraccion }),
|
||||
);
|
||||
})
|
||||
.then(async (infraccion) => {
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.repositoryInstitucionInfraccion.save(
|
||||
this.repositoryInstitucionInfraccion.create({
|
||||
await this.institucionInfraccionRepository.save(
|
||||
this.institucionInfraccionRepository.create({
|
||||
infraccion,
|
||||
institucion: instituciones[i],
|
||||
}),
|
||||
);
|
||||
return { message: 'Se creó creo correctamente una nueva infracción.' };
|
||||
return { message: 'Se creó correctamente una nueva infracción.' };
|
||||
});
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.repositoryInfraccion.find();
|
||||
return this.infraccionRepository.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number) {
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) =>
|
||||
this.repositoryInstitucionInfraccion.find({ institucion }),
|
||||
this.institucionInfraccionRepository.find({ institucion }),
|
||||
);
|
||||
}
|
||||
|
||||
findById(id_institucion_infraccion: number) {
|
||||
return this.repositoryInstitucionInfraccion
|
||||
return this.institucionInfraccionRepository
|
||||
.findOne({ id_institucion_infraccion })
|
||||
.then((institucionInfraccion) => {
|
||||
if (!institucionInfraccion)
|
||||
@@ -69,7 +69,7 @@ export class InstitucionInfraccionService {
|
||||
return this.findById(attrs.id_institucion_infraccion)
|
||||
.then((institucionInfraccion) => {
|
||||
Object.assign(institucionInfraccion, attrs);
|
||||
return this.repositoryInstitucionInfraccion.save(institucionInfraccion);
|
||||
return this.institucionInfraccionRepository.save(institucionInfraccion);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
|
||||
@@ -36,8 +36,8 @@ export class InstitucionProgramaService {
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionProgramaRepository.save(
|
||||
this.institucionProgramaRepository.create({
|
||||
programa,
|
||||
institucion: instituciones[i],
|
||||
programa,
|
||||
}),
|
||||
);
|
||||
return { message: 'Se creó correctamente un nuevo programa.' };
|
||||
|
||||
@@ -14,14 +14,14 @@ import { InstitucionService } from '../institucion/institucion.service';
|
||||
export class InstitucionTipoCarritoService {
|
||||
constructor(
|
||||
@InjectRepository(TipoCarrito)
|
||||
private repositoryTipoCarrito: Repository<TipoCarrito>,
|
||||
private tipoCarritoRepository: Repository<TipoCarrito>,
|
||||
@InjectRepository(InstitucionTipoCarrito)
|
||||
private repositoryInstitucionTipoCarrito: Repository<InstitucionTipoCarrito>,
|
||||
private institucionTipoCarritoRepository: Repository<InstitucionTipoCarrito>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
create(letra: string, tipo_carrito: string) {
|
||||
return this.repositoryTipoCarrito
|
||||
return this.tipoCarritoRepository
|
||||
.findOne({ where: [{ letra }, { tipo_carrito }] })
|
||||
.then((existeTipoCarrito) => {
|
||||
if (existeTipoCarrito) {
|
||||
@@ -34,16 +34,16 @@ export class InstitucionTipoCarritoService {
|
||||
'Ya existe un tipo carrito con este nombre, intente con otro nombre.',
|
||||
);
|
||||
}
|
||||
return this.repositoryTipoCarrito.save(
|
||||
this.repositoryTipoCarrito.create({ letra, tipo_carrito }),
|
||||
return this.tipoCarritoRepository.save(
|
||||
this.tipoCarritoRepository.create({ letra, tipo_carrito }),
|
||||
);
|
||||
})
|
||||
.then(async (tipoCarrito) => {
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.repositoryInstitucionTipoCarrito.save(
|
||||
this.repositoryInstitucionTipoCarrito.create({
|
||||
await this.institucionTipoCarritoRepository.save(
|
||||
this.institucionTipoCarritoRepository.create({
|
||||
institucion: instituciones[i],
|
||||
tipoCarrito,
|
||||
}),
|
||||
@@ -53,7 +53,7 @@ export class InstitucionTipoCarritoService {
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.repositoryTipoCarrito.find();
|
||||
return this.tipoCarritoRepository.find();
|
||||
}
|
||||
|
||||
async findAllByIdInstitucion(id_institucion: number, mostrar = false) {
|
||||
@@ -63,11 +63,11 @@ export class InstitucionTipoCarritoService {
|
||||
};
|
||||
|
||||
if (mostrar) busqueda.mostrar = mostrar;
|
||||
return this.repositoryInstitucionTipoCarrito.find(busqueda);
|
||||
return this.institucionTipoCarritoRepository.find(busqueda);
|
||||
}
|
||||
|
||||
findInstitucionTipoCarritoById(id_institucion_tipo_carrito) {
|
||||
return this.repositoryInstitucionTipoCarrito
|
||||
return this.institucionTipoCarritoRepository
|
||||
.findOne({
|
||||
id_institucion_tipo_carrito,
|
||||
})
|
||||
@@ -81,7 +81,7 @@ export class InstitucionTipoCarritoService {
|
||||
}
|
||||
|
||||
findTipoCarritoById(id_tipo_carrito: number) {
|
||||
return this.repositoryTipoCarrito
|
||||
return this.tipoCarritoRepository
|
||||
.findOne({ id_tipo_carrito })
|
||||
.then((tipoCarrito) => {
|
||||
if (!tipoCarrito)
|
||||
@@ -91,7 +91,7 @@ export class InstitucionTipoCarritoService {
|
||||
}
|
||||
|
||||
findTipoCarritoByTipoCarrito(tipo_carrito: string, validarNoExiste = true) {
|
||||
return this.repositoryTipoCarrito
|
||||
return this.tipoCarritoRepository
|
||||
.findOne({ tipo_carrito })
|
||||
.then((tipoCarrito) => {
|
||||
if (validarNoExiste && !tipoCarrito)
|
||||
@@ -106,7 +106,7 @@ export class InstitucionTipoCarritoService {
|
||||
)
|
||||
.then((institucionTipoCarrito) => {
|
||||
Object.assign(institucionTipoCarrito, attrs);
|
||||
return this.repositoryInstitucionTipoCarrito.save(
|
||||
return this.institucionTipoCarritoRepository.save(
|
||||
institucionTipoCarrito,
|
||||
);
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ export class TipoEntrada {
|
||||
() => EquipoTipoEntrada,
|
||||
(equipoTipoEntrada) => equipoTipoEntrada.tipoEntrada,
|
||||
)
|
||||
equiposTipoEntrada: EquipoTipoEntrada[];
|
||||
equipos: EquipoTipoEntrada[];
|
||||
|
||||
@OneToMany(
|
||||
() => InstitucionTipoEntrada,
|
||||
|
||||
@@ -62,8 +62,9 @@ export class InstitucionTipoEntradaController {
|
||||
type: 'string',
|
||||
})
|
||||
tipoEntradaMostrar(@Query() query: IdInstitucionDto) {
|
||||
return this.tipoEntradaService.findAllByIdInstitucionMostrar(
|
||||
return this.tipoEntradaService.findAllByIdInstitucion(
|
||||
parseInt(query.id_institucion),
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([InstitucionTipoEntrada, TipoEntrada]),
|
||||
InstitucionModule,
|
||||
TypeOrmModule.forFeature([InstitucionTipoEntrada, TipoEntrada]),
|
||||
],
|
||||
controllers: [InstitucionTipoEntradaController],
|
||||
providers: [InstitucionTipoEntradaService],
|
||||
|
||||
@@ -5,59 +5,65 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity';
|
||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionTipoEntradaService {
|
||||
constructor(
|
||||
@InjectRepository(InstitucionTipoEntrada)
|
||||
private repositoryInstitucionTipoEntrada: Repository<InstitucionTipoEntrada>,
|
||||
private institucionTipoEntradaRepository: Repository<InstitucionTipoEntrada>,
|
||||
@InjectRepository(TipoEntrada)
|
||||
private repositoryTipoEntrada: Repository<TipoEntrada>,
|
||||
private tipoEntradaRepository: Repository<TipoEntrada>,
|
||||
private institucionService: InstitucionService,
|
||||
) {}
|
||||
|
||||
async create(tipo_entrada: string) {
|
||||
// corregir
|
||||
return this.repositoryTipoEntrada
|
||||
return this.tipoEntradaRepository
|
||||
.findOne({ tipo_entrada })
|
||||
.then((existeTipoEntrada) => {
|
||||
if (existeTipoEntrada)
|
||||
throw new ConflictException('Ya existe este tipo de entrada.');
|
||||
return this.repositoryTipoEntrada.save(
|
||||
this.repositoryTipoEntrada.create({
|
||||
return this.tipoEntradaRepository.save(
|
||||
this.tipoEntradaRepository.create({
|
||||
tipo_entrada,
|
||||
}),
|
||||
);
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente la nueva entrada.' }));
|
||||
}
|
||||
.then(async (tipoEntrada) => {
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
findAll() {
|
||||
return this.repositoryTipoEntrada.find();
|
||||
}
|
||||
|
||||
findAllByIdInstitucion(id_institucion: number, mostrar = false) {
|
||||
const busqueda: { institucion?: Institucion; mostrar?: boolean } = {};
|
||||
|
||||
if (mostrar) busqueda.mostrar = mostrar;
|
||||
return this.institucionService
|
||||
.findById(id_institucion)
|
||||
.then((institucion) => {
|
||||
busqueda.institucion = institucion;
|
||||
return this.repositoryInstitucionTipoEntrada.find(busqueda);
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionTipoEntradaRepository.save(
|
||||
this.institucionTipoEntradaRepository.create({
|
||||
institucion: instituciones[i],
|
||||
tipoEntrada,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
message: 'Se creó correctamente un nuevo tipo de entrada.',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
findAllByIdInstitucionMostrar(id_institucion: number) {
|
||||
return this.findAllByIdInstitucion(id_institucion, true);
|
||||
findAll() {
|
||||
return this.tipoEntradaRepository.find();
|
||||
}
|
||||
|
||||
async findAllByIdInstitucion(id_institucion: number, mostrar = false) {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const busqueda: { institucion: Institucion; mostrar?: boolean } = {
|
||||
institucion,
|
||||
};
|
||||
|
||||
if (mostrar) busqueda.mostrar = mostrar;
|
||||
return this.institucionTipoEntradaRepository.find(busqueda);
|
||||
}
|
||||
|
||||
findById(id_institucion_tipo_entrada: number) {
|
||||
return this.repositoryInstitucionTipoEntrada
|
||||
return this.institucionTipoEntradaRepository
|
||||
.findOne({
|
||||
id_institucion_tipo_entrada,
|
||||
})
|
||||
@@ -71,7 +77,7 @@ export class InstitucionTipoEntradaService {
|
||||
}
|
||||
|
||||
findTipoEntradaById(id_tipo_entrada: number) {
|
||||
return this.repositoryTipoEntrada
|
||||
return this.tipoEntradaRepository
|
||||
.findOne({ id_tipo_entrada })
|
||||
.then((tipoEntrada) => {
|
||||
if (!tipoEntrada)
|
||||
@@ -81,7 +87,7 @@ export class InstitucionTipoEntradaService {
|
||||
}
|
||||
|
||||
findTipoEntradaByTipoEntrada(tipo_entrada: string, validarNoExiste = true) {
|
||||
return this.repositoryTipoEntrada
|
||||
return this.tipoEntradaRepository
|
||||
.findOne({ tipo_entrada })
|
||||
.then((tipoEntrada) => {
|
||||
if (validarNoExiste && !tipoEntrada)
|
||||
@@ -94,13 +100,12 @@ export class InstitucionTipoEntradaService {
|
||||
return this.findById(attrs.id_institucion_tipo_entrada)
|
||||
.then((institucionTipoEntrada) => {
|
||||
Object.assign(institucionTipoEntrada, attrs);
|
||||
return this.repositoryInstitucionTipoEntrada.save(
|
||||
return this.institucionTipoEntradaRepository.save(
|
||||
institucionTipoEntrada,
|
||||
);
|
||||
})
|
||||
.then((_) => ({
|
||||
message:
|
||||
'Se actualizó correctamente la información de la institución tipo entrada.',
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user