@things-factory/operato-hub 5.0.13 → 6.0.0-alpha.1
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/controllers/bizplace-initializer/dataset/codes.js +9 -0
- package/dist-server/controllers/bizplace-initializer/dataset/codes.js.map +1 -1
- package/dist-server/controllers/bizplace-initializer/dataset/settings.js +5 -0
- package/dist-server/controllers/bizplace-initializer/dataset/settings.js.map +1 -1
- package/dist-server/controllers/bizplace-initializer/generate-bizplace-domain-roles.js +3 -3
- package/dist-server/controllers/bizplace-initializer/generate-bizplace-domain-roles.js.map +1 -1
- package/dist-server/controllers/bizplace-initializer/generate-bizplace-domain.js +2 -2
- package/dist-server/controllers/bizplace-initializer/generate-bizplace-domain.js.map +1 -1
- package/dist-server/controllers/bizplace-initializer/menus.js +2 -2
- package/dist-server/controllers/bizplace-initializer/menus.js.map +1 -1
- package/dist-server/controllers/company-initializer/business-register.js +6 -7
- package/dist-server/controllers/company-initializer/business-register.js.map +1 -1
- package/dist-server/controllers/company-initializer/generate-company-roles.js +4 -4
- package/dist-server/controllers/company-initializer/generate-company-roles.js.map +1 -1
- package/dist-server/controllers/invitation.js +9 -9
- package/dist-server/controllers/invitation.js.map +1 -1
- package/dist-server/controllers/utils/save-invitation-token.js +2 -2
- package/dist-server/controllers/utils/save-invitation-token.js.map +1 -1
- package/dist-server/graphql/resolvers/generators/generate-bizplace.js.map +1 -1
- package/dist-server/graphql/resolvers/generators/generate-company.js +4 -3
- package/dist-server/graphql/resolvers/generators/generate-company.js.map +1 -1
- package/dist-server/graphql/resolvers/generators/update-domain-extType.js +1 -1
- package/dist-server/graphql/resolvers/generators/update-domain-extType.js.map +1 -1
- package/dist-server/graphql/resolvers/invitations/partner-invitation.js +6 -6
- package/dist-server/graphql/resolvers/invitations/partner-invitation.js.map +1 -1
- package/dist-server/graphql/resolvers/oauth2/company-roles-by-scope.js +5 -2
- package/dist-server/graphql/resolvers/oauth2/company-roles-by-scope.js.map +1 -1
- package/dist-server/graphql/resolvers/synchronization/auto-update-all-marketplace-product-variation-quantity.js +149 -0
- package/dist-server/graphql/resolvers/synchronization/auto-update-all-marketplace-product-variation-quantity.js.map +1 -0
- package/dist-server/graphql/resolvers/synchronization/create-dat-shipments.js +58 -0
- package/dist-server/graphql/resolvers/synchronization/create-dat-shipments.js.map +1 -0
- package/dist-server/graphql/resolvers/synchronization/fetch-sync-products.js +3 -3
- package/dist-server/graphql/resolvers/synchronization/fetch-sync-products.js.map +1 -1
- package/dist-server/graphql/resolvers/synchronization/index.js +6 -2
- package/dist-server/graphql/resolvers/synchronization/index.js.map +1 -1
- package/dist-server/graphql/resolvers/synchronization/sellercraft-pack-marketplace-order.js +68 -0
- package/dist-server/graphql/resolvers/synchronization/sellercraft-pack-marketplace-order.js.map +1 -0
- package/dist-server/graphql/resolvers/synchronization/sync-all-products-to-sellercraft.js +35 -0
- package/dist-server/graphql/resolvers/synchronization/sync-all-products-to-sellercraft.js.map +1 -0
- package/dist-server/graphql/resolvers/synchronization/sync-products-from-account.js +1 -1
- package/dist-server/graphql/resolvers/synchronization/sync-products-from-account.js.map +1 -1
- package/dist-server/graphql/resolvers/synchronization/sync-products-to-account.js +1 -1
- package/dist-server/graphql/resolvers/synchronization/sync-products-to-account.js.map +1 -1
- package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js +4 -2
- package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js.map +1 -1
- package/dist-server/graphql/types/synchronization/index.js +4 -0
- package/dist-server/graphql/types/synchronization/index.js.map +1 -1
- package/dist-server/index.js +5 -5
- package/dist-server/index.js.map +1 -1
- package/dist-server/middlewares/business-middleware.js +2 -3
- package/dist-server/middlewares/business-middleware.js.map +1 -1
- package/dist-server/middlewares/store-middleware.js +2 -2
- package/dist-server/middlewares/store-middleware.js.map +1 -1
- package/dist-server/middlewares/warehouse-middleware.js +3 -2
- package/dist-server/middlewares/warehouse-middleware.js.map +1 -1
- package/dist-server/migrations/1597668478399-SeedBusinessDomain.js +2 -3
- package/dist-server/migrations/1597668478399-SeedBusinessDomain.js.map +1 -1
- package/dist-server/migrations/1597668478401-SeedBusinessRoles.js +2 -2
- package/dist-server/migrations/1597668478401-SeedBusinessRoles.js.map +1 -1
- package/dist-server/migrations/1608009991065-SeedUser.js +5 -6
- package/dist-server/migrations/1608009991065-SeedUser.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js +2 -1
- package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-inbound-order.js +5 -4
- package/dist-server/routers/api/restful-apis/unstable/add-inbound-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js +5 -2
- package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-products.js +32 -16
- package/dist-server/routers/api/restful-apis/unstable/add-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +149 -40
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/cancel-release-order.js +4 -4
- package/dist-server/routers/api/restful-apis/unstable/cancel-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-delivery-orders.js +27 -11
- package/dist-server/routers/api/restful-apis/unstable/get-delivery-orders.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-goods-received-notes.js +9 -2
- package/dist-server/routers/api/restful-apis/unstable/get-goods-received-notes.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-onhand-inventories.js +2 -2
- package/dist-server/routers/api/restful-apis/unstable/get-onhand-inventories.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-partners.js +5 -4
- package/dist-server/routers/api/restful-apis/unstable/get-partners.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-products.js +1 -0
- package/dist-server/routers/api/restful-apis/unstable/get-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/get-warehouses.js +2 -2
- package/dist-server/routers/api/restful-apis/unstable/get-warehouses.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/update-release-order-details.js +2 -2
- package/dist-server/routers/api/restful-apis/unstable/update-release-order-details.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/add-inbound-order.js +6 -5
- package/dist-server/routers/api/restful-apis/v1/add-inbound-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js +8 -5
- package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/add-products.js +32 -16
- package/dist-server/routers/api/restful-apis/v1/add-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/add-release-order.js +8 -6
- package/dist-server/routers/api/restful-apis/v1/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/cancel-release-order.js +4 -4
- package/dist-server/routers/api/restful-apis/v1/cancel-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-delivery-orders.js +27 -11
- package/dist-server/routers/api/restful-apis/v1/get-delivery-orders.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-goods-received-notes.js +9 -2
- package/dist-server/routers/api/restful-apis/v1/get-goods-received-notes.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-onhand-inventories.js +2 -2
- package/dist-server/routers/api/restful-apis/v1/get-onhand-inventories.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-partners.js +5 -4
- package/dist-server/routers/api/restful-apis/v1/get-partners.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-products.js +1 -0
- package/dist-server/routers/api/restful-apis/v1/get-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/get-warehouses.js +2 -2
- package/dist-server/routers/api/restful-apis/v1/get-warehouses.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/update-release-order-details.js +2 -2
- package/dist-server/routers/api/restful-apis/v1/update-release-order-details.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/add-inbound-order.js +6 -5
- package/dist-server/routers/api/restful-apis/v2/add-inbound-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js +8 -5
- package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/add-products.js +32 -16
- package/dist-server/routers/api/restful-apis/v2/add-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/add-release-order.js +8 -6
- package/dist-server/routers/api/restful-apis/v2/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/cancel-release-order.js +4 -4
- package/dist-server/routers/api/restful-apis/v2/cancel-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-delivery-orders.js +27 -11
- package/dist-server/routers/api/restful-apis/v2/get-delivery-orders.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-goods-received-notes.js +9 -2
- package/dist-server/routers/api/restful-apis/v2/get-goods-received-notes.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-onhand-inventories.js +2 -2
- package/dist-server/routers/api/restful-apis/v2/get-onhand-inventories.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-partners.js +5 -4
- package/dist-server/routers/api/restful-apis/v2/get-partners.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-products.js +1 -0
- package/dist-server/routers/api/restful-apis/v2/get-products.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/get-warehouses.js +2 -2
- package/dist-server/routers/api/restful-apis/v2/get-warehouses.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/update-release-order-details.js +2 -2
- package/dist-server/routers/api/restful-apis/v2/update-release-order-details.js.map +1 -1
- package/dist-server/routers/auth-invitation-router.js +2 -2
- package/dist-server/routers/auth-invitation-router.js.map +1 -1
- package/dist-server/routers/business/bizplace-register-router.js +3 -3
- package/dist-server/routers/business/bizplace-register-router.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/get-warehouses.js +15 -11
- package/dist-server/utils/get-warehouses.js.map +1 -1
- package/openapi/unstable/product.yaml +9 -3
- package/openapi/v1/product.yaml +9 -3
- package/openapi/v2/product.yaml +9 -3
- package/package.json +47 -47
- package/server/controllers/bizplace-initializer/dataset/codes.ts +9 -0
- package/server/controllers/bizplace-initializer/dataset/settings.ts +5 -0
- package/server/controllers/bizplace-initializer/generate-bizplace-domain-roles.ts +4 -2
- package/server/controllers/bizplace-initializer/generate-bizplace-domain.ts +4 -3
- package/server/controllers/bizplace-initializer/menus.ts +4 -2
- package/server/controllers/company-initializer/business-register.ts +5 -3
- package/server/controllers/company-initializer/generate-company-roles.ts +4 -3
- package/server/controllers/invitation.ts +11 -7
- package/server/controllers/utils/save-invitation-token.ts +1 -1
- package/server/graphql/resolvers/generators/generate-bizplace.ts +1 -1
- package/server/graphql/resolvers/generators/generate-company.ts +5 -4
- package/server/graphql/resolvers/generators/update-domain-extType.ts +7 -5
- package/server/graphql/resolvers/invitations/partner-invitation.ts +5 -5
- package/server/graphql/resolvers/oauth2/company-roles-by-scope.ts +8 -6
- package/server/graphql/resolvers/synchronization/auto-update-all-marketplace-product-variation-quantity.ts +180 -0
- package/server/graphql/resolvers/synchronization/create-dat-shipments.ts +64 -0
- package/server/graphql/resolvers/synchronization/fetch-sync-products.ts +3 -2
- package/server/graphql/resolvers/synchronization/index.ts +10 -2
- package/server/graphql/resolvers/synchronization/sellercraft-pack-marketplace-order.ts +91 -0
- package/server/graphql/resolvers/synchronization/sync-all-products-to-sellercraft.ts +39 -0
- package/server/graphql/resolvers/synchronization/sync-products-from-account.ts +4 -4
- package/server/graphql/resolvers/synchronization/sync-products-to-account.ts +4 -4
- package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +19 -12
- package/server/graphql/types/synchronization/index.ts +4 -0
- package/server/index.ts +7 -7
- package/server/middlewares/business-middleware.ts +1 -2
- package/server/middlewares/store-middleware.ts +1 -1
- package/server/middlewares/warehouse-middleware.ts +3 -2
- package/server/migrations/1597668478399-SeedBusinessDomain.ts +3 -2
- package/server/migrations/1597668478401-SeedBusinessRoles.ts +2 -2
- package/server/migrations/1608009991065-SeedUser.ts +5 -3
- package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +2 -1
- package/server/routers/api/restful-apis/unstable/add-inbound-order.ts +3 -2
- package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +13 -2
- package/server/routers/api/restful-apis/unstable/add-products.ts +40 -16
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +98 -48
- package/server/routers/api/restful-apis/unstable/cancel-release-order.ts +2 -2
- package/server/routers/api/restful-apis/unstable/get-delivery-orders.ts +27 -11
- package/server/routers/api/restful-apis/unstable/get-goods-received-notes.ts +9 -2
- package/server/routers/api/restful-apis/unstable/get-onhand-inventories.ts +1 -1
- package/server/routers/api/restful-apis/unstable/get-partners.ts +4 -2
- package/server/routers/api/restful-apis/unstable/get-products.ts +1 -0
- package/server/routers/api/restful-apis/unstable/get-warehouses.ts +3 -2
- package/server/routers/api/restful-apis/unstable/update-release-order-details.ts +1 -1
- package/server/routers/api/restful-apis/v1/add-inbound-order.ts +4 -3
- package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +17 -5
- package/server/routers/api/restful-apis/v1/add-products.ts +40 -16
- package/server/routers/api/restful-apis/v1/add-release-order.ts +10 -6
- package/server/routers/api/restful-apis/v1/cancel-release-order.ts +2 -2
- package/server/routers/api/restful-apis/v1/get-delivery-orders.ts +27 -11
- package/server/routers/api/restful-apis/v1/get-goods-received-notes.ts +9 -2
- package/server/routers/api/restful-apis/v1/get-onhand-inventories.ts +1 -1
- package/server/routers/api/restful-apis/v1/get-partners.ts +4 -2
- package/server/routers/api/restful-apis/v1/get-products.ts +1 -0
- package/server/routers/api/restful-apis/v1/get-warehouses.ts +3 -2
- package/server/routers/api/restful-apis/v1/update-release-order-details.ts +1 -1
- package/server/routers/api/restful-apis/v2/add-inbound-order.ts +4 -3
- package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +17 -5
- package/server/routers/api/restful-apis/v2/add-products.ts +40 -16
- package/server/routers/api/restful-apis/v2/add-release-order.ts +10 -6
- package/server/routers/api/restful-apis/v2/cancel-release-order.ts +2 -2
- package/server/routers/api/restful-apis/v2/get-delivery-orders.ts +27 -11
- package/server/routers/api/restful-apis/v2/get-goods-received-notes.ts +9 -2
- package/server/routers/api/restful-apis/v2/get-onhand-inventories.ts +1 -1
- package/server/routers/api/restful-apis/v2/get-partners.ts +4 -2
- package/server/routers/api/restful-apis/v2/get-products.ts +1 -0
- package/server/routers/api/restful-apis/v2/get-warehouses.ts +3 -2
- package/server/routers/api/restful-apis/v2/update-release-order-details.ts +1 -1
- package/server/routers/auth-invitation-router.ts +2 -2
- package/server/routers/business/bizplace-register-router.ts +3 -1
- package/server/utils/get-warehouses.ts +46 -36
|
@@ -0,0 +1,180 @@
|
|
|
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: companyDomain, 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: companyDomain },
|
|
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, 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: companyDomain, 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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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: sftp.domain }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
let releaseGoods: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
|
|
30
|
+
where: {
|
|
31
|
+
domain: warehouseDomain,
|
|
32
|
+
bizplace: bizplace,
|
|
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,7 +1,8 @@
|
|
|
1
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
2
2
|
import { AccountingAPI } from '@things-factory/integration-accounting'
|
|
3
3
|
import { Product } from '@things-factory/product-base'
|
|
4
|
-
import { getRepository } from '
|
|
4
|
+
import { getRepository } from '@things-factory/shell'
|
|
5
|
+
|
|
5
6
|
import { buildMap } from '../../../utils/build-map'
|
|
6
7
|
|
|
7
8
|
export const fetchSyncProductsResolver = {
|
|
@@ -18,7 +19,7 @@ export const fetchSyncProductsResolver = {
|
|
|
18
19
|
const platformProducts: Product[] = await getAccountingProducts(accountId)
|
|
19
20
|
const platformProductsMap: Map<string, Product> = buildMap(platformProducts, 'sku')
|
|
20
21
|
|
|
21
|
-
const bizplace: Bizplace = await getRepository(Bizplace).
|
|
22
|
+
const bizplace: Bizplace = await getRepository(Bizplace).findOneBy({ id: bizplaceId })
|
|
22
23
|
const bizplaceProducts: Product[] = await getRepository(Product).find({ where: { bizplace } })
|
|
23
24
|
const bizplaceProductsMap: Map<string, Product> = buildMap(bizplaceProducts, 'sku')
|
|
24
25
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { fetchSyncInvoicesResolver } from './fetch-sync-invoices'
|
|
1
2
|
import { fetchSyncProductsResolver } from './fetch-sync-products'
|
|
2
3
|
import { fetchSyncPurchaseOrdersResolver } from './fetch-sync-purchase-orders'
|
|
3
|
-
import {
|
|
4
|
+
import { sellercraftPackMarketplaceOrderResolver } from './sellercraft-pack-marketplace-order'
|
|
5
|
+
import { syncAllProductsToSellercraftResolver } from './sync-all-products-to-sellercraft'
|
|
4
6
|
import { syncProductsFromAccountResolver } from './sync-products-from-account'
|
|
5
7
|
import { syncProductsToAccountResolver } from './sync-products-to-account'
|
|
6
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'
|
|
7
11
|
|
|
8
12
|
export const Query = {
|
|
9
13
|
...fetchSyncProductsResolver,
|
|
@@ -14,5 +18,9 @@ export const Query = {
|
|
|
14
18
|
export const Mutation = {
|
|
15
19
|
...syncProductsToSellercraftResolver,
|
|
16
20
|
...syncProductsFromAccountResolver,
|
|
17
|
-
...syncProductsToAccountResolver
|
|
21
|
+
...syncProductsToAccountResolver,
|
|
22
|
+
...syncAllProductsToSellercraftResolver,
|
|
23
|
+
...sellercraftPackMarketplaceOrderResolver,
|
|
24
|
+
...createDatShipments,
|
|
25
|
+
...autoUpdateAllMarketplaceProductVariationQuantityResolver
|
|
18
26
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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: sellercraftDomain } })
|
|
25
|
+
|
|
26
|
+
let releaseGoodsWithoutPackageId: ReleaseGood[] = await tx.getRepository(ReleaseGood).find({
|
|
27
|
+
where: {
|
|
28
|
+
bizplace,
|
|
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
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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: companyBizplace.domain }
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
2
2
|
import { Product } from '@things-factory/product-base'
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { buildMap } from '../../../utils/build-map'
|
|
5
5
|
import { getAccountingProducts } from './fetch-sync-products'
|
|
6
6
|
|
|
@@ -8,12 +8,12 @@ export const syncProductsFromAccountResolver = {
|
|
|
8
8
|
async syncProductsFromAccount(
|
|
9
9
|
_: void,
|
|
10
10
|
{ accountId, bizplaceId }: { accountId: string; bizplaceId: string },
|
|
11
|
-
context:
|
|
11
|
+
context: ResolverContext
|
|
12
12
|
): Promise<void> {
|
|
13
13
|
try {
|
|
14
|
-
const { tx }
|
|
14
|
+
const { tx } = context.state
|
|
15
15
|
let platformProducts: Product[] = await getAccountingProducts(accountId)
|
|
16
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
16
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({ id: bizplaceId })
|
|
17
17
|
const platformProductsMap: Map<string, Product> = buildMap(platformProducts, 'sku')
|
|
18
18
|
|
|
19
19
|
let bizplaceProducts: Product[] = await tx.getRepository(Product).find({ where: { bizplace } })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
2
2
|
import { AccountingAPI } from '@things-factory/integration-accounting'
|
|
3
3
|
import { Product } from '@things-factory/product-base'
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import { buildMap } from '../../../utils/build-map'
|
|
6
6
|
import { getAccountingProducts } from './fetch-sync-products'
|
|
7
7
|
|
|
@@ -9,12 +9,12 @@ export const syncProductsToAccountResolver = {
|
|
|
9
9
|
async syncProductsToAccount(
|
|
10
10
|
_: void,
|
|
11
11
|
{ accountId, bizplaceId }: { accountId: string; bizplaceId: string },
|
|
12
|
-
context:
|
|
12
|
+
context: ResolverContext
|
|
13
13
|
): Promise<void> {
|
|
14
14
|
try {
|
|
15
|
-
const { tx }
|
|
15
|
+
const { tx } = context.state
|
|
16
16
|
|
|
17
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
17
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({ id: bizplaceId })
|
|
18
18
|
const bizplaceProducts: Product[] = await tx.getRepository(Product).find({ where: { bizplace } })
|
|
19
19
|
|
|
20
20
|
let platformProducts: Product[] = await getAccountingProducts(accountId)
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { EntityManager, getRepository } from 'typeorm'
|
|
2
|
-
|
|
3
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
4
2
|
import { logger } from '@things-factory/env'
|
|
5
3
|
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
6
4
|
import { Sellercraft, SellercraftAPI } from '@things-factory/integration-sellercraft'
|
|
7
|
-
import {
|
|
8
|
-
import { WarehouseBizplaceOnhandInventory } from '@things-factory/worksheet-base'
|
|
5
|
+
import { ProductDetail } from '@things-factory/product-base'
|
|
9
6
|
import { Domain } from '@things-factory/shell'
|
|
10
7
|
|
|
11
8
|
export const syncProductsToSellercraftResolver = {
|
|
@@ -18,18 +15,21 @@ export const syncProductsToSellercraftResolver = {
|
|
|
18
15
|
context: any
|
|
19
16
|
): Promise<void> {
|
|
20
17
|
try {
|
|
21
|
-
const { domain, tx }
|
|
18
|
+
const { domain, tx } = context.state
|
|
22
19
|
|
|
23
20
|
let page: number = 0
|
|
24
21
|
let hasMorePage: boolean = true
|
|
25
22
|
const limit: number = 50
|
|
26
23
|
|
|
27
|
-
const sellercraft: Sellercraft = await tx
|
|
24
|
+
const sellercraft: Sellercraft = await tx
|
|
25
|
+
.getRepository(Sellercraft)
|
|
26
|
+
.findOne({ where: { id: sellercraftId }, relations: ['domain'] })
|
|
28
27
|
const customerDomain: Domain = sellercraft.domain
|
|
29
28
|
const fulfilmentCenter: FulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(fulfillmentCenterId)
|
|
30
29
|
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: customerDomain } })
|
|
31
30
|
|
|
32
|
-
await tx.query(
|
|
31
|
+
await tx.query(
|
|
32
|
+
`
|
|
33
33
|
create temp table temp_warehouse_product_inventory ON COMMIT DROP as (
|
|
34
34
|
select p.id, p.sku as product_sku, p.name as product_name, p.description as product_description,
|
|
35
35
|
pd.gtin, pd.uom, pd.packing_size, coalesce(pd.nett_weight, 0) as nett_weight, pd.width, pd."depth", pd.height,
|
|
@@ -51,7 +51,9 @@ export const syncProductsToSellercraftResolver = {
|
|
|
51
51
|
and src."uom" = pd."uom"
|
|
52
52
|
where b.id = $2
|
|
53
53
|
)
|
|
54
|
-
`,
|
|
54
|
+
`,
|
|
55
|
+
[fulfilmentCenter.id, customerBizplace.id]
|
|
56
|
+
)
|
|
55
57
|
|
|
56
58
|
let total = await tx.query(`
|
|
57
59
|
select count(*) from temp_warehouse_product_inventory
|
|
@@ -66,9 +68,12 @@ export const syncProductsToSellercraftResolver = {
|
|
|
66
68
|
// paginationOffset: page
|
|
67
69
|
// })
|
|
68
70
|
|
|
69
|
-
const items = await tx.query(
|
|
71
|
+
const items = await tx.query(
|
|
72
|
+
`
|
|
70
73
|
select * from temp_warehouse_product_inventory limit $1 offset $2
|
|
71
|
-
`,
|
|
74
|
+
`,
|
|
75
|
+
[limit, page * limit]
|
|
76
|
+
)
|
|
72
77
|
|
|
73
78
|
let sellercraftInv: any[] = []
|
|
74
79
|
|
|
@@ -101,9 +106,11 @@ export const syncProductsToSellercraftResolver = {
|
|
|
101
106
|
await SellercraftAPI.updateProduct(sellercraft, { context, accountId: sellercraft.accountId, sellercraftInv })
|
|
102
107
|
|
|
103
108
|
page++
|
|
104
|
-
hasMorePage = (total[0]?.count || 0) >
|
|
109
|
+
hasMorePage = (total[0]?.count || 0) > page * limit
|
|
105
110
|
} catch (e) {
|
|
106
|
-
logger.error(
|
|
111
|
+
logger.error(
|
|
112
|
+
`[syncProductsToSellercraftResolver] sellercraftID:${sellercraftId} fulfillmentCenterId:${fulfillmentCenterId} page:${page} - ${e}`
|
|
113
|
+
)
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
116
|
} catch (e) {
|
|
@@ -15,6 +15,10 @@ export const Mutation = /* GraphQL */ `
|
|
|
15
15
|
syncProductsToSellercraft(sellercraftId: String!, fulfillmentCenterId: String!): Boolean @transaction
|
|
16
16
|
syncProductsFromAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
|
|
17
17
|
syncProductsToAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
|
|
18
|
+
syncAllProductsToSellercraft: Boolean @transaction
|
|
19
|
+
sellercraftPackMarketplaceOrder: Boolean @transaction
|
|
20
|
+
createDatShipments: Boolean @transaction
|
|
21
|
+
autoUpdateAllMarketplaceProductVariationQuantity(companyDomainId: String, warehouseId: String): Boolean @transaction
|
|
18
22
|
`
|
|
19
23
|
|
|
20
24
|
export const Types = [
|
package/server/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from './migrations'
|
|
1
|
+
import './routers/api'
|
|
2
|
+
import './routes'
|
|
4
3
|
|
|
5
4
|
import { User } from '@things-factory/auth-base'
|
|
6
5
|
import { Bizplace } from '@things-factory/biz-base'
|
|
7
|
-
import { Domain } from '@things-factory/shell'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
7
|
+
|
|
8
|
+
export * from './graphql'
|
|
9
|
+
export * from './middlewares'
|
|
10
|
+
export * from './migrations'
|
|
11
11
|
|
|
12
12
|
declare global {
|
|
13
13
|
namespace NodeJS {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Bizplace, Company } from '@things-factory/biz-base'
|
|
2
|
-
import { Domain, getDomainFromURL } from '@things-factory/shell'
|
|
3
|
-
import { getRepository } from 'typeorm'
|
|
2
|
+
import { Domain, getDomainFromURL, getRepository } from '@things-factory/shell'
|
|
4
3
|
|
|
5
4
|
const debug = require('debug')('things-factory:operato-hub:business-middleware')
|
|
6
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
2
1
|
import { MarketplaceStore as MarketplaceStoreEntity } from '@things-factory/integration-marketplace'
|
|
2
|
+
import { getRepository } from '@things-factory/shell'
|
|
3
3
|
|
|
4
4
|
const debug = require('debug')('things-factory:operato-hub:store-middleware')
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
2
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
2
|
+
import { getRepository } from '@things-factory/shell'
|
|
3
3
|
|
|
4
4
|
const debug = require('debug')('things-factory:operato-hub:warehouse-middleware')
|
|
5
5
|
|
|
@@ -17,7 +17,8 @@ export async function warehouseMiddleware(context, next) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
if (warehouseId) {
|
|
20
|
-
warehouse = await getRepository(Bizplace).findOne(
|
|
20
|
+
warehouse = await getRepository(Bizplace).findOne({
|
|
21
|
+
where: { id: warehouseId },
|
|
21
22
|
relations: ['company', 'domain']
|
|
22
23
|
})
|
|
23
24
|
debug('warehouse', warehouseId, warehouse?.domain?.subdomain)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { MigrationInterface, QueryRunner
|
|
2
|
-
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
3
4
|
|
|
4
5
|
const SEED_BUSINESS_DOMAIN = [
|
|
5
6
|
{
|
|
@@ -351,7 +351,7 @@ export class SeedBusinessRoles1597668478401 implements MigrationInterface {
|
|
|
351
351
|
// const privileges = await Promise.all(
|
|
352
352
|
// role.privileges.map(
|
|
353
353
|
// async privilege =>
|
|
354
|
-
// await privilegeRepo.
|
|
354
|
+
// await privilegeRepo.findOneBy({
|
|
355
355
|
// ...privilege
|
|
356
356
|
// })
|
|
357
357
|
// )
|
|
@@ -367,7 +367,7 @@ export class SeedBusinessRoles1597668478401 implements MigrationInterface {
|
|
|
367
367
|
public async down(queryRunner: QueryRunner): Promise<any> {
|
|
368
368
|
// const roleRepo = getRepository(Role)
|
|
369
369
|
// const domainRepo = getRepository(Domain)
|
|
370
|
-
// const domain = await domainRepo.findOne({ where: })
|
|
370
|
+
// const domain = await domainRepo.findOne({ where: ...})
|
|
371
371
|
// return await Promise.all(
|
|
372
372
|
// SEED_ROLES_PRIVILEGES.reverse().map(async (role: Role) => {
|
|
373
373
|
// await roleRepo.delete({ domain, name: role.name })
|