update del carrito

This commit is contained in:
Andres2908
2022-05-12 09:56:17 -05:00
parent 8b1ecc5166
commit 1a4b42f548
+16 -11
View File
@@ -88,20 +88,25 @@ export class CarritoService {
return this.repository.find(busqueda);
}
// re hacer
async update(attrs: Partial<Carrito>) {
const carrito = await this.findById(attrs.id_carrito);
return this.repository
.findOne({ carrito: attrs.carrito, modulo: carrito.modulo })
async existeCarrito(id_modulo: number | Modulo, carrito: string) {
const modulo = typeof id_modulo === 'number' ? await this.moduloService.findById(id_modulo) : id_modulo
return this.repository.findOne({ modulo, carrito })
.then((existeCarrito) => {
if (existeCarrito)
throw new ConflictException('Ya existe un carrito con este número.');
if(existeCarrito) throw new ConflictException('Ya existe un carrito con este nombre, intenta con otro.')
})
}
async update(attrs: Partial<Carrito>) {
return this.findById(attrs.id_carrito)
.then(async (carrito) => {
if (attrs.carrito)
await this.existeCarrito(carrito.modulo, attrs.carrito)
Object.assign(carrito, attrs);
return this.repository.save(carrito);
return this.repository.save(carrito)
})
.then((_) => ({
message: 'Se actualizo correctamente la información del carrito.',
}));
message: 'Se actualizo correctamente la información del carrito.'
}))
}
}