hora excepcion service final
This commit is contained in:
parent
f6d51a6eab
commit
192ee92a02
@ -114,7 +114,7 @@ export class CarreraProgramaService {
|
||||
// Validamos que el usuario pertenezca a la institución de la información que solicita
|
||||
if (!institucionUsuario)
|
||||
throw new ForbiddenException(
|
||||
'No puedes acceder a esta información porque no perteneces a esta institución.',
|
||||
'No puedes acceder a esta información porque no le pertenece a tu institución.',
|
||||
);
|
||||
return this.findAllByInstitucion(institucion);
|
||||
});
|
||||
|
@ -56,7 +56,7 @@ export class CarritoService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear carritos para este módulo porque no pertenece a tu institución.',
|
||||
);
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository
|
||||
.save(
|
||||
this.repository.create({ carrito, marca, modelo, modulo, tipoCarrito }),
|
||||
|
@ -75,7 +75,7 @@ export class EquipoProgramaService {
|
||||
// Si lo tiene lo eliminamos
|
||||
if (existeEquipoSinPrograma)
|
||||
await this.repository.remove(existeEquipoSinPrograma);
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(
|
||||
this.repository.create({ equipo, programa }),
|
||||
);
|
||||
@ -112,7 +112,7 @@ export class EquipoProgramaService {
|
||||
.then(async (n) => {
|
||||
// Asignar "Sin software" si es que solo tiene 1, el que se va a eliminar
|
||||
if (n === 1) await this.createSinPrograma(equipoPrograma.equipo);
|
||||
// Eliminamos registro
|
||||
// Eliminamos el registro
|
||||
return this.repository.remove(equipoPrograma);
|
||||
})
|
||||
.then((_) => ({
|
||||
|
@ -84,7 +84,7 @@ export class EquipoTipoEntradaService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes modificar la información este equipo porque no pertenece a tu institución.',
|
||||
);
|
||||
// Eliminamos registro
|
||||
// Eliminamos el registro
|
||||
return this.repository.remove(equipoTipoEntrada);
|
||||
})
|
||||
.then((_) => ({
|
||||
|
@ -70,7 +70,7 @@ export class EquipoService {
|
||||
marca: Marca,
|
||||
modelo: Modelo,
|
||||
): Promise<Equipo> {
|
||||
// Creamos y guradamos registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository
|
||||
.save(
|
||||
this.repository.create({
|
||||
|
@ -91,6 +91,7 @@ export class HoraExcepcionController {
|
||||
|
||||
this.validarUsuarioService.validarAdmin(admin);
|
||||
return this.horaExcepcionService.findAllByIdInstitucionDia(
|
||||
admin,
|
||||
parseInt(query.id_institucion_dia),
|
||||
);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import {
|
||||
ConflictException,
|
||||
NotFoundException,
|
||||
Injectable,
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { LessThanOrEqual, MoreThanOrEqual, Repository } from 'typeorm';
|
||||
@ -24,27 +24,25 @@ export class HoraExcepcionService {
|
||||
id_institucion_dia: number,
|
||||
hora_inicio: string,
|
||||
hora_fin: string,
|
||||
) {
|
||||
): Promise<{ message: string }> {
|
||||
const institucionDia = await this.institucionDiaService.findById(
|
||||
id_institucion_dia,
|
||||
);
|
||||
|
||||
// Validamos que el id institución día mandado sea de la institución a la que
|
||||
// pertenece el operador que realiza esta acción
|
||||
// Validamos que el día pertenezca a la institución del admin
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionDia.institucion.id_institucion
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear una horario sin servicio en este día porque no le pertenece a tu institución.',
|
||||
'No puedes crear una hora excepeción en este día porque no pertenece a tu institución.',
|
||||
);
|
||||
// hora_inicio no puede ser mayor a hora fin
|
||||
if (hora_inicio > hora_fin)
|
||||
throw new BadRequestException(
|
||||
'La hora inicio no puede ser mayor que la hora fin.',
|
||||
);
|
||||
// Buscamos un horario servicio que pertenezca al mismo día y que sus horas inicio
|
||||
// y fin encierren, en tiempo, a alguna de las horas mandadas del front
|
||||
// Buscamos una hora excepción que encierre las horas enviadas
|
||||
return this.repository
|
||||
.findOne({
|
||||
where: [
|
||||
@ -61,9 +59,8 @@ export class HoraExcepcionService {
|
||||
],
|
||||
})
|
||||
.then((existeHoraExcepcion) => {
|
||||
// Saca error si encuentra uno
|
||||
// Si encontramos uno sacamos error
|
||||
if (existeHoraExcepcion) {
|
||||
// Si las horas enviadas son las mismas que las del registro saca error
|
||||
if (
|
||||
existeHoraExcepcion.hora_fin === hora_fin &&
|
||||
existeHoraExcepcion.hora_inicio === hora_inicio
|
||||
@ -75,7 +72,7 @@ export class HoraExcepcionService {
|
||||
'Las horas escogídas se sobrelapan con otro horario sin servicio del mismo día.',
|
||||
);
|
||||
}
|
||||
// Crea y guarda el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(
|
||||
this.repository.create({ institucionDia, hora_inicio, hora_fin }),
|
||||
);
|
||||
@ -85,11 +82,13 @@ export class HoraExcepcionService {
|
||||
}));
|
||||
}
|
||||
|
||||
delete(admin: Operador, id_hora_excepcion: number) {
|
||||
delete(
|
||||
admin: Operador,
|
||||
id_hora_excepcion: number,
|
||||
): Promise<{ message: string }> {
|
||||
return this.findById(id_hora_excepcion)
|
||||
.then((horaExcepcion) => {
|
||||
// Validamos que el id hora excepción pertenezca a la institución del operador
|
||||
// que realiza esta acción
|
||||
// Validamos que la hora excepción pertenezca a la institución del admin
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
horaExcepcion.institucionDia.institucion.id_institucion
|
||||
@ -97,7 +96,7 @@ export class HoraExcepcionService {
|
||||
throw new ConflictException(
|
||||
'No puedes eliminar esta horario sin servicio porque no pertenece a tu institución.',
|
||||
);
|
||||
// Eliminamos registro
|
||||
// Eliminamos el registro
|
||||
return this.repository.remove(horaExcepcion);
|
||||
})
|
||||
.then((_) => ({
|
||||
@ -105,15 +104,26 @@ export class HoraExcepcionService {
|
||||
}));
|
||||
}
|
||||
|
||||
findAllByIdInstitucionDia(id_institucion_dia: number) {
|
||||
findAllByIdInstitucionDia(
|
||||
admin: Operador,
|
||||
id_institucion_dia: number,
|
||||
): Promise<HoraExcepcion[]> {
|
||||
return this.institucionDiaService
|
||||
.findById(id_institucion_dia)
|
||||
.then((institucionDia) =>
|
||||
this.repository.find({ where: { institucionDia } }),
|
||||
);
|
||||
.then((institucionDia) => {
|
||||
// Validamos que el día pertenezca a la institución del admin
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionDia.institucion.id_institucion
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No puedes acceder a esta información porque no le pertenece a tu institución.',
|
||||
);
|
||||
return this.repository.find({ where: { institucionDia } });
|
||||
});
|
||||
}
|
||||
|
||||
findById(id_hora_excepcion: number) {
|
||||
findById(id_hora_excepcion: number): Promise<HoraExcepcion> {
|
||||
return this.repository
|
||||
.findOne({
|
||||
join: {
|
||||
|
@ -29,7 +29,7 @@ export class InstitucionInfraccionService {
|
||||
// Saco error si existe
|
||||
if (existeInfraccion)
|
||||
throw new ConflictException('Ya existe esta infracción.');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.infraccionRepository.save(
|
||||
this.infraccionRepository.create({ infraccion }),
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ export class InstitucionProgramaService {
|
||||
// Saco error si existe
|
||||
if (existePrograma)
|
||||
throw new ConflictException('Ya existe este programa.');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.programaRepository.save(
|
||||
this.programaRepository.create({ programa }),
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ export class InstitucionTipoEntradaService {
|
||||
// Saco error si existe
|
||||
if (existeTipoEntrada)
|
||||
throw new ConflictException('Ya existe este tipo de entrada.');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.tipoEntradaRepository.save(
|
||||
this.tipoEntradaRepository.create({ tipo_entrada }),
|
||||
);
|
||||
|
@ -21,7 +21,7 @@ export class InstitucionUsuarioService {
|
||||
) {}
|
||||
|
||||
create(institucionCarrera: InstitucionCarrera, usuario: Usuario) {
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository
|
||||
.save(this.repository.create({ institucionCarrera, usuario }))
|
||||
.then((institucionUsuario) => ({
|
||||
|
@ -83,7 +83,7 @@ export class InstitucionController {
|
||||
admin.institucion.id_institucion != institucion.id_institucion
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No puedes acceder a esta información porque no perteneces a esta institución.',
|
||||
'No puedes acceder a esta información porque no le pertenece a tu institución.',
|
||||
);
|
||||
return institucion;
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ export class MarcaService {
|
||||
.then((existeMarca) => {
|
||||
// Saco error si existe
|
||||
if (existeMarca) throw new ConflictException('Ya existe esta marca.');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(this.repository.create({ marca, tipo }));
|
||||
})
|
||||
.then((_) => ({ message: 'Se creó correctamente una nueva marca.' }));
|
||||
|
@ -15,7 +15,7 @@ export class ModeloService {
|
||||
.then((existeModelo) => {
|
||||
// Saco error si existe
|
||||
if (existeModelo) throw new ConflictException('Ya existe este modelo.');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(this.repository.create({ modelo, tipo }));
|
||||
})
|
||||
.then((_) => ({ message: 'Se creó correctamente un nuevo modelo.' }));
|
||||
|
@ -33,7 +33,7 @@ export class ModuloService {
|
||||
// que realiza esta acción
|
||||
return this.findModulo(admin.institucion, modulo, true)
|
||||
.then((_) =>
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
institucion: admin.institucion,
|
||||
|
@ -21,7 +21,7 @@ export class TipoUsuarioService {
|
||||
// Saco error si existe
|
||||
if (existeTipoUsuario)
|
||||
throw new ConflictException('Ya existe este tipo usuario');
|
||||
// Creamos y guardamos el registro
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(this.repository.create({ tipo_usuario }));
|
||||
})
|
||||
.then((_) => ({
|
||||
|
Loading…
Reference in New Issue
Block a user