listo hora excepción
This commit is contained in:
parent
866dd0cd42
commit
cedb67e241
@ -83,7 +83,7 @@ export class CarreraProgramaService {
|
||||
'No puedes eliminar esta asociación porque no pertenece a tu institución.',
|
||||
);
|
||||
// Elimino
|
||||
return this.repository.delete(carreraPrograma);
|
||||
return this.repository.remove(carreraPrograma);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se eliminó correctamente la asignación del programa.',
|
||||
|
@ -23,6 +23,7 @@ import { Operador } from '../operador/entity/operador.entity';
|
||||
import { CreateHoraExcepcionDto } from './dto/input/create.dto';
|
||||
import { DeleteHoraExcepcionDto } from './dto/input/delete.dto';
|
||||
import { GetHoraExcepcionDto } from './dto/input/get.dto';
|
||||
import { MessageOutputDto } from '../dto/output/message.dto';
|
||||
import { HoraExcepcionOutputDto } from './dto/output/hora-excepcion.dto';
|
||||
|
||||
@Controller('hora-excepcion')
|
||||
@ -33,6 +34,7 @@ export class HoraExcepcionController {
|
||||
private validarUsuarioService: ValidarUsuarioService,
|
||||
) {}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
@ -63,6 +65,7 @@ export class HoraExcepcionController {
|
||||
);
|
||||
}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Delete()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
|
@ -6,14 +6,8 @@ import {
|
||||
ForbiddenException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import {
|
||||
FindOperator,
|
||||
LessThanOrEqual,
|
||||
MoreThanOrEqual,
|
||||
Repository,
|
||||
} from 'typeorm';
|
||||
import { LessThanOrEqual, MoreThanOrEqual, Repository } from 'typeorm';
|
||||
import { HoraExcepcion } from './entity/hora-excepcion.entity';
|
||||
import { InstitucionDia } from '../institucion-dia/entity/institucion-dia.entity';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { InstitucionDiaService } from '../institucion-dia/institucion-dia.service';
|
||||
|
||||
@ -34,12 +28,9 @@ export class HoraExcepcionService {
|
||||
const institucionDia = await this.institucionDiaService.findById(
|
||||
id_institucion_dia,
|
||||
);
|
||||
const busqueda: {
|
||||
hora_fin: FindOperator<string>;
|
||||
hora_inicio: FindOperator<string>;
|
||||
institucionDia: InstitucionDia;
|
||||
}[] = [];
|
||||
|
||||
// Valido que el id institución día mandado se de la institución a la que
|
||||
// pertenece el operador que realiza esta acción
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionDia.institucion.id_institucion
|
||||
@ -47,35 +38,44 @@ export class HoraExcepcionService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear una horario sin servicio en este día porque no le 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.',
|
||||
);
|
||||
if (hora_inicio)
|
||||
busqueda.push({
|
||||
hora_fin: MoreThanOrEqual(hora_inicio),
|
||||
hora_inicio: LessThanOrEqual(hora_inicio),
|
||||
institucionDia,
|
||||
});
|
||||
if (hora_fin)
|
||||
busqueda.push({
|
||||
hora_fin: MoreThanOrEqual(hora_fin),
|
||||
hora_inicio: LessThanOrEqual(hora_fin),
|
||||
institucionDia,
|
||||
});
|
||||
// Busco 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
|
||||
return this.repository
|
||||
.findOne({ where: busqueda })
|
||||
.findOne({
|
||||
where: [
|
||||
{
|
||||
hora_fin: MoreThanOrEqual(hora_inicio),
|
||||
hora_inicio: LessThanOrEqual(hora_inicio),
|
||||
institucionDia,
|
||||
},
|
||||
{
|
||||
hora_fin: MoreThanOrEqual(hora_fin),
|
||||
hora_inicio: LessThanOrEqual(hora_fin),
|
||||
institucionDia,
|
||||
},
|
||||
],
|
||||
})
|
||||
.then((existeHoraExcepcion) => {
|
||||
// Saca error si encuentra uno
|
||||
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
|
||||
)
|
||||
throw new ConflictException('Ya existe este horario sin servicio.');
|
||||
throw new ConflictException(
|
||||
'Ya existe un horario sin servicio con estas horass.',
|
||||
);
|
||||
throw new BadRequestException(
|
||||
'Las horas escogídas se sobrelapan con otro horario sin servicio del mismo día.',
|
||||
);
|
||||
}
|
||||
// Crea y guarda el registro
|
||||
return this.repository.save(
|
||||
this.repository.create({ institucionDia, hora_inicio, hora_fin }),
|
||||
);
|
||||
@ -88,6 +88,8 @@ export class HoraExcepcionService {
|
||||
delete(admin: Operador, id_hora_excepcion: number) {
|
||||
return this.findById(id_hora_excepcion)
|
||||
.then((horaExcepcion) => {
|
||||
// Valido que el id hora excepción pertenezca a la institución del operador
|
||||
// que realiza esta acción
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
horaExcepcion.institucionDia.institucion.id_institucion
|
||||
@ -95,7 +97,8 @@ export class HoraExcepcionService {
|
||||
throw new ConflictException(
|
||||
'No puedes eliminar esta horario sin servicio porque no pertenece a tu institución.',
|
||||
);
|
||||
this.repository.delete(horaExcepcion);
|
||||
// Elimino registros
|
||||
return this.repository.remove(horaExcepcion);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se eliminó correctamente este horario sin servicio.',
|
||||
|
Loading…
Reference in New Issue
Block a user