carrito listo
This commit is contained in:
parent
12a2544f90
commit
c4ebe4efcf
@ -38,7 +38,7 @@ export class CarritoMotivoService {
|
||||
}
|
||||
|
||||
findAllByIdCarrito(id_carrito: number, pagina: number) {
|
||||
return this.carritoService.findInfoCarritoById(id_carrito).then((carrito) =>
|
||||
return this.carritoService.findById(id_carrito).then((carrito) =>
|
||||
this.repository.findAndCount({
|
||||
where: { carrito },
|
||||
skip: (pagina - 1) * 25,
|
||||
|
@ -25,6 +25,7 @@ import { CarritoDto } from './dto/input/carrito.dto';
|
||||
import { CarritosDto } from './dto/input/carritos.dto';
|
||||
import { CreateCarritoDto } from './dto/input/create.dto';
|
||||
import { UpdateCarritoDto } from './dto/input/update.dto';
|
||||
import { MessageOutputDto } from '../dto/output/message.dto';
|
||||
import { CarritoOutputDto } from './dto/output/carrito.dto';
|
||||
import { CarritosOutputDto } from './dto/output/carritos.dto';
|
||||
|
||||
@ -53,7 +54,7 @@ export class CarritoController {
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.carritoService
|
||||
.findFullInfoCarritoById(parseInt(query.id_carrito))
|
||||
.findFullInfoById(parseInt(query.id_carrito))
|
||||
.then((carrito) => {
|
||||
if (
|
||||
operador.tipoUsuario.id_tipo_usuario > 2 &&
|
||||
@ -126,9 +127,10 @@ export class CarritoController {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.carritoService.findFullInfoCarritoAll(query);
|
||||
return this.carritoService.findFullInfoAll(query);
|
||||
}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
@ -156,6 +158,7 @@ export class CarritoController {
|
||||
);
|
||||
}
|
||||
|
||||
@Serealize(MessageOutputDto)
|
||||
@Put()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
|
@ -52,10 +52,12 @@ export class CarritoService {
|
||||
const marca = await this.marcaService.findById(id_marca, 'c');
|
||||
const modelo = await this.modeloService.findById(id_modelo, 'c');
|
||||
|
||||
// Valido que el módulo seleccionado pertenezca a la institutción del admin
|
||||
if (admin.institucion.id_institucion != modulo.institucion.id_institucion)
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear carritos para este módulo porque no pertenece a tu institución.',
|
||||
);
|
||||
// Cuento cuantos carritos tiene ese modulo de ese tipo de carrito
|
||||
return this.informacionCarritoView
|
||||
.count({
|
||||
where: {
|
||||
@ -63,10 +65,11 @@ export class CarritoService {
|
||||
id_tipo_carrito: tipoCarrito.id_tipo_carrito,
|
||||
},
|
||||
})
|
||||
.then((carritos) =>
|
||||
.then((n) =>
|
||||
// Creo y cuardo el registro
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
carrito: `C${carritos >= 9 ? '' : '0'}${carritos + 1}`,
|
||||
carrito: `C${n >= 9 ? '' : '0'}${n + 1}`,
|
||||
marca,
|
||||
modelo,
|
||||
modulo,
|
||||
@ -79,7 +82,17 @@ export class CarritoService {
|
||||
}));
|
||||
}
|
||||
|
||||
async findCarrito(modulo: Modulo, tipoCarrito: TipoCarrito, carrito: string) {
|
||||
findById(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);
|
||||
});
|
||||
}
|
||||
|
||||
findCarrito(modulo: Modulo, tipoCarrito: TipoCarrito, carrito: string) {
|
||||
return this.informacionCarritoView
|
||||
.findOne({
|
||||
where: {
|
||||
@ -94,7 +107,7 @@ export class CarritoService {
|
||||
});
|
||||
}
|
||||
|
||||
findFullInfoCarritoById(id_carrito: number) {
|
||||
findFullInfoById(id_carrito: number) {
|
||||
return this.fullInformacionCarritoView
|
||||
.findOne({ where: { id_carrito } })
|
||||
.then((infoCarrito) => {
|
||||
@ -128,17 +141,7 @@ export class CarritoService {
|
||||
});
|
||||
}
|
||||
|
||||
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: {
|
||||
async findFullInfoAll(filtros: {
|
||||
pagina?: string;
|
||||
activo?: string;
|
||||
carrito?: string;
|
||||
@ -180,6 +183,7 @@ export class CarritoService {
|
||||
if (modelo) busqueda.id_modelo = modelo.id_modelo;
|
||||
if (tipoCarrito) busqueda.id_tipo_carrito = tipoCarrito.id_tipo_carrito;
|
||||
options.where = busqueda;
|
||||
// Si viene con página es que quiere paginación
|
||||
if (filtros.pagina) {
|
||||
options.skip = (parseInt(filtros.pagina) - 1) * 25;
|
||||
options.take = 25;
|
||||
@ -187,24 +191,17 @@ export class CarritoService {
|
||||
.findAndCount(options)
|
||||
.then((infoCarritos) => {
|
||||
for (let i = 0; i < infoCarritos[0].length; i++)
|
||||
carritos.push(
|
||||
this.repository.create(
|
||||
this.fullViewToCarrito(infoCarritos[0][i]),
|
||||
),
|
||||
);
|
||||
carritos.push(this.fullViewToCarrito(infoCarritos[0][i]));
|
||||
return [carritos, infoCarritos[1]];
|
||||
});
|
||||
} else {
|
||||
} 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])),
|
||||
);
|
||||
carritos.push(this.fullViewToCarrito(infoCarritos[i]));
|
||||
return carritos;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private fullViewToCarrito(infoCarrito: FullInformacionCarritoView) {
|
||||
@ -228,8 +225,9 @@ export class CarritoService {
|
||||
}
|
||||
|
||||
async update(operador: Operador, attrs: Partial<Carrito>, motivo: string) {
|
||||
return this.findInfoCarritoById(attrs.id_carrito)
|
||||
return this.findById(attrs.id_carrito)
|
||||
.then(async (carrito) => {
|
||||
// Valido que el carrito pertenezca a la institución del operador
|
||||
if (
|
||||
operador.institucion.id_institucion !=
|
||||
carrito.modulo.institucion.id_institucion
|
||||
@ -237,10 +235,13 @@ export class CarritoService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes modificar la información este carrito porque no pertenece a tu institución.',
|
||||
);
|
||||
// Actualizo el objeto con los valores enviados del front
|
||||
Object.assign(carrito, attrs);
|
||||
// Guardo cambios
|
||||
return this.repository.save(carrito);
|
||||
})
|
||||
.then((carrito) =>
|
||||
// Creo reporte de cambio de status del carrito
|
||||
this.caritoMotivoService.create(
|
||||
carrito,
|
||||
operador,
|
||||
@ -248,9 +249,7 @@ export class CarritoService {
|
||||
motivo,
|
||||
),
|
||||
)
|
||||
.then((_) => ({
|
||||
message: 'Se guardaron los cambios correctamente.',
|
||||
}));
|
||||
.then((_) => ({ message: 'Se guardaron los cambios correctamente.' }));
|
||||
}
|
||||
|
||||
private viewToCarrito(infoCarrito: InformacionCarritoView) {
|
||||
@ -258,13 +257,9 @@ export class CarritoService {
|
||||
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,
|
||||
institucion: { id_institucion: infoCarrito.id_institucion },
|
||||
},
|
||||
tipoCarrito: { id_tipo_carrito: infoCarrito.id_tipo_carrito },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,18 @@ export class Carrito {
|
||||
@Column({ type: String, nullable: false, length: 4 })
|
||||
carrito: string;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_marca: number;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_modelo: number;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_modulo: number;
|
||||
|
||||
@Column({ type: Number, nullable: true })
|
||||
id_tipo_carrito: number;
|
||||
|
||||
@ManyToOne(() => Marca, (marca) => marca.carritos, { eager: true })
|
||||
@JoinColumn({ name: 'id_marca' })
|
||||
marca: Marca;
|
||||
|
@ -104,9 +104,7 @@ export class EquipoService {
|
||||
},
|
||||
) {
|
||||
const carrito = filtros.id_carrito
|
||||
? await this.carritoService.findInfoCarritoById(
|
||||
parseInt(filtros.id_carrito),
|
||||
)
|
||||
? await this.carritoService.findById(parseInt(filtros.id_carrito))
|
||||
: null;
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findInfoInstitucionById(
|
||||
@ -447,7 +445,7 @@ export class EquipoService {
|
||||
motivo?: string,
|
||||
) {
|
||||
const carrito = id_carrito
|
||||
? await this.carritoService.findInfoCarritoById(id_carrito)
|
||||
? await this.carritoService.findById(id_carrito)
|
||||
: null;
|
||||
const status = id_status
|
||||
? await this.statusService.findById(id_status)
|
||||
|
Loading…
Reference in New Issue
Block a user