cleanup: Eventbus, BP, Contentful, NotificationService (#292)
This commit is contained in:
1 parent
db9d6c0cf5
commit
c1bec4f843
7 files changed
+34
-15
No files matched your search
@@ -22,10 +22,10 @@ export default (container) => {
|
|||||||
|
|
||||||
app.post("/brightpearl/goods-out", bodyParser.json(), async (req, res) => {
|
app.post("/brightpearl/goods-out", bodyParser.json(), async (req, res) => {
|
||||||
const { id, lifecycle_event } = req.body
|
const { id, lifecycle_event } = req.body
|
||||||
const brightpearlService = req.scope.resolve("brightpearlService")
|
const eventBusService = req.scope.resolve("eventBusService")
|
||||||
|
|
||||||
if (lifecycle_event === "created") {
|
if (lifecycle_event === "created") {
|
||||||
await brightpearlService.createFulfillmentFromGoodsOut(id)
|
eventBusService.emit("brightpearl.goods_out_note", { id })
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
|
|||||||
@@ -1110,6 +1110,7 @@ class BrightpearlService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createFulfillmentFromGoodsOut(id) {
|
async createFulfillmentFromGoodsOut(id) {
|
||||||
|
await this.manager_.transaction(async (m) => {
|
||||||
const client = await this.getClient()
|
const client = await this.getClient()
|
||||||
|
|
||||||
// Get goods out and associated order
|
// Get goods out and associated order
|
||||||
@@ -1146,19 +1147,26 @@ class BrightpearlService extends BaseService {
|
|||||||
|
|
||||||
if (partId) {
|
if (partId) {
|
||||||
if (partId.startsWith("claim")) {
|
if (partId.startsWith("claim")) {
|
||||||
return this.claimService_.createFulfillment(partId, {
|
return this.claimService_
|
||||||
|
.withTransaction(m)
|
||||||
|
.createFulfillment(partId, {
|
||||||
goods_out_note: id,
|
goods_out_note: id,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return this.swapService_.createFulfillment(partId, {
|
return this.swapService_
|
||||||
|
.withTransaction(m)
|
||||||
|
.createFulfillment(partId, {
|
||||||
goods_out_note: id,
|
goods_out_note: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.orderService_.createFulfillment(order.externalRef, lines, {
|
return this.orderService_
|
||||||
|
.withTransaction(m)
|
||||||
|
.createFulfillment(order.externalRef, lines, {
|
||||||
goods_out_note: id,
|
goods_out_note: id,
|
||||||
})
|
})
|
||||||
|
}, "SERIALIZABLE")
|
||||||
}
|
}
|
||||||
|
|
||||||
async createCustomer(fromOrder) {
|
async createCustomer(fromOrder) {
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ class OrderSubscriber {
|
|||||||
|
|
||||||
eventBusService.subscribe("order.placed", this.sendToBrightpearl)
|
eventBusService.subscribe("order.placed", this.sendToBrightpearl)
|
||||||
|
|
||||||
|
eventBusService.subscribe(
|
||||||
|
"brightpearl.goods_out_note",
|
||||||
|
this.createFulfillmentFromGoodsOut
|
||||||
|
)
|
||||||
|
|
||||||
eventBusService.subscribe("claim.created", this.registerClaim)
|
eventBusService.subscribe("claim.created", this.registerClaim)
|
||||||
|
|
||||||
eventBusService.subscribe("order.refund_created", this.registerRefund)
|
eventBusService.subscribe("order.refund_created", this.registerRefund)
|
||||||
@@ -50,6 +55,10 @@ class OrderSubscriber {
|
|||||||
return this.brightpearlService_.createPayment(id)
|
return this.brightpearlService_.createPayment(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createFulfillmentFromGoodsOut = ({ id }) => {
|
||||||
|
return this.brightpearlService_.createFulfillmentFromGoodsOut(id)
|
||||||
|
}
|
||||||
|
|
||||||
registerSwapPayment = async (data) => {
|
registerSwapPayment = async (data) => {
|
||||||
return this.registerSwap({ id: data.id, swap_id: data.id })
|
return this.registerSwap({ id: data.id, swap_id: data.id })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,9 +297,6 @@ class ContentfulService extends BaseService {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// const ignoreIds = (await this.getIgnoreIds_("product_variant")) || []
|
|
||||||
// ignoreIds.push(v.id)
|
|
||||||
// this.redis_.set("product_variant_ignore_ids", JSON.stringify(ignoreIds))
|
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
@@ -311,7 +308,7 @@ class ContentfulService extends BaseService {
|
|||||||
.then(() => true)
|
.then(() => true)
|
||||||
.catch(() => false)
|
.catch(() => false)
|
||||||
if (!hasType) {
|
if (!hasType) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const r = await this.regionService_.retrieve(region.id, {
|
const r = await this.regionService_.retrieve(region.id, {
|
||||||
@@ -353,7 +350,7 @@ class ContentfulService extends BaseService {
|
|||||||
.then(() => true)
|
.then(() => true)
|
||||||
.catch(() => false)
|
.catch(() => false)
|
||||||
if (!hasType) {
|
if (!hasType) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateFields = [
|
const updateFields = [
|
||||||
@@ -435,13 +432,13 @@ class ContentfulService extends BaseService {
|
|||||||
|
|
||||||
const found = data.fields.find((f) => updateFields.includes(f))
|
const found = data.fields.find((f) => updateFields.includes(f))
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ignore = await this.shouldIgnore_(data.id, "contentful")
|
const ignore = await this.shouldIgnore_(data.id, "contentful")
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = await this.productService_.retrieve(data.id, {
|
const p = await this.productService_.retrieve(data.id, {
|
||||||
@@ -594,14 +591,14 @@ class ContentfulService extends BaseService {
|
|||||||
if (variant.fields) {
|
if (variant.fields) {
|
||||||
const found = variant.fields.find((f) => updateFields.includes(f))
|
const found = variant.fields.find((f) => updateFields.includes(f))
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ignore = await this.shouldIgnore_(variant.id, "contentful")
|
const ignore = await this.shouldIgnore_(variant.id, "contentful")
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
const environment = await this.getContentfulEnvironment_()
|
const environment = await this.getContentfulEnvironment_()
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ class VariantSubscriber {
|
|||||||
.triggerRestock(id)
|
.triggerRestock(id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class NotificationService extends BaseService {
|
|||||||
handleEvent(eventName, data) {
|
handleEvent(eventName, data) {
|
||||||
const subs = this.subscribers_[eventName]
|
const subs = this.subscribers_[eventName]
|
||||||
if (!subs) {
|
if (!subs) {
|
||||||
return
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
|
|||||||
@@ -110,10 +110,13 @@ class OrderService extends BaseService {
|
|||||||
shippingOptionService: this.shippingOptionService_,
|
shippingOptionService: this.shippingOptionService_,
|
||||||
shippingProfileService: this.shippingProfileService_,
|
shippingProfileService: this.shippingProfileService_,
|
||||||
fulfillmentProviderService: this.fulfillmentProviderService_,
|
fulfillmentProviderService: this.fulfillmentProviderService_,
|
||||||
|
fulfillmentService: this.fulfillmentService_,
|
||||||
|
customerService: this.customerService_,
|
||||||
discountService: this.discountService_,
|
discountService: this.discountService_,
|
||||||
totalsService: this.totalsService_,
|
totalsService: this.totalsService_,
|
||||||
cartService: this.cartService_,
|
cartService: this.cartService_,
|
||||||
giftCardService: this.giftCardService_,
|
giftCardService: this.giftCardService_,
|
||||||
|
addressRepository: this.addressRepository_,
|
||||||
draftOrderService: this.draftOrderService_,
|
draftOrderService: this.draftOrderService_,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user