hotfix(brightpearl): wrap inventory update in transaction (#184)

This commit is contained in:
Sebastian Rindom authored and GitHub committed 2021-02-24 09:03:50 +01:00
1 parent 90ea888829
commit 5edcbbd7e1
1 file changed
+7 -1
@@ -5,6 +5,7 @@ import Brightpearl from "../utils/brightpearl"
class BrightpearlService extends BaseService { class BrightpearlService extends BaseService {
constructor( constructor(
{ {
manager,
oauthService, oauthService,
totalsService, totalsService,
productVariantService, productVariantService,
@@ -18,6 +19,7 @@ class BrightpearlService extends BaseService {
) { ) {
super() super()
this.manager_ = manager
this.options = options this.options = options
this.productVariantService_ = productVariantService this.productVariantService_ = productVariantService
this.regionService_ = regionService this.regionService_ = regionService
@@ -189,9 +191,13 @@ class BrightpearlService extends BaseService {
.retrieveBySKU(sku) .retrieveBySKU(sku)
.catch((_) => undefined) .catch((_) => undefined)
if (variant && variant.manage_inventory) { if (variant && variant.manage_inventory) {
await this.productVariantService_.update(variant.id, { await this.manager_.transaction((m) => {
return this.productVariantService_
.withTransaction(m)
.update(variant.id, {
inventory_quantity: onHand, inventory_quantity: onHand,
}) })
})
} }
} }
} }