carrito final
This commit is contained in:
@@ -38,7 +38,7 @@ export class CarritoMotivoService {
|
||||
}
|
||||
|
||||
findAllByIdCarrito(id_carrito: number, pagina: number) {
|
||||
return this.carritoService.findById(id_carrito).then((carrito) =>
|
||||
return this.carritoService.findInfoCarritoById(id_carrito).then((carrito) =>
|
||||
this.repository.findAndCount({
|
||||
where: { carrito },
|
||||
skip: (pagina - 1) * 25,
|
||||
|
||||
@@ -126,7 +126,7 @@ export class CarritoController {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.carritoService.findMinInfoCarritoAll(query);
|
||||
return this.carritoService.findFullInfoCarritoAll(query);
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
ConflictException,
|
||||
ForbiddenException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
@@ -55,7 +54,7 @@ export class CarritoService {
|
||||
|
||||
if (admin.institucion.id_institucion != modulo.institucion.id_institucion)
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear un carrito para este módulo porque no pertenece a tu institución.',
|
||||
'No puedes crear carritos para este módulo porque no pertenece a tu institución.',
|
||||
);
|
||||
return this.informacionCarritoView
|
||||
.count({
|
||||
@@ -80,59 +79,18 @@ export class CarritoService {
|
||||
}));
|
||||
}
|
||||
|
||||
findById(id_carrito: number) {
|
||||
return this.repository
|
||||
.findOne({ where: { id_carrito } })
|
||||
.then((carrito) => {
|
||||
if (!carrito) throw new NotFoundException('No existe este id carrito.');
|
||||
return carrito;
|
||||
});
|
||||
}
|
||||
|
||||
async findCarrito(
|
||||
id_modulo: number | Modulo,
|
||||
id_tipo_carrito: number | TipoCarrito,
|
||||
carrito: string,
|
||||
validarNoExiste = true,
|
||||
) {
|
||||
const modulo =
|
||||
typeof id_modulo === 'number'
|
||||
? await this.moduloService.findInfoModuloById(id_modulo)
|
||||
: id_modulo;
|
||||
const tipoCarrito =
|
||||
typeof id_tipo_carrito === 'number'
|
||||
? await this.institucionTipoCarritoService.findTipoCarritoById(
|
||||
id_tipo_carrito,
|
||||
)
|
||||
: id_tipo_carrito;
|
||||
|
||||
return this.repository
|
||||
.findOne({ where: { carrito, modulo, tipoCarrito } })
|
||||
.then((carrito) => {
|
||||
if (validarNoExiste && !carrito)
|
||||
throw new ConflictException('No existe este carrito.');
|
||||
return carrito;
|
||||
});
|
||||
}
|
||||
|
||||
findInfoCarritoById(id_carrito: number) {
|
||||
async findCarrito(modulo: Modulo, tipoCarrito: TipoCarrito, carrito: string) {
|
||||
return this.informacionCarritoView
|
||||
.findOne({ where: { id_carrito } })
|
||||
.findOne({
|
||||
where: {
|
||||
carrito,
|
||||
id_modulo: modulo.id_modulo,
|
||||
id_tipo_carrito: tipoCarrito.id_tipo_carrito,
|
||||
},
|
||||
})
|
||||
.then((infoCarrito) => {
|
||||
if (!infoCarrito)
|
||||
throw new NotFoundException('No existe este id carrito.');
|
||||
return this.repository.create({
|
||||
id_carrito: infoCarrito.id_carrito,
|
||||
tipoCarrito: {
|
||||
id_tipo_carrito: infoCarrito.id_tipo_carrito,
|
||||
},
|
||||
modulo: {
|
||||
id_modulo: infoCarrito.id_modulo,
|
||||
institucion: {
|
||||
id_institucion: infoCarrito.id_institucion,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!infoCarrito) return null;
|
||||
return this.viewToCarrito(infoCarrito);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -170,7 +128,17 @@ export class CarritoService {
|
||||
});
|
||||
}
|
||||
|
||||
async findMinInfoCarritoAll(filtros: {
|
||||
findInfoCarritoById(id_carrito: number) {
|
||||
return this.informacionCarritoView
|
||||
.findOne({ where: { id_carrito } })
|
||||
.then((infoCarrito) => {
|
||||
if (!infoCarrito)
|
||||
throw new NotFoundException('No existe este id carrito.');
|
||||
return this.viewToCarrito(infoCarrito);
|
||||
});
|
||||
}
|
||||
|
||||
async findFullInfoCarritoAll(filtros: {
|
||||
pagina?: string;
|
||||
activo?: string;
|
||||
carrito?: string;
|
||||
@@ -180,6 +148,7 @@ export class CarritoService {
|
||||
id_modulo?: string;
|
||||
id_tipo_carrito?: string;
|
||||
}) {
|
||||
const carritos: Carrito[] = [];
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findInfoInstitucionById(
|
||||
parseInt(filtros.id_institucion),
|
||||
@@ -210,39 +179,52 @@ export class CarritoService {
|
||||
if (marca) busqueda.id_marca = marca.id_marca;
|
||||
if (modelo) busqueda.id_modelo = modelo.id_modelo;
|
||||
if (tipoCarrito) busqueda.id_tipo_carrito = tipoCarrito.id_tipo_carrito;
|
||||
if (filtros.pagina) {
|
||||
options.take = 25;
|
||||
options.skip = (parseInt(filtros.pagina) - 1) * 25;
|
||||
}
|
||||
options.where = busqueda;
|
||||
return this.fullInformacionCarritoView
|
||||
.findAndCount(options)
|
||||
.then((infoCarritos) => {
|
||||
const carritos: Carrito[] = [];
|
||||
if (filtros.pagina) {
|
||||
options.skip = (parseInt(filtros.pagina) - 1) * 25;
|
||||
options.take = 25;
|
||||
return this.fullInformacionCarritoView
|
||||
.findAndCount(options)
|
||||
.then((infoCarritos) => {
|
||||
for (let i = 0; i < infoCarritos[0].length; i++)
|
||||
carritos.push(
|
||||
this.repository.create(
|
||||
this.fullViewToCarrito(infoCarritos[0][i]),
|
||||
),
|
||||
);
|
||||
return [carritos, infoCarritos[1]];
|
||||
});
|
||||
} else {
|
||||
return this.fullInformacionCarritoView
|
||||
.find(options)
|
||||
.then((infoCarritos) => {
|
||||
for (let i = 0; i < infoCarritos.length; i++)
|
||||
carritos.push(
|
||||
this.repository.create(this.fullViewToCarrito(infoCarritos[i])),
|
||||
);
|
||||
return carritos;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < infoCarritos[0].length; i++)
|
||||
carritos.push(
|
||||
this.repository.create({
|
||||
id_carrito: infoCarritos[0][i].id_carrito,
|
||||
activo: infoCarritos[0][i].activo === 1,
|
||||
carrito: infoCarritos[0][i].carrito,
|
||||
modulo: {
|
||||
id_modulo: infoCarritos[0][i].id_modulo,
|
||||
modulo: infoCarritos[0][i].modulo,
|
||||
institucion: {
|
||||
id_institucion: infoCarritos[0][i].id_institucion,
|
||||
institucion: infoCarritos[0][i].institucion,
|
||||
},
|
||||
},
|
||||
tipoCarrito: {
|
||||
id_tipo_carrito: infoCarritos[0][i].id_tipo_carrito,
|
||||
tipo_carrito: infoCarritos[0][i].tipo_carrito,
|
||||
},
|
||||
}),
|
||||
);
|
||||
if (filtros.pagina) return [carritos, infoCarritos[1]];
|
||||
return carritos;
|
||||
});
|
||||
private fullViewToCarrito(infoCarrito: FullInformacionCarritoView) {
|
||||
return this.repository.create({
|
||||
id_carrito: infoCarrito.id_carrito,
|
||||
activo: infoCarrito.activo === 1,
|
||||
carrito: infoCarrito.carrito,
|
||||
modulo: {
|
||||
id_modulo: infoCarrito.id_modulo,
|
||||
modulo: infoCarrito.modulo,
|
||||
institucion: {
|
||||
id_institucion: infoCarrito.id_institucion,
|
||||
institucion: infoCarrito.institucion,
|
||||
},
|
||||
},
|
||||
tipoCarrito: {
|
||||
id_tipo_carrito: infoCarrito.id_tipo_carrito,
|
||||
tipo_carrito: infoCarrito.tipo_carrito,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async update(operador: Operador, attrs: Partial<Carrito>, motivo: string) {
|
||||
@@ -270,4 +252,19 @@ export class CarritoService {
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
}
|
||||
|
||||
private viewToCarrito(infoCarrito: InformacionCarritoView) {
|
||||
return this.repository.create({
|
||||
id_carrito: infoCarrito.id_carrito,
|
||||
modulo: {
|
||||
id_modulo: infoCarrito.id_modulo,
|
||||
institucion: {
|
||||
id_institucion: infoCarrito.id_institucion,
|
||||
},
|
||||
},
|
||||
tipoCarrito: {
|
||||
id_tipo_carrito: infoCarrito.id_tipo_carrito,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,9 @@ export class EquipoService {
|
||||
},
|
||||
) {
|
||||
const carrito = filtros.id_carrito
|
||||
? await this.carritoService.findById(parseInt(filtros.id_carrito))
|
||||
? await this.carritoService.findInfoCarritoById(
|
||||
parseInt(filtros.id_carrito),
|
||||
)
|
||||
: null;
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findInfoInstitucionById(
|
||||
@@ -361,7 +363,7 @@ export class EquipoService {
|
||||
async findInfoEquipoByEquipo(id_carrito: number | Carrito, equipo: string) {
|
||||
const carrito =
|
||||
typeof id_carrito === 'number'
|
||||
? await this.carritoService.findById(id_carrito)
|
||||
? await this.carritoService.findInfoCarritoById(id_carrito)
|
||||
: id_carrito;
|
||||
|
||||
return this.informacionEquipoView
|
||||
@@ -465,7 +467,7 @@ export class EquipoService {
|
||||
motivo?: string,
|
||||
) {
|
||||
const carrito = id_carrito
|
||||
? await this.carritoService.findById(id_carrito)
|
||||
? await this.carritoService.findInfoCarritoById(id_carrito)
|
||||
: null;
|
||||
const operador = id_operador
|
||||
? typeof id_operador === 'number'
|
||||
|
||||
@@ -211,7 +211,6 @@ export class UploadFileService {
|
||||
modulo,
|
||||
tipoCarrito,
|
||||
dataEquipo.carrito,
|
||||
false,
|
||||
)
|
||||
: null;
|
||||
let equipo = carrito
|
||||
|
||||
Reference in New Issue
Block a user