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