@things-factory/marketplace-base 3.8.10 → 3.8.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/entities/marketplace-product-variation.js +6 -1
- package/dist-server/entities/marketplace-product-variation.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js +135 -25
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js +144 -22
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/dist-server/graphql/types/marketplace-product-variation/marketplace-product-variation-patch.js +1 -0
- package/dist-server/graphql/types/marketplace-product-variation/marketplace-product-variation-patch.js.map +1 -1
- package/dist-server/graphql/types/marketplace-product-variation/marketplace-product-variation.js +1 -0
- package/dist-server/graphql/types/marketplace-product-variation/marketplace-product-variation.js.map +1 -1
- package/dist-server/graphql/types/marketplace-product-variation/new-marketplace-product-variation.js +1 -0
- package/dist-server/graphql/types/marketplace-product-variation/new-marketplace-product-variation.js.map +1 -1
- package/package.json +4 -4
- package/server/entities/marketplace-product-variation.ts +9 -2
- package/server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.ts +229 -53
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +219 -49
- package/server/graphql/types/marketplace-product-variation/marketplace-product-variation-patch.ts +1 -0
- package/server/graphql/types/marketplace-product-variation/marketplace-product-variation.ts +1 -0
- package/server/graphql/types/marketplace-product-variation/new-marketplace-product-variation.ts +1 -0
|
@@ -124,26 +124,53 @@ export const syncMarketplaceOrder = {
|
|
|
124
124
|
const centerId: string = fulfillmentCenter.centerId
|
|
125
125
|
const warehouseDomain: Domain = await tx.getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
126
126
|
const customerBizplaces: Bizplace[] = await getCustomerBizplaces(warehouseDomain)
|
|
127
|
-
const customerBizplaceId: string = customerBizplaces
|
|
127
|
+
const customerBizplaceId: string = customerBizplaces.find(
|
|
128
|
+
customerBizplace => customerBizplace.company.domain.id == domain.id
|
|
129
|
+
).id
|
|
128
130
|
|
|
129
131
|
let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfillmentCenter, {
|
|
130
132
|
customerBizplaceId,
|
|
131
133
|
refNo: marketplaceOrder.orderNo
|
|
132
134
|
})
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
if (existingMarketplaceOrder.isSplitted) {
|
|
137
|
+
for (let a = 0; a < releaseOrders.length; a++) {
|
|
138
|
+
const releaseOrder: any = releaseOrders[a]
|
|
139
|
+
const foundMarketplaceOrderShipping: MarketplaceOrderShipping = await tx
|
|
140
|
+
.getRepository(MarketplaceOrderShipping)
|
|
141
|
+
.findOne({
|
|
142
|
+
where: { domain: marketplaceStore.domain, subOrderNoRef: releaseOrder.refNo2 }
|
|
143
|
+
})
|
|
144
|
+
let patch = {
|
|
145
|
+
id: releaseOrder.id,
|
|
146
|
+
marketplaceOrderStatus: marketplaceOrder.status,
|
|
147
|
+
trackingNo: foundMarketplaceOrderShipping?.trackingNo
|
|
148
|
+
? foundMarketplaceOrderShipping.trackingNo
|
|
149
|
+
: foundMarketplaceOrderShipping.ownTrackingNo,
|
|
150
|
+
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
151
|
+
}
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
await FulfillmentAPI.updateReleaseGoodDetails(fulfillmentCenter, {
|
|
154
|
+
customerBizplaceId,
|
|
155
|
+
releaseOrder: { ...patch },
|
|
156
|
+
shippingOrder: null
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
let releaseOrder = Object.assign({}, releaseOrders[0])
|
|
161
|
+
let patch = {
|
|
162
|
+
id: releaseOrder.id,
|
|
163
|
+
marketplaceOrderStatus: marketplaceOrder.status,
|
|
164
|
+
trackingNo: marketplaceOrder.trackingNo,
|
|
165
|
+
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await FulfillmentAPI.updateReleaseGoodDetails(fulfillmentCenter, {
|
|
169
|
+
customerBizplaceId,
|
|
170
|
+
releaseOrder: { ...patch },
|
|
171
|
+
shippingOrder: null
|
|
172
|
+
})
|
|
173
|
+
}
|
|
147
174
|
|
|
148
175
|
if (cancelStatuses.includes(marketplaceOrder.status)) {
|
|
149
176
|
if (existingMarketplaceOrder.isSplitted) {
|
|
@@ -152,7 +179,7 @@ export const syncMarketplaceOrder = {
|
|
|
152
179
|
})
|
|
153
180
|
|
|
154
181
|
if (releaseOrders?.length) {
|
|
155
|
-
for (
|
|
182
|
+
for (let a = 0; a < releaseOrders.length; a++) {
|
|
156
183
|
const releaseOrderId: string = releaseOrders[a].id
|
|
157
184
|
await FulfillmentAPI.cancelReleaseOrder(fulfillmentCenter, { customerBizplaceId, releaseOrderId })
|
|
158
185
|
}
|
|
@@ -285,9 +312,10 @@ export const syncMarketplaceOrder = {
|
|
|
285
312
|
let foundVariation
|
|
286
313
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
287
314
|
var item = order.orderItems[j]
|
|
288
|
-
foundVariation = await tx
|
|
289
|
-
.
|
|
290
|
-
|
|
315
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).findOne({
|
|
316
|
+
where: { domain: marketplaceStore.domain, variationId: item.variationId },
|
|
317
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
318
|
+
})
|
|
291
319
|
|
|
292
320
|
if (!foundVariation) {
|
|
293
321
|
let newVariation: any = {
|
|
@@ -373,43 +401,161 @@ export const syncMarketplaceOrder = {
|
|
|
373
401
|
nonMatchedOrderItems.push({ ...item })
|
|
374
402
|
}
|
|
375
403
|
})
|
|
376
|
-
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status))
|
|
404
|
+
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
405
|
+
await Promise.all(
|
|
406
|
+
nonMatchedOrderItems.map(async item => {
|
|
407
|
+
if (foundVariation.sku) {
|
|
408
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
409
|
+
.getRepository(MarketplaceProductVariation)
|
|
410
|
+
.find({
|
|
411
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
412
|
+
relations: [
|
|
413
|
+
'domain',
|
|
414
|
+
'marketplaceProduct',
|
|
415
|
+
'marketplaceProduct.marketplaceStore',
|
|
416
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
417
|
+
]
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
421
|
+
variation =>
|
|
422
|
+
variation.id != foundVariation.id &&
|
|
423
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
variationsFromOtherStores.map(async variation => {
|
|
427
|
+
variation.reserveQty -= item.qty
|
|
428
|
+
|
|
429
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
foundVariation.qty += item.qty
|
|
434
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
435
|
+
})
|
|
436
|
+
)
|
|
437
|
+
|
|
377
438
|
await tx.getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
439
|
+
}
|
|
378
440
|
|
|
379
|
-
existingOrderItems =
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
itm
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
441
|
+
existingOrderItems = await Promise.all(
|
|
442
|
+
marketplaceOrderItems.map(async item => {
|
|
443
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
444
|
+
itm =>
|
|
445
|
+
itm.name == item.name &&
|
|
446
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
447
|
+
)
|
|
448
|
+
if (matchedOrderItem) {
|
|
449
|
+
if (foundVariation.sku) {
|
|
450
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
451
|
+
.getRepository(MarketplaceProductVariation)
|
|
452
|
+
.find({
|
|
453
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
454
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
458
|
+
variation =>
|
|
459
|
+
variation.id != foundVariation.id &&
|
|
460
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
variationsFromOtherStores.map(async variation => {
|
|
464
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
465
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
466
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
467
|
+
|
|
468
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
469
|
+
})
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
473
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
474
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
475
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
...matchedOrderItem,
|
|
479
|
+
...item,
|
|
480
|
+
updater: user
|
|
481
|
+
}
|
|
390
482
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
483
|
+
})
|
|
484
|
+
)
|
|
393
485
|
} else {
|
|
394
|
-
existingOrderItems =
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
itm
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
486
|
+
existingOrderItems = await Promise.all(
|
|
487
|
+
marketplaceOrderItems.map(async item => {
|
|
488
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
489
|
+
itm =>
|
|
490
|
+
itm.name == item.name &&
|
|
491
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
492
|
+
)
|
|
493
|
+
if (matchedOrderItem) {
|
|
494
|
+
if (foundVariation.sku) {
|
|
495
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
496
|
+
.getRepository(MarketplaceProductVariation)
|
|
497
|
+
.find({
|
|
498
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
499
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
503
|
+
variation =>
|
|
504
|
+
variation.id != foundVariation.id &&
|
|
505
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
variationsFromOtherStores.map(async variation => {
|
|
509
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
510
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
511
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
512
|
+
|
|
513
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
514
|
+
})
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
518
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
519
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
520
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
...matchedOrderItem,
|
|
524
|
+
...item,
|
|
525
|
+
updater: user
|
|
526
|
+
}
|
|
527
|
+
} else {
|
|
528
|
+
if (foundVariation.sku) {
|
|
529
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
530
|
+
.getRepository(MarketplaceProductVariation)
|
|
531
|
+
.find({
|
|
532
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
533
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
537
|
+
variation =>
|
|
538
|
+
variation.id != foundVariation.id &&
|
|
539
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
variationsFromOtherStores.map(async variation => {
|
|
543
|
+
variation.reserveQty += item.qty
|
|
544
|
+
|
|
545
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
546
|
+
})
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
foundVariation.qty -= item.qty
|
|
550
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
551
|
+
|
|
552
|
+
return {
|
|
553
|
+
...item,
|
|
554
|
+
updater: user
|
|
555
|
+
}
|
|
410
556
|
}
|
|
411
|
-
}
|
|
412
|
-
|
|
557
|
+
})
|
|
558
|
+
)
|
|
413
559
|
}
|
|
414
560
|
|
|
415
561
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -422,6 +568,30 @@ export const syncMarketplaceOrder = {
|
|
|
422
568
|
}
|
|
423
569
|
}
|
|
424
570
|
} else {
|
|
571
|
+
if (foundVariation.sku) {
|
|
572
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
573
|
+
.getRepository(MarketplaceProductVariation)
|
|
574
|
+
.find({
|
|
575
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
576
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
580
|
+
variation =>
|
|
581
|
+
variation.id != foundVariation.id &&
|
|
582
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
variationsFromOtherStores.map(async variation => {
|
|
586
|
+
variation.reserveQty += item.qty
|
|
587
|
+
|
|
588
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
589
|
+
})
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
foundVariation.qty -= item.qty
|
|
593
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
594
|
+
|
|
425
595
|
if (order?.orderShipping) {
|
|
426
596
|
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
427
597
|
savedMarketplaceOrderShipping = await tx
|