@things-factory/marketplace-base 4.0.24 → 4.0.28
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 +100 -13
- 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 +106 -9
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.js +1 -1
- package/dist-server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.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 +5 -5
- package/server/entities/marketplace-product-variation.ts +9 -2
- package/server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.ts +192 -41
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +181 -36
- package/server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.ts +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-marketplace-product-variation.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-product-variation/new-marketplace-product-variation.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,8BAA8B,GAAG,IAAA,qBAAG,EAAA
|
|
1
|
+
{"version":3,"file":"new-marketplace-product-variation.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-product-variation/new-marketplace-product-variation.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,8BAA8B,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;CAuBhD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/marketplace-base",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.28",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/integration-fulfillment": "^4.0.
|
|
28
|
-
"@things-factory/integration-marketplace": "^4.0.
|
|
29
|
-
"@things-factory/shell": "^4.0.
|
|
27
|
+
"@things-factory/integration-fulfillment": "^4.0.28",
|
|
28
|
+
"@things-factory/integration-marketplace": "^4.0.28",
|
|
29
|
+
"@things-factory/shell": "^4.0.28"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "fc526e27ae290a6fa3f001ce7ee75a2904b1d363"
|
|
32
32
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { User } from '@things-factory/auth-base'
|
|
2
|
-
import { Domain } from '@things-factory/shell'
|
|
3
1
|
import {
|
|
4
2
|
Column,
|
|
5
3
|
CreateDateColumn,
|
|
@@ -10,8 +8,13 @@ import {
|
|
|
10
8
|
PrimaryGeneratedColumn,
|
|
11
9
|
UpdateDateColumn
|
|
12
10
|
} from 'typeorm'
|
|
11
|
+
|
|
12
|
+
import { User } from '@things-factory/auth-base'
|
|
13
|
+
import { Domain } from '@things-factory/shell'
|
|
14
|
+
|
|
13
15
|
import { MarketplaceProduct, MarketplaceProductVariationPrice } from '../entities'
|
|
14
16
|
import { NoGenerator } from '../utils'
|
|
17
|
+
|
|
15
18
|
@Entity()
|
|
16
19
|
@Index(
|
|
17
20
|
'ix_marketplace-product-variation_0',
|
|
@@ -33,6 +36,7 @@ export class MarketplaceProductVariation {
|
|
|
33
36
|
this.name = productVariation.name ? productVariation.name.toString() : NoGenerator.id()
|
|
34
37
|
this.description = productVariation.description
|
|
35
38
|
this.qty = productVariation.qty
|
|
39
|
+
this.reserveQty = productVariation.reserveQty
|
|
36
40
|
this.type = productVariation.type
|
|
37
41
|
this.mrpPrice = productVariation.mrpPrice
|
|
38
42
|
this.costPrice = productVariation.costPrice
|
|
@@ -91,6 +95,9 @@ export class MarketplaceProductVariation {
|
|
|
91
95
|
@Column('float', { nullable: true })
|
|
92
96
|
qty: number
|
|
93
97
|
|
|
98
|
+
@Column('float', { nullable: true })
|
|
99
|
+
reserveQty: number
|
|
100
|
+
|
|
94
101
|
@Column({ nullable: true })
|
|
95
102
|
type: string
|
|
96
103
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
@@ -16,7 +16,7 @@ import { NoGenerator } from '../../../utils'
|
|
|
16
16
|
|
|
17
17
|
export const syncAllMarketplaceOrder = {
|
|
18
18
|
async syncAllMarketplaceOrder(_: any, { companyDomainId, fromDate, toDate, blackListStores }, context: any) {
|
|
19
|
-
const { user
|
|
19
|
+
const { user }: { user: User } = context.state
|
|
20
20
|
|
|
21
21
|
const companyDomain: Domain = await getRepository(Domain).findOne(companyDomainId)
|
|
22
22
|
|
|
@@ -127,14 +127,23 @@ export const syncAllMarketplaceOrder = {
|
|
|
127
127
|
otherInfoJSON.shippingProvider = deliveryProvider
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
marketplaceOrder = {
|
|
131
|
+
...existingMarketplaceOrder,
|
|
132
|
+
...marketplaceOrder,
|
|
133
|
+
otherInfoJSON: otherInfoJSON ? JSON.stringify(otherInfoJSON) : null,
|
|
134
|
+
updater: user
|
|
135
|
+
}
|
|
136
|
+
|
|
130
137
|
if (marketplaceOrder?.releaseOrderId) {
|
|
131
138
|
const fulfillmentCenter: FulfillmentCenter = marketplaceOrder.fulfillmentCenter
|
|
132
139
|
const centerId: string = fulfillmentCenter.centerId
|
|
133
|
-
const warehouseDomain: Domain = await
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
const warehouseDomain: Domain = await getRepository(Domain).findOne({
|
|
141
|
+
where: { subdomain: centerId }
|
|
142
|
+
})
|
|
136
143
|
const customerBizplaces: Bizplace[] = await getCustomerBizplaces(warehouseDomain)
|
|
137
|
-
const customerBizplaceId: string = customerBizplaces
|
|
144
|
+
const customerBizplaceId: string = customerBizplaces.find(
|
|
145
|
+
customerBizplace => customerBizplace.company.domain.id == domain.id
|
|
146
|
+
).id
|
|
138
147
|
|
|
139
148
|
let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfillmentCenter, {
|
|
140
149
|
customerBizplaceId,
|
|
@@ -174,9 +183,9 @@ export const syncAllMarketplaceOrder = {
|
|
|
174
183
|
const fulfillmentCenter: FulfillmentCenter = marketplaceOrder.fulfillmentCenter
|
|
175
184
|
const centerId: string = fulfillmentCenter.centerId
|
|
176
185
|
|
|
177
|
-
const warehouseDomain: Domain = await
|
|
178
|
-
|
|
179
|
-
|
|
186
|
+
const warehouseDomain: Domain = await getRepository(Domain).findOne({
|
|
187
|
+
where: { subdomain: centerId }
|
|
188
|
+
})
|
|
180
189
|
const customerBizplaces: Bizplace[] = await getCustomerBizplaces(warehouseDomain)
|
|
181
190
|
const customerBizplaceId: string = customerBizplaces[0].id
|
|
182
191
|
|
|
@@ -380,43 +389,161 @@ export const syncAllMarketplaceOrder = {
|
|
|
380
389
|
nonMatchedOrderItems.push({ ...item })
|
|
381
390
|
}
|
|
382
391
|
})
|
|
383
|
-
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status))
|
|
392
|
+
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
393
|
+
await Promise.all(
|
|
394
|
+
nonMatchedOrderItems.map(async item => {
|
|
395
|
+
if (foundVariation.sku) {
|
|
396
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
397
|
+
MarketplaceProductVariation
|
|
398
|
+
).find({
|
|
399
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
400
|
+
relations: [
|
|
401
|
+
'domain',
|
|
402
|
+
'marketplaceProduct',
|
|
403
|
+
'marketplaceProduct.marketplaceStore',
|
|
404
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
405
|
+
]
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
409
|
+
variation =>
|
|
410
|
+
variation.id != foundVariation.id &&
|
|
411
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
variationsFromOtherStores.map(async variation => {
|
|
415
|
+
variation.reserveQty -= item.qty
|
|
416
|
+
|
|
417
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
foundVariation.qty += item.qty
|
|
422
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
423
|
+
})
|
|
424
|
+
)
|
|
425
|
+
|
|
384
426
|
await getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
427
|
+
}
|
|
385
428
|
|
|
386
|
-
existingOrderItems =
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
itm
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
429
|
+
existingOrderItems = await Promise.all(
|
|
430
|
+
marketplaceOrderItems.map(async item => {
|
|
431
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
432
|
+
itm =>
|
|
433
|
+
itm.name == item.name &&
|
|
434
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
435
|
+
)
|
|
436
|
+
if (matchedOrderItem) {
|
|
437
|
+
if (foundVariation.sku) {
|
|
438
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
439
|
+
MarketplaceProductVariation
|
|
440
|
+
).find({
|
|
441
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
442
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
446
|
+
variation =>
|
|
447
|
+
variation.id != foundVariation.id &&
|
|
448
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
variationsFromOtherStores.map(async variation => {
|
|
452
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
453
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
454
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
455
|
+
|
|
456
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
461
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
462
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
463
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
464
|
+
|
|
465
|
+
return {
|
|
466
|
+
...matchedOrderItem,
|
|
467
|
+
...item,
|
|
468
|
+
updater: user
|
|
469
|
+
}
|
|
397
470
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
471
|
+
})
|
|
472
|
+
)
|
|
400
473
|
} else {
|
|
401
|
-
existingOrderItems =
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
itm
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
474
|
+
existingOrderItems = await Promise.all(
|
|
475
|
+
marketplaceOrderItems.map(async item => {
|
|
476
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
477
|
+
itm =>
|
|
478
|
+
itm.name == item.name &&
|
|
479
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
480
|
+
)
|
|
481
|
+
if (matchedOrderItem) {
|
|
482
|
+
if (foundVariation.sku) {
|
|
483
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
484
|
+
MarketplaceProductVariation
|
|
485
|
+
).find({
|
|
486
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
487
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
488
|
+
})
|
|
489
|
+
|
|
490
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
491
|
+
variation =>
|
|
492
|
+
variation.id != foundVariation.id &&
|
|
493
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
variationsFromOtherStores.map(async variation => {
|
|
497
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
498
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
499
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
500
|
+
|
|
501
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
502
|
+
})
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
506
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
507
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
508
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
509
|
+
|
|
510
|
+
return {
|
|
511
|
+
...matchedOrderItem,
|
|
512
|
+
...item,
|
|
513
|
+
updater: user
|
|
514
|
+
}
|
|
515
|
+
} else {
|
|
516
|
+
if (foundVariation.sku) {
|
|
517
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
518
|
+
MarketplaceProductVariation
|
|
519
|
+
).find({
|
|
520
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
521
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
525
|
+
variation =>
|
|
526
|
+
variation.id != foundVariation.id &&
|
|
527
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
variationsFromOtherStores.map(async variation => {
|
|
531
|
+
variation.reserveQty += item.qty
|
|
532
|
+
|
|
533
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
534
|
+
})
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
foundVariation.qty -= item.qty
|
|
538
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
539
|
+
|
|
540
|
+
return {
|
|
541
|
+
...item,
|
|
542
|
+
updater: user
|
|
543
|
+
}
|
|
412
544
|
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
...item,
|
|
416
|
-
updater: user
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
})
|
|
545
|
+
})
|
|
546
|
+
)
|
|
420
547
|
}
|
|
421
548
|
|
|
422
549
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -429,6 +556,30 @@ export const syncAllMarketplaceOrder = {
|
|
|
429
556
|
}
|
|
430
557
|
}
|
|
431
558
|
} else {
|
|
559
|
+
if (foundVariation.sku) {
|
|
560
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
561
|
+
MarketplaceProductVariation
|
|
562
|
+
).find({
|
|
563
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
564
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
568
|
+
variation =>
|
|
569
|
+
variation.id != foundVariation.id &&
|
|
570
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
variationsFromOtherStores.map(async variation => {
|
|
574
|
+
variation.reserveQty += item.qty
|
|
575
|
+
|
|
576
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
577
|
+
})
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
foundVariation.qty -= item.qty
|
|
581
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
582
|
+
|
|
432
583
|
if (order?.orderShipping) {
|
|
433
584
|
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
434
585
|
savedMarketplaceOrderShipping = await getRepository(MarketplaceOrderShipping).save(
|
|
@@ -124,7 +124,9 @@ 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,
|
|
@@ -285,9 +287,10 @@ export const syncMarketplaceOrder = {
|
|
|
285
287
|
let foundVariation
|
|
286
288
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
287
289
|
var item = order.orderItems[j]
|
|
288
|
-
foundVariation = await tx
|
|
289
|
-
.
|
|
290
|
-
|
|
290
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).findOne({
|
|
291
|
+
where: { domain: marketplaceStore.domain, variationId: item.variationId },
|
|
292
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
293
|
+
})
|
|
291
294
|
|
|
292
295
|
if (!foundVariation) {
|
|
293
296
|
let newVariation: any = {
|
|
@@ -373,43 +376,161 @@ export const syncMarketplaceOrder = {
|
|
|
373
376
|
nonMatchedOrderItems.push({ ...item })
|
|
374
377
|
}
|
|
375
378
|
})
|
|
376
|
-
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status))
|
|
379
|
+
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
380
|
+
await Promise.all(
|
|
381
|
+
nonMatchedOrderItems.map(async item => {
|
|
382
|
+
if (foundVariation.sku) {
|
|
383
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
384
|
+
.getRepository(MarketplaceProductVariation)
|
|
385
|
+
.find({
|
|
386
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
387
|
+
relations: [
|
|
388
|
+
'domain',
|
|
389
|
+
'marketplaceProduct',
|
|
390
|
+
'marketplaceProduct.marketplaceStore',
|
|
391
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
392
|
+
]
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
396
|
+
variation =>
|
|
397
|
+
variation.id != foundVariation.id &&
|
|
398
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
variationsFromOtherStores.map(async variation => {
|
|
402
|
+
variation.reserveQty -= item.qty
|
|
403
|
+
|
|
404
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
405
|
+
})
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
foundVariation.qty += item.qty
|
|
409
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
410
|
+
})
|
|
411
|
+
)
|
|
412
|
+
|
|
377
413
|
await tx.getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
414
|
+
}
|
|
378
415
|
|
|
379
|
-
existingOrderItems =
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
itm
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
416
|
+
existingOrderItems = await Promise.all(
|
|
417
|
+
marketplaceOrderItems.map(async item => {
|
|
418
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
419
|
+
itm =>
|
|
420
|
+
itm.name == item.name &&
|
|
421
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
422
|
+
)
|
|
423
|
+
if (matchedOrderItem) {
|
|
424
|
+
if (foundVariation.sku) {
|
|
425
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
426
|
+
.getRepository(MarketplaceProductVariation)
|
|
427
|
+
.find({
|
|
428
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
429
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
433
|
+
variation =>
|
|
434
|
+
variation.id != foundVariation.id &&
|
|
435
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
variationsFromOtherStores.map(async variation => {
|
|
439
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
440
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
441
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
442
|
+
|
|
443
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
448
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
449
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
450
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
...matchedOrderItem,
|
|
454
|
+
...item,
|
|
455
|
+
updater: user
|
|
456
|
+
}
|
|
390
457
|
}
|
|
391
|
-
}
|
|
392
|
-
|
|
458
|
+
})
|
|
459
|
+
)
|
|
393
460
|
} else {
|
|
394
|
-
existingOrderItems =
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
itm
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
461
|
+
existingOrderItems = await Promise.all(
|
|
462
|
+
marketplaceOrderItems.map(async item => {
|
|
463
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
464
|
+
itm =>
|
|
465
|
+
itm.name == item.name &&
|
|
466
|
+
itm.marketplaceProductVariation.variationId == item.marketplaceProductVariation.variationId
|
|
467
|
+
)
|
|
468
|
+
if (matchedOrderItem) {
|
|
469
|
+
if (foundVariation.sku) {
|
|
470
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
471
|
+
.getRepository(MarketplaceProductVariation)
|
|
472
|
+
.find({
|
|
473
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
474
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
478
|
+
variation =>
|
|
479
|
+
variation.id != foundVariation.id &&
|
|
480
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
variationsFromOtherStores.map(async variation => {
|
|
484
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
485
|
+
? variation.reserveQty + matchedOrderItem.qty
|
|
486
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
487
|
+
|
|
488
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
foundVariation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
493
|
+
? foundVariation.qty - matchedOrderItem.qty
|
|
494
|
+
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
495
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
496
|
+
|
|
497
|
+
return {
|
|
498
|
+
...matchedOrderItem,
|
|
499
|
+
...item,
|
|
500
|
+
updater: user
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
if (foundVariation.sku) {
|
|
504
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
505
|
+
.getRepository(MarketplaceProductVariation)
|
|
506
|
+
.find({
|
|
507
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
508
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
512
|
+
variation =>
|
|
513
|
+
variation.id != foundVariation.id &&
|
|
514
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
variationsFromOtherStores.map(async variation => {
|
|
518
|
+
variation.reserveQty += item.qty
|
|
519
|
+
|
|
520
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
521
|
+
})
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
foundVariation.qty -= item.qty
|
|
525
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
526
|
+
|
|
527
|
+
return {
|
|
528
|
+
...item,
|
|
529
|
+
updater: user
|
|
530
|
+
}
|
|
405
531
|
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
...item,
|
|
409
|
-
updater: user
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
})
|
|
532
|
+
})
|
|
533
|
+
)
|
|
413
534
|
}
|
|
414
535
|
|
|
415
536
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -422,6 +543,30 @@ export const syncMarketplaceOrder = {
|
|
|
422
543
|
}
|
|
423
544
|
}
|
|
424
545
|
} else {
|
|
546
|
+
if (foundVariation.sku) {
|
|
547
|
+
let allVariations: MarketplaceProductVariation[] = await tx
|
|
548
|
+
.getRepository(MarketplaceProductVariation)
|
|
549
|
+
.find({
|
|
550
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
551
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
555
|
+
variation =>
|
|
556
|
+
variation.id != foundVariation.id &&
|
|
557
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
variationsFromOtherStores.map(async variation => {
|
|
561
|
+
variation.reserveQty += item.qty
|
|
562
|
+
|
|
563
|
+
variation = await tx.getRepository(MarketplaceProductVariation).save(variation)
|
|
564
|
+
})
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
foundVariation.qty -= item.qty
|
|
568
|
+
foundVariation = await tx.getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
569
|
+
|
|
425
570
|
if (order?.orderShipping) {
|
|
426
571
|
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
427
572
|
savedMarketplaceOrderShipping = await tx
|
|
@@ -17,7 +17,7 @@ export const marketplaceOrderShippingsResolver = {
|
|
|
17
17
|
.innerJoinAndSelect('MOI.marketplaceProductVariation', 'MPV')
|
|
18
18
|
.innerJoinAndSelect('MOS.marketplaceStore', 'MS')
|
|
19
19
|
.innerJoinAndSelect('MOS.domain', 'domain')
|
|
20
|
-
.
|
|
20
|
+
.leftJoinAndSelect('MOS.creator', 'creator')
|
|
21
21
|
.leftJoinAndSelect('MOS.updater', 'updater')
|
|
22
22
|
|
|
23
23
|
buildQuery(qb, params, context, false)
|