institucion tipo entrada service final
This commit is contained in:
parent
5b8e1ce628
commit
d1c7b25762
@ -31,7 +31,7 @@ export class InstitucionProgramaService {
|
|||||||
.then((existePrograma) => {
|
.then((existePrograma) => {
|
||||||
// Sacamos error si existe
|
// Sacamos error si existe
|
||||||
if (existePrograma)
|
if (existePrograma)
|
||||||
throw new ConflictException('Ya existe este programa.');
|
throw new ConflictException('Ya existe este software.');
|
||||||
// Creamos y guardamos un registro
|
// Creamos y guardamos un registro
|
||||||
return this.programaRepository.save(
|
return this.programaRepository.save(
|
||||||
this.programaRepository.create({ programa }),
|
this.programaRepository.create({ programa }),
|
||||||
@ -48,7 +48,7 @@ export class InstitucionProgramaService {
|
|||||||
programa,
|
programa,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return { message: 'Se creó correctamente un nuevo programa.' };
|
return { message: 'Se creó correctamente un nuevo software.' };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export class InstitucionTipoCarritoService {
|
|||||||
if (existeTipoCarrito) {
|
if (existeTipoCarrito) {
|
||||||
if (letra === existeTipoCarrito.letra)
|
if (letra === existeTipoCarrito.letra)
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
'Ya existe un tipo carrito con esta letra, intente con otra.',
|
'Ya existe un tipo de carrito con esta letra, intente con otra.',
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
|
@ -33,7 +33,7 @@ import { TipoEntradaOutputDto } from './dto/output/tipo-entrada.dto';
|
|||||||
@ApiTags('institucion-tipo-entrada')
|
@ApiTags('institucion-tipo-entrada')
|
||||||
export class InstitucionTipoEntradaController {
|
export class InstitucionTipoEntradaController {
|
||||||
constructor(
|
constructor(
|
||||||
private tipoEntradaService: InstitucionTipoEntradaService,
|
private institucionTipoEntradaService: InstitucionTipoEntradaService,
|
||||||
private validarUsuarioService: ValidarUsuarioService,
|
private validarUsuarioService: ValidarUsuarioService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ export class InstitucionTipoEntradaController {
|
|||||||
const superAdmin: Operador = req.user.operador;
|
const superAdmin: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarSuperAdmin(superAdmin);
|
this.validarUsuarioService.validarSuperAdmin(superAdmin);
|
||||||
return this.tipoEntradaService.create(body.tipo_entrada);
|
return this.institucionTipoEntradaService.create(body.tipo_entrada);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serealize(TipoEntradaOutputDto)
|
@Serealize(TipoEntradaOutputDto)
|
||||||
@ -62,7 +62,7 @@ export class InstitucionTipoEntradaController {
|
|||||||
const superAdmin: Operador = req.user.operador;
|
const superAdmin: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarSuperAdmin(superAdmin);
|
this.validarUsuarioService.validarSuperAdmin(superAdmin);
|
||||||
return this.tipoEntradaService.findAll();
|
return this.institucionTipoEntradaService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serealize(InstitucionTipoEntradaOutputDto)
|
@Serealize(InstitucionTipoEntradaOutputDto)
|
||||||
@ -76,9 +76,7 @@ export class InstitucionTipoEntradaController {
|
|||||||
const operador: Operador = req.user.operador;
|
const operador: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarAdminOperador(operador);
|
this.validarUsuarioService.validarAdminOperador(operador);
|
||||||
return this.tipoEntradaService.findAllByIdInstitucion(
|
return this.institucionTipoEntradaService.findAllOperador(operador);
|
||||||
operador.institucion.id_institucion,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serealize(InstitucionTipoEntradaMinOutputDto)
|
@Serealize(InstitucionTipoEntradaMinOutputDto)
|
||||||
@ -97,9 +95,9 @@ export class InstitucionTipoEntradaController {
|
|||||||
const usuario: Usuario = req.user.usuario;
|
const usuario: Usuario = req.user.usuario;
|
||||||
|
|
||||||
this.validarUsuarioService.validarUsuario(usuario);
|
this.validarUsuarioService.validarUsuario(usuario);
|
||||||
return this.tipoEntradaService.findAllByIdInstitucion(
|
return this.institucionTipoEntradaService.findAllMostrar(
|
||||||
|
usuario,
|
||||||
parseInt(query.id_institucion),
|
parseInt(query.id_institucion),
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +118,6 @@ export class InstitucionTipoEntradaController {
|
|||||||
const admin: Operador = req.user.operador;
|
const admin: Operador = req.user.operador;
|
||||||
|
|
||||||
this.validarUsuarioService.validarAdmin(admin);
|
this.validarUsuarioService.validarAdmin(admin);
|
||||||
return this.tipoEntradaService.update(admin, body);
|
return this.institucionTipoEntradaService.update(admin, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ConflictException,
|
ConflictException,
|
||||||
|
ForbiddenException,
|
||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
@ -8,7 +9,9 @@ import { Repository } from 'typeorm';
|
|||||||
import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity';
|
import { InstitucionTipoEntrada } from './entity/institucion-tipo-entrada.entity';
|
||||||
import { Operador } from '../operador/entity/operador.entity';
|
import { Operador } from '../operador/entity/operador.entity';
|
||||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||||
|
import { Usuario } from 'src/usuario/entity/usuario.entity';
|
||||||
import { InstitucionService } from '../institucion/institucion.service';
|
import { InstitucionService } from '../institucion/institucion.service';
|
||||||
|
import { InstitucionUsuarioService } from '../institucion-usuario/institucion-usuario.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InstitucionTipoEntradaService {
|
export class InstitucionTipoEntradaService {
|
||||||
@ -18,16 +21,17 @@ export class InstitucionTipoEntradaService {
|
|||||||
@InjectRepository(TipoEntrada)
|
@InjectRepository(TipoEntrada)
|
||||||
private tipoEntradaRepository: Repository<TipoEntrada>,
|
private tipoEntradaRepository: Repository<TipoEntrada>,
|
||||||
private institucionService: InstitucionService,
|
private institucionService: InstitucionService,
|
||||||
|
private institucionUsuarioService: InstitucionUsuarioService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(tipo_entrada: string) {
|
create(tipo_entrada: string): Promise<{ message: string }> {
|
||||||
// Buscamos un tipo de entrada con ese nombre
|
// Buscamos un registro con ese nombre
|
||||||
return this.tipoEntradaRepository
|
return this.tipoEntradaRepository
|
||||||
.findOne({ where: { tipo_entrada } })
|
.findOne({ where: { tipo_entrada } })
|
||||||
.then((existeTipoEntrada) => {
|
.then((existeTipoEntrada) => {
|
||||||
// Sacamos error si existe
|
// Sacamos error si existe
|
||||||
if (existeTipoEntrada)
|
if (existeTipoEntrada)
|
||||||
throw new ConflictException('Ya existe este tipo de entrada.');
|
throw new ConflictException('Ya existe este tipo de conector.');
|
||||||
// Creamos y guardamos un registro
|
// Creamos y guardamos un registro
|
||||||
return this.tipoEntradaRepository.save(
|
return this.tipoEntradaRepository.save(
|
||||||
this.tipoEntradaRepository.create({ tipo_entrada }),
|
this.tipoEntradaRepository.create({ tipo_entrada }),
|
||||||
@ -36,7 +40,7 @@ export class InstitucionTipoEntradaService {
|
|||||||
.then(async (tipoEntrada) => {
|
.then(async (tipoEntrada) => {
|
||||||
const instituciones = await this.institucionService.findAll();
|
const instituciones = await this.institucionService.findAll();
|
||||||
|
|
||||||
// Le asigno el nuevo tipo de entrada a todas las instituciones
|
// Asociamos el nuevo tipo de entrada con las instituciones existentes
|
||||||
for (let i = 0; i < instituciones.length; i++)
|
for (let i = 0; i < instituciones.length; i++)
|
||||||
await this.institucionTipoEntradaRepository.save(
|
await this.institucionTipoEntradaRepository.save(
|
||||||
this.institucionTipoEntradaRepository.create({
|
this.institucionTipoEntradaRepository.create({
|
||||||
@ -44,40 +48,47 @@ export class InstitucionTipoEntradaService {
|
|||||||
tipoEntrada,
|
tipoEntrada,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return { message: 'Se creó correctamente un nuevo tipo de entrada.' };
|
return { message: 'Se creó correctamente un nuevo tipo de conector.' };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll(): Promise<TipoEntrada[]> {
|
||||||
return this.tipoEntradaRepository.find({ order: { tipo_entrada: 'ASC' } });
|
return this.tipoEntradaRepository.find({ order: { tipo_entrada: 'ASC' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByIdInstitucion(id_institucion: number, mostrar = false) {
|
async findAllMostrar(
|
||||||
|
usuario: Usuario,
|
||||||
|
id_institucion: number,
|
||||||
|
): Promise<InstitucionTipoEntrada[]> {
|
||||||
const institucion = await this.institucionService.findById(id_institucion);
|
const institucion = await this.institucionService.findById(id_institucion);
|
||||||
const query = await this.institucionTipoEntradaRepository
|
const institucionUsuario =
|
||||||
.createQueryBuilder('ite')
|
await this.institucionUsuarioService.findByIdUsuarioIdInstitucion(
|
||||||
.innerJoinAndSelect(
|
usuario,
|
||||||
'ite.institucion',
|
institucion,
|
||||||
'i',
|
);
|
||||||
'i.id_institucion = :id_institucion',
|
|
||||||
{ id_institucion: institucion.id_institucion },
|
|
||||||
)
|
|
||||||
.innerJoinAndSelect('ite.tipoEntrada', 'te')
|
|
||||||
.orderBy('te.tipo_entrada');
|
|
||||||
|
|
||||||
if (mostrar) query.andWhere('ite.mostrar = 1');
|
if (!institucionUsuario)
|
||||||
return query.getMany();
|
throw new ForbiddenException(
|
||||||
|
'No puedes acceder a esta información porque no peteneces a esta institución.',
|
||||||
|
);
|
||||||
|
return this.institucionTipoEntradaRepository.find({
|
||||||
|
where: { mostrar: true, institucion },
|
||||||
|
order: { tipoEntrada: { tipo_entrada: 'ASC' } },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findById(id_institucion_tipo_entrada: number) {
|
findAllOperador(operador: Operador): Promise<InstitucionTipoEntrada[]> {
|
||||||
|
return this.institucionTipoEntradaRepository.find({
|
||||||
|
where: { institucion: operador.institucion },
|
||||||
|
order: { tipoEntrada: { tipo_entrada: 'ASC' } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
findById(
|
||||||
|
id_institucion_tipo_entrada: number,
|
||||||
|
): Promise<InstitucionTipoEntrada> {
|
||||||
return this.institucionTipoEntradaRepository
|
return this.institucionTipoEntradaRepository
|
||||||
.findOne({
|
.findOne({ where: { id_institucion_tipo_entrada } })
|
||||||
join: {
|
|
||||||
alias: 'ite',
|
|
||||||
innerJoinAndSelect: { i: 'ite.institucion', te: 'ite.tipoEntrada' },
|
|
||||||
},
|
|
||||||
where: { id_institucion_tipo_entrada },
|
|
||||||
})
|
|
||||||
.then((institucionTipoEntrada) => {
|
.then((institucionTipoEntrada) => {
|
||||||
if (!institucionTipoEntrada)
|
if (!institucionTipoEntrada)
|
||||||
throw new NotFoundException(
|
throw new NotFoundException(
|
||||||
@ -87,7 +98,7 @@ export class InstitucionTipoEntradaService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTipoEntradaById(id_tipo_entrada: number) {
|
findTipoEntradaById(id_tipo_entrada: number): Promise<TipoEntrada> {
|
||||||
return this.tipoEntradaRepository
|
return this.tipoEntradaRepository
|
||||||
.findOne({ where: { id_tipo_entrada } })
|
.findOne({ where: { id_tipo_entrada } })
|
||||||
.then((tipoEntrada) => {
|
.then((tipoEntrada) => {
|
||||||
@ -97,27 +108,23 @@ export class InstitucionTipoEntradaService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findTipoEntradaByTipoEntrada(tipo_entrada: string, validarNoExiste = true) {
|
findTipoEntradaByTipoEntrada(tipo_entrada: string): Promise<TipoEntrada> {
|
||||||
return this.tipoEntradaRepository
|
return this.tipoEntradaRepository.findOne({ where: { tipo_entrada } });
|
||||||
.findOne({ where: { tipo_entrada } })
|
|
||||||
.then((tipoEntrada) => {
|
|
||||||
if (validarNoExiste && !tipoEntrada)
|
|
||||||
throw new NotFoundException('No existe este tipo de entrada.');
|
|
||||||
return tipoEntrada;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(admin: Operador, attrs: Partial<InstitucionTipoEntrada>) {
|
update(
|
||||||
|
admin: Operador,
|
||||||
|
attrs: Partial<InstitucionTipoEntrada>,
|
||||||
|
): Promise<{ message: string }> {
|
||||||
return this.findById(attrs.id_institucion_tipo_entrada)
|
return this.findById(attrs.id_institucion_tipo_entrada)
|
||||||
.then((institucionTipoEntrada) => {
|
.then((institucionTipoEntrada) => {
|
||||||
// Validamos que la institucionTipoEntrada le pertenezca al operador que
|
// Validamos que la institucion tipo entrada pertenezca a la institución del admin
|
||||||
// realiza esta acción
|
|
||||||
if (
|
if (
|
||||||
admin.institucion.id_institucion !=
|
admin.institucion.id_institucion !=
|
||||||
institucionTipoEntrada.institucion.id_institucion
|
institucionTipoEntrada.institucion.id_institucion
|
||||||
)
|
)
|
||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
'No puedes actualizar la información de este tipo de carrito porque no le pertenece a tu institución.',
|
'No puedes modificar la información este tipo de conector porque no pertenece a tu institución.',
|
||||||
);
|
);
|
||||||
// Asignamos valores enviados al objeto
|
// Asignamos valores enviados al objeto
|
||||||
Object.assign(institucionTipoEntrada, attrs);
|
Object.assign(institucionTipoEntrada, attrs);
|
||||||
@ -126,8 +133,6 @@ export class InstitucionTipoEntradaService {
|
|||||||
institucionTipoEntrada,
|
institucionTipoEntrada,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((_) => ({
|
.then((_) => ({ message: 'Se guardaron los cambios correctamente.' }));
|
||||||
message: 'Se guardaron los cambios correctamente.',
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,6 @@ export class UploadFileService {
|
|||||||
const tipoEntrada =
|
const tipoEntrada =
|
||||||
await this.institucionTipoEntradaService.findTipoEntradaByTipoEntrada(
|
await this.institucionTipoEntradaService.findTipoEntradaByTipoEntrada(
|
||||||
entradas[j].trim(),
|
entradas[j].trim(),
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
const existeEquipoTipoEntrada = tipoEntrada
|
const existeEquipoTipoEntrada = tipoEntrada
|
||||||
? await this.equipoTipoEntradaService.findByEquipoTipoEntrada(
|
? await this.equipoTipoEntradaService.findByEquipoTipoEntrada(
|
||||||
|
Loading…
Reference in New Issue
Block a user