@things-factory/operato-hub 6.1.83 → 6.1.85
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/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -46
- package/server/controllers/bizplace-initializer/codes.ts +0 -32
- package/server/controllers/bizplace-initializer/dataset/codes.ts +0 -398
- package/server/controllers/bizplace-initializer/dataset/groups.ts +0 -21
- package/server/controllers/bizplace-initializer/dataset/index.ts +0 -5
- package/server/controllers/bizplace-initializer/dataset/menus.ts +0 -500
- package/server/controllers/bizplace-initializer/dataset/roles-privileges.ts +0 -402
- package/server/controllers/bizplace-initializer/dataset/settings.ts +0 -91
- package/server/controllers/bizplace-initializer/generate-bizplace-domain-roles.ts +0 -29
- package/server/controllers/bizplace-initializer/generate-bizplace-domain.ts +0 -56
- package/server/controllers/bizplace-initializer/groups.ts +0 -19
- package/server/controllers/bizplace-initializer/index.ts +0 -5
- package/server/controllers/bizplace-initializer/menus.ts +0 -42
- package/server/controllers/bizplace-initializer/settings.ts +0 -20
- package/server/controllers/company-initializer/business-register.ts +0 -59
- package/server/controllers/company-initializer/codes.ts +0 -147
- package/server/controllers/company-initializer/generate-company-roles.ts +0 -119
- package/server/controllers/company-initializer/index.ts +0 -6
- package/server/controllers/company-initializer/menus.ts +0 -359
- package/server/controllers/company-initializer/settings.ts +0 -33
- package/server/controllers/company-initializer/transporter.ts +0 -20
- package/server/controllers/index.ts +0 -0
- package/server/controllers/invitation.ts +0 -132
- package/server/controllers/utils/make-invitation-token.ts +0 -5
- package/server/controllers/utils/save-invitation-token.ts +0 -9
- package/server/entities/index.ts +0 -0
- package/server/errors/index.ts +0 -1
- package/server/errors/validation-error.ts +0 -17
- package/server/graphql/index.ts +0 -7
- package/server/graphql/resolvers/generators/generate-bizplace.ts +0 -40
- package/server/graphql/resolvers/generators/generate-company.ts +0 -76
- package/server/graphql/resolvers/generators/index.ts +0 -9
- package/server/graphql/resolvers/generators/update-domain-extType.ts +0 -55
- package/server/graphql/resolvers/index.ts +0 -8
- package/server/graphql/resolvers/invitations/index.ts +0 -5
- package/server/graphql/resolvers/invitations/partner-invitation.ts +0 -62
- package/server/graphql/resolvers/oauth2/company-roles-by-scope.ts +0 -38
- package/server/graphql/resolvers/oauth2/index.ts +0 -5
- package/server/graphql/resolvers/synchronization/auto-update-all-marketplace-product-variation-quantity.ts +0 -180
- package/server/graphql/resolvers/synchronization/create-dat-shipments.ts +0 -64
- package/server/graphql/resolvers/synchronization/fetch-sync-invoices.ts +0 -52
- package/server/graphql/resolvers/synchronization/fetch-sync-products.ts +0 -99
- package/server/graphql/resolvers/synchronization/fetch-sync-purchase-orders.ts +0 -75
- package/server/graphql/resolvers/synchronization/index.ts +0 -26
- package/server/graphql/resolvers/synchronization/sellercraft-pack-marketplace-order.ts +0 -91
- package/server/graphql/resolvers/synchronization/sync-all-products-to-sellercraft.ts +0 -39
- package/server/graphql/resolvers/synchronization/sync-products-from-account.ts +0 -40
- package/server/graphql/resolvers/synchronization/sync-products-to-account.ts +0 -64
- package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +0 -176
- package/server/graphql/types/generators/generate-bizplace-input.ts +0 -11
- package/server/graphql/types/generators/generate-company-input.ts +0 -11
- package/server/graphql/types/generators/index.ts +0 -11
- package/server/graphql/types/generators/update-domain-type-input.ts +0 -8
- package/server/graphql/types/index.ts +0 -10
- package/server/graphql/types/invitations/index.ts +0 -5
- package/server/graphql/types/oauth2/company-role.ts +0 -8
- package/server/graphql/types/oauth2/index.ts +0 -7
- package/server/graphql/types/synchronization/index.ts +0 -33
- package/server/graphql/types/synchronization/sync-invoice-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-invoice-set.ts +0 -38
- package/server/graphql/types/synchronization/sync-product-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-product-set.ts +0 -8
- package/server/graphql/types/synchronization/sync-purchase-order-list.ts +0 -8
- package/server/graphql/types/synchronization/sync-purchase-order-set.ts +0 -28
- package/server/index.ts +0 -37
- package/server/middlewares/business-middleware.ts +0 -32
- package/server/middlewares/index.ts +0 -20
- package/server/middlewares/store-middleware.ts +0 -36
- package/server/middlewares/warehouse-middleware.ts +0 -36
- package/server/migrations/1597668478399-SeedBusinessDomain.ts +0 -34
- package/server/migrations/1597668478401-SeedBusinessRoles.ts +0 -377
- package/server/migrations/1608009991065-SeedUser.ts +0 -64
- package/server/migrations/index.ts +0 -9
- package/server/routers/api/index.ts +0 -3
- package/server/routers/api/restful-apis/unstable/add-contact-point.ts +0 -89
- package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +0 -198
- package/server/routers/api/restful-apis/unstable/add-inbound-order.ts +0 -246
- package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +0 -171
- package/server/routers/api/restful-apis/unstable/add-products.ts +0 -112
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +0 -1061
- package/server/routers/api/restful-apis/unstable/add-sales-invoice.ts +0 -144
- package/server/routers/api/restful-apis/unstable/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/unstable/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/unstable/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/unstable/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/unstable/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/unstable/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/unstable/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/unstable/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/unstable/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/unstable/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/unstable/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/unstable/get-inventory-product-group.ts +0 -107
- package/server/routers/api/restful-apis/unstable/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/unstable/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/unstable/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/unstable/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/unstable/get-products.ts +0 -216
- package/server/routers/api/restful-apis/unstable/get-release-order-detail.ts +0 -138
- package/server/routers/api/restful-apis/unstable/get-release-order-list.ts +0 -199
- package/server/routers/api/restful-apis/unstable/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/unstable/index.ts +0 -32
- package/server/routers/api/restful-apis/unstable/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/unstable/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/unstable/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/unstable/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/unstable/update-marketplace-shipping-order.ts +0 -107
- package/server/routers/api/restful-apis/unstable/update-release-order-details.ts +0 -94
- package/server/routers/api/restful-apis/v1/add-contact-point.ts +0 -77
- package/server/routers/api/restful-apis/v1/add-draft-release-order.ts +0 -196
- package/server/routers/api/restful-apis/v1/add-inbound-order.ts +0 -243
- package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +0 -172
- package/server/routers/api/restful-apis/v1/add-products.ts +0 -112
- package/server/routers/api/restful-apis/v1/add-release-order.ts +0 -967
- package/server/routers/api/restful-apis/v1/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/v1/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/v1/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/v1/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/v1/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/v1/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/v1/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/v1/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/v1/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/v1/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/v1/get-inventory-product-group.ts +0 -112
- package/server/routers/api/restful-apis/v1/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/v1/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/v1/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/v1/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/v1/get-products.ts +0 -216
- package/server/routers/api/restful-apis/v1/get-release-order-detail.ts +0 -134
- package/server/routers/api/restful-apis/v1/get-release-order-list.ts +0 -198
- package/server/routers/api/restful-apis/v1/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/v1/index.ts +0 -31
- package/server/routers/api/restful-apis/v1/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/v1/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/v1/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/v1/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/v1/update-marketplace-shipping-order.ts +0 -104
- package/server/routers/api/restful-apis/v1/update-release-order-details.ts +0 -94
- package/server/routers/api/restful-apis/v2/add-contact-point.ts +0 -77
- package/server/routers/api/restful-apis/v2/add-draft-release-order.ts +0 -196
- package/server/routers/api/restful-apis/v2/add-inbound-order.ts +0 -243
- package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +0 -172
- package/server/routers/api/restful-apis/v2/add-products.ts +0 -112
- package/server/routers/api/restful-apis/v2/add-release-order.ts +0 -967
- package/server/routers/api/restful-apis/v2/bizplace.ts +0 -45
- package/server/routers/api/restful-apis/v2/cancel-marketplace-order.ts +0 -81
- package/server/routers/api/restful-apis/v2/cancel-release-order.ts +0 -91
- package/server/routers/api/restful-apis/v2/get-contact-point-list.ts +0 -110
- package/server/routers/api/restful-apis/v2/get-delivery-order-detail.ts +0 -46
- package/server/routers/api/restful-apis/v2/get-delivery-order-list.ts +0 -121
- package/server/routers/api/restful-apis/v2/get-delivery-orders.ts +0 -178
- package/server/routers/api/restful-apis/v2/get-goods-received-notes.ts +0 -134
- package/server/routers/api/restful-apis/v2/get-inbound-order-detail.ts +0 -128
- package/server/routers/api/restful-apis/v2/get-inbound-order-list.ts +0 -126
- package/server/routers/api/restful-apis/v2/get-inventory-overall-product-group.ts +0 -99
- package/server/routers/api/restful-apis/v2/get-inventory-product-group.ts +0 -112
- package/server/routers/api/restful-apis/v2/get-marketplace-order-shipping-list.ts +0 -156
- package/server/routers/api/restful-apis/v2/get-marketplace-store-list.ts +0 -81
- package/server/routers/api/restful-apis/v2/get-onhand-inventories.ts +0 -125
- package/server/routers/api/restful-apis/v2/get-partners.ts +0 -26
- package/server/routers/api/restful-apis/v2/get-products.ts +0 -216
- package/server/routers/api/restful-apis/v2/get-release-order-detail.ts +0 -134
- package/server/routers/api/restful-apis/v2/get-release-order-list.ts +0 -198
- package/server/routers/api/restful-apis/v2/get-warehouses.ts +0 -19
- package/server/routers/api/restful-apis/v2/index.ts +0 -31
- package/server/routers/api/restful-apis/v2/reject-inbound-order.ts +0 -46
- package/server/routers/api/restful-apis/v2/set-marketplace-order-delivered.ts +0 -60
- package/server/routers/api/restful-apis/v2/set-marketplace-order-failed-delivery.ts +0 -60
- package/server/routers/api/restful-apis/v2/update-marketplace-order.ts +0 -111
- package/server/routers/api/restful-apis/v2/update-marketplace-shipping-order.ts +0 -104
- package/server/routers/api/restful-apis/v2/update-release-order-details.ts +0 -94
- package/server/routers/auth-invitation-router.ts +0 -25
- package/server/routers/business/bizplace-register-router.ts +0 -31
- package/server/routers/business/business-register-router.ts +0 -32
- package/server/routers/business/index.ts +0 -3
- package/server/routers/business/path-base-business-router.ts +0 -15
- package/server/routes.ts +0 -28
- package/server/templates/account-unlock-email.ts +0 -64
- package/server/templates/invitation-email.ts +0 -65
- package/server/templates/reset-password-email.ts +0 -64
- package/server/templates/verification-email.ts +0 -65
- package/server/utils/build-map.ts +0 -18
- package/server/utils/get-warehouses.ts +0 -115
- package/server/utils/index.ts +0 -3
- package/server/utils/order-no-generator.ts +0 -8
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { getConnection, getRepository } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { logger } from '@things-factory/env'
|
|
4
|
-
import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
|
|
5
|
-
import { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
6
|
-
import { MarketplaceProductVariation } from '@things-factory/marketplace-base'
|
|
7
|
-
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
8
|
-
import { Domain } from '@things-factory/shell'
|
|
9
|
-
import { getProductBundleInventory, Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
10
|
-
|
|
11
|
-
export const autoUpdateAllMarketplaceProductVariationQuantityResolver = {
|
|
12
|
-
async autoUpdateAllMarketplaceProductVariationQuantity(_: any, { companyDomainId, warehouseId }, context: any) {
|
|
13
|
-
const companyDomain: Domain = await getRepository(Domain).findOne(companyDomainId)
|
|
14
|
-
|
|
15
|
-
const marketplaceStores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({
|
|
16
|
-
where: { domain: { id: companyDomain.id }, status: 'ACTIVE' },
|
|
17
|
-
relations: ['marketplaceDistributors']
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
21
|
-
const centerId: string = fulfilmentCenter.centerId
|
|
22
|
-
const warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
23
|
-
|
|
24
|
-
let products: Product[] = await getRepository(Product).find({
|
|
25
|
-
where: { domain: { id: companyDomain.id } },
|
|
26
|
-
relations: ['productDetails']
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
let inventoryProducts: any[] = await Promise.all(
|
|
30
|
-
products.map(async product => {
|
|
31
|
-
const productDetails: ProductDetail[] = product.productDetails
|
|
32
|
-
const defaultProductDetail: ProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0]
|
|
33
|
-
|
|
34
|
-
let qb = await getRepository(Inventory).createQueryBuilder('inv')
|
|
35
|
-
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
36
|
-
.andWhere('"inv"."domain_id" = :domainId')
|
|
37
|
-
.andWhere('"inv"."product_id" = :productId')
|
|
38
|
-
.andWhere('"inv"."status" != :status')
|
|
39
|
-
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
40
|
-
.setParameters({
|
|
41
|
-
domainId: warehouseDomain.id,
|
|
42
|
-
productId: product.id,
|
|
43
|
-
status: INVENTORY_STATUS.TERMINATED,
|
|
44
|
-
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
let inventories: Inventory[] = await qb.getMany()
|
|
48
|
-
|
|
49
|
-
const inventoryQty: number = inventories.reduce((total, currentValue) => {
|
|
50
|
-
total += currentValue.qty
|
|
51
|
-
return total
|
|
52
|
-
}, 0)
|
|
53
|
-
|
|
54
|
-
const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {
|
|
55
|
-
total += currentValue.lockedQty
|
|
56
|
-
return total
|
|
57
|
-
}, 0)
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
product,
|
|
61
|
-
sku: product.sku,
|
|
62
|
-
name: product.name,
|
|
63
|
-
packingType: defaultProductDetail.packingType,
|
|
64
|
-
packingSize: defaultProductDetail.packingSize,
|
|
65
|
-
uom: defaultProductDetail.uom,
|
|
66
|
-
qty: inventoryQty - inventoryLockedQty
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
await getConnection().transaction(async tx => {
|
|
72
|
-
let bundleProductInventories: any[] = await getProductBundleInventory(
|
|
73
|
-
warehouseDomain,
|
|
74
|
-
companyDomain,
|
|
75
|
-
inventoryProducts,
|
|
76
|
-
tx
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
bundleProductInventories.map(bundleProductInventory => {
|
|
80
|
-
inventoryProducts.push(bundleProductInventory)
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
for (let i = 0; i < marketplaceStores.length; i++) {
|
|
85
|
-
try {
|
|
86
|
-
const marketplaceStore: MarketplaceStore = marketplaceStores[i]
|
|
87
|
-
|
|
88
|
-
const marketplaceSetting: MarketplaceSetting = await getRepository(MarketplaceSetting).findOne({
|
|
89
|
-
where: { marketplaceStore: { id: marketplaceStore.id }, category: 'stock_allocation' }
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
for (let j = 0; j < inventoryProducts.length; j++) {
|
|
93
|
-
try {
|
|
94
|
-
await getConnection().transaction(async tx => {
|
|
95
|
-
const inventoryProduct = inventoryProducts[j]
|
|
96
|
-
const marketplaceProductVariations: MarketplaceProductVariation[] = await tx
|
|
97
|
-
.getRepository(MarketplaceProductVariation)
|
|
98
|
-
.find({
|
|
99
|
-
where: { domain: { id: companyDomain.id }, sku: inventoryProduct.sku },
|
|
100
|
-
relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
|
|
104
|
-
productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
let percentageValue: number = 100
|
|
108
|
-
if (storeProductVariations) {
|
|
109
|
-
for (let k = 0; k < storeProductVariations.length; k++) {
|
|
110
|
-
let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
|
|
111
|
-
if (marketplaceSetting) {
|
|
112
|
-
percentageValue = parseInt(marketplaceSetting.value)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let remainQty: number = Math.floor(
|
|
116
|
-
(inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
|
|
117
|
-
)
|
|
118
|
-
if (remainQty < 0) remainQty = 0
|
|
119
|
-
|
|
120
|
-
let productVariationLocationId = storeProductVariation?.locationId
|
|
121
|
-
let adjustQty: number = remainQty
|
|
122
|
-
|
|
123
|
-
if (marketplaceStore.platform === 'shopify') {
|
|
124
|
-
let locationIds: any[] = JSON.parse(productVariationLocationId)
|
|
125
|
-
adjustQty = adjustQty - storeProductVariation.qty
|
|
126
|
-
if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let validMarketplaceDistributors: any[] = []
|
|
130
|
-
if (marketplaceStore.marketplaceDistributors) {
|
|
131
|
-
validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
|
|
132
|
-
distributor => distributor.status === 'ACTIVE'
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const hasVariation: boolean = storeProductVariation?.marketplaceProduct?.hasVariation
|
|
137
|
-
|
|
138
|
-
if (hasVariation) {
|
|
139
|
-
await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
|
|
140
|
-
{
|
|
141
|
-
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
142
|
-
variationId: storeProductVariation.variationId,
|
|
143
|
-
variationSku: storeProductVariation.variationSku,
|
|
144
|
-
qty: adjustQty,
|
|
145
|
-
locationId: productVariationLocationId,
|
|
146
|
-
inventoryItemId: storeProductVariation.inventoryItemId,
|
|
147
|
-
distributors: validMarketplaceDistributors
|
|
148
|
-
}
|
|
149
|
-
])
|
|
150
|
-
} else {
|
|
151
|
-
await StoreAPI.updateStoreProductStock(marketplaceStore, [
|
|
152
|
-
{
|
|
153
|
-
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
154
|
-
variationId: storeProductVariation.variationId,
|
|
155
|
-
variationSku: storeProductVariation.variationSku,
|
|
156
|
-
qty: adjustQty,
|
|
157
|
-
distributors: validMarketplaceDistributors
|
|
158
|
-
}
|
|
159
|
-
])
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
storeProductVariation.qty = remainQty
|
|
163
|
-
await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
} catch (error) {
|
|
168
|
-
logger.error(
|
|
169
|
-
`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
} catch (e) {
|
|
174
|
-
logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return true
|
|
179
|
-
}
|
|
180
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { getConnection, MoreThan } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
4
|
-
import { logger } from '@things-factory/env'
|
|
5
|
-
import { Sftp, SftpAPI } from '@things-factory/integration-sftp'
|
|
6
|
-
import { ReleaseGood } from '@things-factory/sales-base'
|
|
7
|
-
import { Domain } from '@things-factory/shell'
|
|
8
|
-
|
|
9
|
-
export const createDatShipments = {
|
|
10
|
-
async createDatShipments(_: void, {}, context: ResolverContext): Promise<void> {
|
|
11
|
-
try {
|
|
12
|
-
await getConnection().transaction(async tx => {
|
|
13
|
-
const currentTime = new Date()
|
|
14
|
-
const batchSize = 80
|
|
15
|
-
let sftps: Sftp[] = await tx.getRepository(Sftp).find({
|
|
16
|
-
where: { status: 'ACTIVE' },
|
|
17
|
-
relations: ['domain', 'fulfillmentCenter']
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
for (let sftp of sftps) {
|
|
21
|
-
let warehouseDomain: Domain = await tx.getRepository(Domain).findOne({
|
|
22
|
-
where: { subdomain: sftp.fulfillmentCenter.centerId }
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
let bizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
26
|
-
where: { domain: { id: sftp.domain.id } }
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
let releaseGoods: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
|
|
30
|
-
where: {
|
|
31
|
-
domain: { id: warehouseDomain.id },
|
|
32
|
-
bizplace: { id: bizplace.id },
|
|
33
|
-
status: 'DONE',
|
|
34
|
-
updatedAt: MoreThan(sftp.lastTimeSync)
|
|
35
|
-
},
|
|
36
|
-
relations: ['orderInventories', 'orderInventories.product']
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
while (releaseGoods.length > 0) {
|
|
40
|
-
let releaseGoodBatch = releaseGoods.splice(
|
|
41
|
-
0,
|
|
42
|
-
releaseGoods.length >= batchSize ? batchSize : releaseGoods.length
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
const responseFileTypes: any = JSON.parse(sftp.responseFileTypes)
|
|
46
|
-
|
|
47
|
-
if (releaseGoodBatch.length > 0) {
|
|
48
|
-
if (responseFileTypes.enableShipment) {
|
|
49
|
-
let shipmentResult: Sftp = await SftpAPI.createShipment(sftp, {
|
|
50
|
-
releaseGoods: releaseGoodBatch,
|
|
51
|
-
sftp: sftp
|
|
52
|
-
})
|
|
53
|
-
shipmentResult.lastTimeSync = currentTime
|
|
54
|
-
sftp = await tx.getRepository(Sftp).save(shipmentResult)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
} catch (e) {
|
|
61
|
-
logger.error(`createDatShipment: ${e}`)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { AccountingAPI } from '@things-factory/integration-accounting'
|
|
2
|
-
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
3
|
-
|
|
4
|
-
export const fetchSyncInvoicesResolver = {
|
|
5
|
-
async fetchSyncInvoices(
|
|
6
|
-
_: void,
|
|
7
|
-
{
|
|
8
|
-
accountId,
|
|
9
|
-
warehouseId,
|
|
10
|
-
customerBizplaceId
|
|
11
|
-
}: {
|
|
12
|
-
accountId: string
|
|
13
|
-
warehouseId: string
|
|
14
|
-
customerBizplaceId: string
|
|
15
|
-
},
|
|
16
|
-
context: any
|
|
17
|
-
): Promise<void> {
|
|
18
|
-
try {
|
|
19
|
-
await getAccountingInvoices(accountId, warehouseId, customerBizplaceId)
|
|
20
|
-
return
|
|
21
|
-
} catch (e) {
|
|
22
|
-
throw e
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function getAccountingInvoices(accountId: string, warehouseId: string, customerBizplaceId: string) {
|
|
28
|
-
try {
|
|
29
|
-
const accounting: AccountingAPI = await AccountingAPI.getAccounting(accountId)
|
|
30
|
-
|
|
31
|
-
const fulfilmentCenter: FulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
32
|
-
const invoices: any[] = await AccountingAPI.getInvoices(accounting, { Statuses: 'AUTHORISED' })
|
|
33
|
-
|
|
34
|
-
for (var i = 0; i < invoices.length; i++) {
|
|
35
|
-
const releaseOrder = invoices[i]
|
|
36
|
-
|
|
37
|
-
const existingReleaseOrder = await FulfillmentAPI.getOutboundOrder(fulfilmentCenter, {
|
|
38
|
-
customerBizplaceId,
|
|
39
|
-
refNo: releaseOrder.refNo
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
if (!existingReleaseOrder) {
|
|
43
|
-
await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
44
|
-
customerBizplaceId,
|
|
45
|
-
releaseOrder
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
} catch (e) {
|
|
50
|
-
throw new Error(e.statusText)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
2
|
-
import { AccountingAPI } from '@things-factory/integration-accounting'
|
|
3
|
-
import { Product } from '@things-factory/product-base'
|
|
4
|
-
import { getRepository } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { buildMap } from '../../../utils/build-map'
|
|
7
|
-
|
|
8
|
-
export const fetchSyncProductsResolver = {
|
|
9
|
-
async fetchSyncProducts(
|
|
10
|
-
_: void,
|
|
11
|
-
{
|
|
12
|
-
accountId,
|
|
13
|
-
bizplaceId,
|
|
14
|
-
pagination
|
|
15
|
-
}: { accountId: string; bizplaceId: string; pagination: { page: number; limit: number } },
|
|
16
|
-
context: any
|
|
17
|
-
): Promise<{ items: { bizplaceProduct: Product; platformProduct: Product }[]; total: number }> {
|
|
18
|
-
try {
|
|
19
|
-
const platformProducts: Product[] = await getAccountingProducts(accountId)
|
|
20
|
-
const platformProductsMap: Map<string, Product> = buildMap(platformProducts, 'sku')
|
|
21
|
-
|
|
22
|
-
const bizplace: Bizplace = await getRepository(Bizplace).findOneBy({ id: bizplaceId })
|
|
23
|
-
const bizplaceProducts: Product[] = await getRepository(Product).find({
|
|
24
|
-
where: { bizplace: { id: bizplace.id } }
|
|
25
|
-
})
|
|
26
|
-
const bizplaceProductsMap: Map<string, Product> = buildMap(bizplaceProducts, 'sku')
|
|
27
|
-
|
|
28
|
-
let items: { bizplaceProduct: Product; platformProduct: Product }[] = []
|
|
29
|
-
|
|
30
|
-
if (platformProductsMap.size) {
|
|
31
|
-
platformProductsMap.forEach((platformProduct: Product) => {
|
|
32
|
-
const { sku }: Product = platformProduct
|
|
33
|
-
|
|
34
|
-
let bizplaceProduct: Product = {}
|
|
35
|
-
|
|
36
|
-
if (bizplaceProductsMap.has(sku)) {
|
|
37
|
-
bizplaceProduct = bizplaceProductsMap.get(sku)
|
|
38
|
-
bizplaceProductsMap.delete(sku)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
platformProductsMap.delete(sku)
|
|
42
|
-
|
|
43
|
-
items.push({
|
|
44
|
-
bizplaceProduct,
|
|
45
|
-
platformProduct
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (bizplaceProductsMap.size) {
|
|
51
|
-
bizplaceProductsMap.forEach((bizplaceProduct: Product) => {
|
|
52
|
-
const { sku }: Product = bizplaceProduct
|
|
53
|
-
|
|
54
|
-
let platformProduct: Product = {}
|
|
55
|
-
|
|
56
|
-
if (platformProductsMap.has(sku)) {
|
|
57
|
-
platformProduct = platformProductsMap.get(sku)
|
|
58
|
-
platformProductsMap.delete(sku)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
bizplaceProductsMap.delete(sku)
|
|
62
|
-
|
|
63
|
-
items.push({
|
|
64
|
-
bizplaceProduct,
|
|
65
|
-
platformProduct
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const { page, limit }: { page: number; limit: number } = pagination
|
|
71
|
-
const startIdx: number = (page - 1) * limit
|
|
72
|
-
const endIdx: number = page * limit
|
|
73
|
-
|
|
74
|
-
const total = items.length
|
|
75
|
-
items = items.slice(startIdx, endIdx)
|
|
76
|
-
|
|
77
|
-
return { items, total }
|
|
78
|
-
} catch (e) {
|
|
79
|
-
throw e
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function sortBySku(products: Product[]): Product[] {
|
|
85
|
-
return products.sort((a: Product, b: Product) => {
|
|
86
|
-
if (a.sku > b.sku) return 1
|
|
87
|
-
if (a.sku < b.sku) return -1
|
|
88
|
-
return 0
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function getAccountingProducts(accountId: string): Promise<Product[]> {
|
|
93
|
-
try {
|
|
94
|
-
const accounting: AccountingAPI = await AccountingAPI.getAccounting(accountId)
|
|
95
|
-
return await AccountingAPI.getItems(accounting)
|
|
96
|
-
} catch (e) {
|
|
97
|
-
throw new Error(e.statusText)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AccountingAPI } from '@things-factory/integration-accounting'
|
|
2
|
-
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
3
|
-
import { logger } from '@things-factory/env'
|
|
4
|
-
|
|
5
|
-
export const fetchSyncPurchaseOrdersResolver = {
|
|
6
|
-
async fetchSyncPurchaseOrders(
|
|
7
|
-
_: void,
|
|
8
|
-
{
|
|
9
|
-
accountId,
|
|
10
|
-
warehouseId,
|
|
11
|
-
customerBizplaceId,
|
|
12
|
-
fromDate,
|
|
13
|
-
toDate
|
|
14
|
-
}: { accountId: string; warehouseId: string; customerBizplaceId: string; fromDate: string; toDate: string },
|
|
15
|
-
context: any
|
|
16
|
-
): Promise<void> {
|
|
17
|
-
try {
|
|
18
|
-
await getAccountingPurchaseOrders(accountId, warehouseId, customerBizplaceId, fromDate, toDate)
|
|
19
|
-
} catch (e) {
|
|
20
|
-
logger.error(`Xero: fetchSyncPurchaseOrders: ${e}`)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function getAccountingPurchaseOrders(
|
|
26
|
-
accountId: string,
|
|
27
|
-
warehouseId: string,
|
|
28
|
-
customerBizplaceId: string,
|
|
29
|
-
fromDate: string,
|
|
30
|
-
toDate: string
|
|
31
|
-
) {
|
|
32
|
-
try {
|
|
33
|
-
const accounting: AccountingAPI = await AccountingAPI.getAccounting(accountId)
|
|
34
|
-
|
|
35
|
-
const fulfilmentCenter: FulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
36
|
-
let parameters: any = { status: 'AUTHORISED' }
|
|
37
|
-
|
|
38
|
-
if (fromDate) {
|
|
39
|
-
if (!toDate) throw new Error('From Date setting requires To Date')
|
|
40
|
-
parameters = { ...parameters, DateFrom: fromDate, DateTo: toDate }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const purchaseOrders: any[] = await AccountingAPI.getPurchaseOrders(accounting, { ...parameters })
|
|
44
|
-
await createInboundOrder(fulfilmentCenter, purchaseOrders, customerBizplaceId)
|
|
45
|
-
} catch (e) {
|
|
46
|
-
logger.error(`Xero: getAccountingPurchaseOrders: ${e}`)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function createInboundOrder(
|
|
51
|
-
fulfilmentCenter: FulfillmentCenter,
|
|
52
|
-
purchaseOrders: any[],
|
|
53
|
-
customerBizplaceId: string
|
|
54
|
-
) {
|
|
55
|
-
for (var i = 0; i < purchaseOrders.length; i++) {
|
|
56
|
-
try {
|
|
57
|
-
const purchaseOrder = purchaseOrders[i]
|
|
58
|
-
|
|
59
|
-
const existingArrivalNotice = await FulfillmentAPI.getInboundOrder(fulfilmentCenter, {
|
|
60
|
-
customerBizplaceId,
|
|
61
|
-
refNo: purchaseOrder.refNo,
|
|
62
|
-
ganNo: null
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if (!existingArrivalNotice?.id) {
|
|
66
|
-
await FulfillmentAPI.createInboundOrder(fulfilmentCenter, {
|
|
67
|
-
customerBizplaceId,
|
|
68
|
-
purchaseOrder
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
} catch (e) {
|
|
72
|
-
logger.error(`Xero: createInboundOrder: ${e}`)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { fetchSyncInvoicesResolver } from './fetch-sync-invoices'
|
|
2
|
-
import { fetchSyncProductsResolver } from './fetch-sync-products'
|
|
3
|
-
import { fetchSyncPurchaseOrdersResolver } from './fetch-sync-purchase-orders'
|
|
4
|
-
import { sellercraftPackMarketplaceOrderResolver } from './sellercraft-pack-marketplace-order'
|
|
5
|
-
import { syncAllProductsToSellercraftResolver } from './sync-all-products-to-sellercraft'
|
|
6
|
-
import { syncProductsFromAccountResolver } from './sync-products-from-account'
|
|
7
|
-
import { syncProductsToAccountResolver } from './sync-products-to-account'
|
|
8
|
-
import { syncProductsToSellercraftResolver } from './sync-products-to-sellercraft'
|
|
9
|
-
import { createDatShipments } from './create-dat-shipments'
|
|
10
|
-
import { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity'
|
|
11
|
-
|
|
12
|
-
export const Query = {
|
|
13
|
-
...fetchSyncProductsResolver,
|
|
14
|
-
...fetchSyncPurchaseOrdersResolver,
|
|
15
|
-
...fetchSyncInvoicesResolver
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const Mutation = {
|
|
19
|
-
...syncProductsToSellercraftResolver,
|
|
20
|
-
...syncProductsFromAccountResolver,
|
|
21
|
-
...syncProductsToAccountResolver,
|
|
22
|
-
...syncAllProductsToSellercraftResolver,
|
|
23
|
-
...sellercraftPackMarketplaceOrderResolver,
|
|
24
|
-
...createDatShipments,
|
|
25
|
-
...autoUpdateAllMarketplaceProductVariationQuantityResolver
|
|
26
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { getConnection, In, IsNull, Not, Repository } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
4
|
-
import { logger } from '@things-factory/env'
|
|
5
|
-
import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
|
|
6
|
-
import { Sellercraft, SellercraftAPI, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
7
|
-
import { Product } from '@things-factory/product-base'
|
|
8
|
-
import { ORDER_STATUS, OrderProduct, ReleaseGood } from '@things-factory/sales-base'
|
|
9
|
-
import { Domain } from '@things-factory/shell'
|
|
10
|
-
|
|
11
|
-
export const sellercraftPackMarketplaceOrderResolver = {
|
|
12
|
-
async sellercraftPackMarketplaceOrder(_: void, {}, context: ResolverContext): Promise<void> {
|
|
13
|
-
try {
|
|
14
|
-
await getConnection().transaction(async tx => {
|
|
15
|
-
const sellercrafts: Sellercraft[] = await tx
|
|
16
|
-
.getRepository(Sellercraft)
|
|
17
|
-
.find({ where: { status: SellercraftStatus.ACTIVE }, relations: ['domain'] })
|
|
18
|
-
|
|
19
|
-
for (const sellercraft of sellercrafts) {
|
|
20
|
-
try {
|
|
21
|
-
const sellercraftDomain: Domain = sellercraft.domain
|
|
22
|
-
const bizplace: Bizplace = await tx
|
|
23
|
-
.getRepository(Bizplace)
|
|
24
|
-
.findOne({ where: { domain: { id: sellercraftDomain.id } } })
|
|
25
|
-
|
|
26
|
-
let releaseGoodsWithoutPackageId: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
|
|
27
|
-
where: {
|
|
28
|
-
bizplace: { id: bizplace.id },
|
|
29
|
-
type: 'b2c',
|
|
30
|
-
packageId: IsNull(),
|
|
31
|
-
status: Not(In([ORDER_STATUS.CANCELLED, ORDER_STATUS.PENDING_CANCEL, ORDER_STATUS.DONE]))
|
|
32
|
-
},
|
|
33
|
-
relations: ['domain', 'orderProducts', 'orderProducts.product']
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
if (releaseGoodsWithoutPackageId?.length > 0) {
|
|
37
|
-
await Promise.all(
|
|
38
|
-
releaseGoodsWithoutPackageId.map(async releaseGood => {
|
|
39
|
-
const orderProducts: OrderProduct[] = releaseGood.orderProducts
|
|
40
|
-
let sellercraftOPs: any[] = []
|
|
41
|
-
|
|
42
|
-
sellercraftOPs = orderProducts.map(orderProduct => {
|
|
43
|
-
const product: Product = orderProduct.product
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
sku: product.sku,
|
|
47
|
-
releaseQty: orderProduct.releaseQty,
|
|
48
|
-
uom: 'EA'
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
const orderInformation: any = {
|
|
53
|
-
accountId: sellercraft.accountId,
|
|
54
|
-
orderId: releaseGood.refNo2,
|
|
55
|
-
sellercraftOPs
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const packageId: string = await SellercraftAPI.packMarketplaceOrder(sellercraft, {
|
|
59
|
-
...orderInformation,
|
|
60
|
-
context: { state: { domain: releaseGood?.domain, user: null } }
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
createPayloadLog(
|
|
64
|
-
sellercraft.accountId,
|
|
65
|
-
`/order/pack`,
|
|
66
|
-
orderInformation,
|
|
67
|
-
packageId,
|
|
68
|
-
context,
|
|
69
|
-
PayloadType.EGESTION,
|
|
70
|
-
'scheduler'
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
if (packageId) {
|
|
74
|
-
await (tx.getRepository(ReleaseGood) as Repository<ReleaseGood>).update(
|
|
75
|
-
{ id: releaseGood.id },
|
|
76
|
-
{ packageId: packageId }
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
} catch (e) {
|
|
83
|
-
logger.error(`sellercraftPackMarketplaceOrder: ${e}`)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
} catch (e) {
|
|
88
|
-
logger.error(`sellercraftPackMarketplaceOrder: ${e}`)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { getConnection } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Bizplace, getCompanyBizplace } from '@things-factory/biz-base'
|
|
4
|
-
import { FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
5
|
-
import { Sellercraft } from '@things-factory/integration-sellercraft'
|
|
6
|
-
|
|
7
|
-
import { syncProductsToSellercraftResolver as resolver } from './sync-products-to-sellercraft'
|
|
8
|
-
|
|
9
|
-
export const syncAllProductsToSellercraftResolver = {
|
|
10
|
-
async syncAllProductsToSellercraft(_: any, {}, context: ResolverContext): Promise<void> {
|
|
11
|
-
const { user } = context.state
|
|
12
|
-
try {
|
|
13
|
-
await getConnection().transaction(async tx => {
|
|
14
|
-
const qb = await tx
|
|
15
|
-
.getRepository(Sellercraft)
|
|
16
|
-
.createQueryBuilder('sellercraft')
|
|
17
|
-
.innerJoinAndSelect('sellercraft.domain', 'domain')
|
|
18
|
-
.innerJoinAndSelect(Bizplace, 'bizplace', 'bizplace.domain_id = domain.id')
|
|
19
|
-
.where('sellercraft.status = :status', { status: 'ACTIVE' })
|
|
20
|
-
|
|
21
|
-
const sellercrafts: Sellercraft[] = await qb.getRawMany()
|
|
22
|
-
|
|
23
|
-
for (const sellercraft of sellercrafts) {
|
|
24
|
-
const companyBizplace: Bizplace = await getCompanyBizplace(null, null, sellercraft.bizplace_id, tx)
|
|
25
|
-
const fulfillmentCenter: FulfillmentCenter = await tx.getRepository(FulfillmentCenter).find({
|
|
26
|
-
where: { domain: { id: companyBizplace.domain.id } }
|
|
27
|
-
})
|
|
28
|
-
await resolver.syncProductsToSellercraft(
|
|
29
|
-
null,
|
|
30
|
-
{ sellercraftId: sellercraft.id, fulfillmentCenterId: fulfillmentCenter.id, toCreateSku: false },
|
|
31
|
-
context
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.log(e)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
2
|
-
import { Product } from '@things-factory/product-base'
|
|
3
|
-
|
|
4
|
-
import { buildMap } from '../../../utils/build-map'
|
|
5
|
-
import { getAccountingProducts } from './fetch-sync-products'
|
|
6
|
-
|
|
7
|
-
export const syncProductsFromAccountResolver = {
|
|
8
|
-
async syncProductsFromAccount(
|
|
9
|
-
_: void,
|
|
10
|
-
{ accountId, bizplaceId }: { accountId: string; bizplaceId: string },
|
|
11
|
-
context: ResolverContext
|
|
12
|
-
): Promise<void> {
|
|
13
|
-
try {
|
|
14
|
-
const { tx } = context.state
|
|
15
|
-
let platformProducts: Product[] = await getAccountingProducts(accountId)
|
|
16
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({ id: bizplaceId })
|
|
17
|
-
const platformProductsMap: Map<string, Product> = buildMap(platformProducts, 'sku')
|
|
18
|
-
|
|
19
|
-
let bizplaceProducts: Product[] = await tx
|
|
20
|
-
.getRepository(Product)
|
|
21
|
-
.find({ where: { bizplace: { id: bizplace.id } } })
|
|
22
|
-
|
|
23
|
-
const updateTargetProducts: Product[] = bizplaceProducts
|
|
24
|
-
.filter(({ sku }: Product) => platformProductsMap.has(sku))
|
|
25
|
-
.map((bizplaceProduct: Product) => {
|
|
26
|
-
const platformProduct: Product = platformProductsMap.get(bizplaceProduct.sku)
|
|
27
|
-
|
|
28
|
-
Object.keys(platformProduct).forEach((key: string) => {
|
|
29
|
-
bizplaceProduct[key] = platformProduct[key] === undefined ? null : platformProduct[key]
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
return bizplaceProduct
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
await tx.getRepository(Product).save(updateTargetProducts, { chunk: 500 })
|
|
36
|
-
} catch (e) {
|
|
37
|
-
throw e
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|