fix: customer not found (#152)

This commit is contained in:
Sebastian Rindom
2021-01-26 12:10:06 +01:00
committed by GitHub
parent ff49d23322
commit 282eaae675
2 changed files with 12 additions and 14 deletions

View File

@@ -33,23 +33,20 @@ export default async (req, res) => {
}
try {
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async m => {
// Update the cart
await cartService.withTransaction(m).update(id, value)
// Update the cart
await cartService.update(id, value)
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length && !value.region_id) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
// If the cart has payment sessions update these
const updated = await cartService.retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length && !value.region_id) {
await cartService.setPaymentSessions(id)
}
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,

View File

@@ -689,12 +689,13 @@ class CartService extends BaseService {
}
let customer = await this.customerService_
.withTransaction(this.transactionManager_)
.retrieveByEmail(value)
.catch(() => undefined)
if (!customer) {
customer = await this.customerService_
.withTransaction(this.manager_)
.withTransaction(this.transactionManager_)
.create({ email })
}
@@ -1112,7 +1113,7 @@ class CartService extends BaseService {
}
}
}
}, "SERIALIZABLE")
})
}
/**