listo institucion programa, tipo carrito y tipo entrada
This commit is contained in:
parent
f3f5fe7d8a
commit
772010d7f1
@ -21,19 +21,22 @@ export class InstitucionProgramaService {
|
||||
) {}
|
||||
|
||||
create(programa: string) {
|
||||
// Busco un programa con ese nombre
|
||||
return this.programaRepository
|
||||
.findOne({ where: { programa } })
|
||||
.then((existePrograma) => {
|
||||
// Saco error si existe
|
||||
if (existePrograma)
|
||||
throw new ConflictException('Ya existe este programa.');
|
||||
// Creo y guardo el registro
|
||||
return this.programaRepository.save(
|
||||
this.programaRepository.create({ programa }),
|
||||
);
|
||||
})
|
||||
.then(async (programa) => {
|
||||
const instituciones =
|
||||
await this.institucionService.findAll();
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
// Le asigno el nuevo programa a todas las instituciones
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionProgramaRepository.save(
|
||||
this.institucionProgramaRepository.create({
|
||||
@ -111,6 +114,8 @@ export class InstitucionProgramaService {
|
||||
update(admin: Operador, attrs: Partial<InstitucionPrograma>) {
|
||||
return this.findById(attrs.id_institucion_programa)
|
||||
.then((institucionPrograma) => {
|
||||
// Valido que la institucionPrograma le pertenezca al operador que
|
||||
// realiza esta acción
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionPrograma.institucion.id_institucion
|
||||
@ -118,11 +123,11 @@ export class InstitucionProgramaService {
|
||||
throw new ConflictException(
|
||||
'No puedes actualizar la información de este software porque no le pertenece a tu institución.',
|
||||
);
|
||||
// Asigno valores enviados al objeto
|
||||
Object.assign(institucionPrograma, attrs);
|
||||
// Guardar
|
||||
return this.institucionProgramaRepository.save(institucionPrograma);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
.then((_) => ({ message: 'Se guardaron los cambios correctamente.' }));
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ export class InstitucionTipoCarritoService {
|
||||
) {}
|
||||
|
||||
create(letra: string, tipo_carrito: string) {
|
||||
// Busco un tipo de carrito con ese nombre o letra
|
||||
return this.tipoCarritoRepository
|
||||
.findOne({ where: [{ letra }, { tipo_carrito }] })
|
||||
.then((existeTipoCarrito) => {
|
||||
// Saco error si existe
|
||||
if (existeTipoCarrito) {
|
||||
if (letra === existeTipoCarrito.letra)
|
||||
throw new ConflictException(
|
||||
@ -34,14 +36,15 @@ export class InstitucionTipoCarritoService {
|
||||
'Ya existe un tipo carrito con este nombre, intente con otro nombre.',
|
||||
);
|
||||
}
|
||||
// Creo y guardo el registros
|
||||
return this.tipoCarritoRepository.save(
|
||||
this.tipoCarritoRepository.create({ letra, tipo_carrito }),
|
||||
);
|
||||
})
|
||||
.then(async (tipoCarrito) => {
|
||||
const instituciones =
|
||||
await this.institucionService.findAll();
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
// Le asigno el nuevo tipo de carrito a todas las instituciones
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionTipoCarritoRepository.save(
|
||||
this.institucionTipoCarritoRepository.create({
|
||||
@ -117,6 +120,8 @@ export class InstitucionTipoCarritoService {
|
||||
attrs.id_institucion_tipo_carrito,
|
||||
)
|
||||
.then((institucionTipoCarrito) => {
|
||||
// Valido que la institucionTipoCarrito le pertenezca al operador que
|
||||
// realiza esta acción
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionTipoCarrito.institucion.id_institucion
|
||||
@ -124,13 +129,13 @@ export class InstitucionTipoCarritoService {
|
||||
throw new ConflictException(
|
||||
'No puedes actualizar la información de este tipo de carrito porque no le pertenece a tu institución.',
|
||||
);
|
||||
// Asigno valores enviados al objeto
|
||||
Object.assign(institucionTipoCarrito, attrs);
|
||||
// Guardar
|
||||
return this.institucionTipoCarritoRepository.save(
|
||||
institucionTipoCarrito,
|
||||
);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
.then((_) => ({ message: 'Se guardaron los cambios correctamente.' }));
|
||||
}
|
||||
}
|
||||
|
@ -21,20 +21,22 @@ export class InstitucionTipoEntradaService {
|
||||
) {}
|
||||
|
||||
async create(tipo_entrada: string) {
|
||||
// Busco un tipo de entrada con ese nombre
|
||||
return this.tipoEntradaRepository
|
||||
.findOne({ where: { tipo_entrada } })
|
||||
.then((existeTipoEntrada) => {
|
||||
// Saco error si existe
|
||||
if (existeTipoEntrada)
|
||||
throw new ConflictException('Ya existe este tipo de entrada.');
|
||||
// Creo y guardo el registro
|
||||
return this.tipoEntradaRepository.save(
|
||||
this.tipoEntradaRepository.create({
|
||||
tipo_entrada,
|
||||
}),
|
||||
this.tipoEntradaRepository.create({ tipo_entrada }),
|
||||
);
|
||||
})
|
||||
.then(async (tipoEntrada) => {
|
||||
const instituciones = await this.institucionService.findAll();
|
||||
|
||||
// Le asigno el nuevo tipo de entrada a todas las instituciones
|
||||
for (let i = 0; i < instituciones.length; i++)
|
||||
await this.institucionTipoEntradaRepository.save(
|
||||
this.institucionTipoEntradaRepository.create({
|
||||
@ -42,9 +44,7 @@ export class InstitucionTipoEntradaService {
|
||||
tipoEntrada,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
message: 'Se creó correctamente un nuevo tipo de entrada.',
|
||||
};
|
||||
return { message: 'Se creó correctamente un nuevo tipo de entrada.' };
|
||||
});
|
||||
}
|
||||
|
||||
@ -110,6 +110,8 @@ export class InstitucionTipoEntradaService {
|
||||
update(admin: Operador, attrs: Partial<InstitucionTipoEntrada>) {
|
||||
return this.findById(attrs.id_institucion_tipo_entrada)
|
||||
.then((institucionTipoEntrada) => {
|
||||
// Valido que la institucionTipoEntrada le pertenezca al operador que
|
||||
// realiza esta acción
|
||||
if (
|
||||
admin.institucion.id_institucion !=
|
||||
institucionTipoEntrada.institucion.id_institucion
|
||||
@ -117,7 +119,9 @@ export class InstitucionTipoEntradaService {
|
||||
throw new ConflictException(
|
||||
'No puedes actualizar la información de este tipo de carrito porque no le pertenece a tu institución.',
|
||||
);
|
||||
// Asigno valores enviados al objeto
|
||||
Object.assign(institucionTipoEntrada, attrs);
|
||||
// Guardar
|
||||
return this.institucionTipoEntradaRepository.save(
|
||||
institucionTipoEntrada,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user