update del carrito
This commit is contained in:
@@ -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.'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user