@things-factory/operato-mms 4.3.669 → 4.3.671

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.
Files changed (77) hide show
  1. package/package.json +33 -33
  2. package/dist-server/controllers/index.js +0 -1
  3. package/dist-server/controllers/index.js.map +0 -1
  4. package/dist-server/entities/index.js +0 -5
  5. package/dist-server/entities/index.js.map +0 -1
  6. package/dist-server/graphql/index.js +0 -33
  7. package/dist-server/graphql/index.js.map +0 -1
  8. package/dist-server/graphql/resolvers/index.js +0 -32
  9. package/dist-server/graphql/resolvers/index.js.map +0 -1
  10. package/dist-server/graphql/resolvers/interface-with-hub/add-release-order.js +0 -242
  11. package/dist-server/graphql/resolvers/interface-with-hub/add-release-order.js.map +0 -1
  12. package/dist-server/graphql/resolvers/interface-with-hub/auto-add-release-order.js +0 -218
  13. package/dist-server/graphql/resolvers/interface-with-hub/auto-add-release-order.js.map +0 -1
  14. package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js +0 -159
  15. package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js.map +0 -1
  16. package/dist-server/graphql/resolvers/interface-with-hub/generate-replenishment-order.js +0 -27
  17. package/dist-server/graphql/resolvers/interface-with-hub/generate-replenishment-order.js.map +0 -1
  18. package/dist-server/graphql/resolvers/interface-with-hub/index.js +0 -12
  19. package/dist-server/graphql/resolvers/interface-with-hub/index.js.map +0 -1
  20. package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js +0 -157
  21. package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map +0 -1
  22. package/dist-server/graphql/resolvers/shipping-provider/index.js +0 -6
  23. package/dist-server/graphql/resolvers/shipping-provider/index.js.map +0 -1
  24. package/dist-server/graphql/resolvers/shipping-provider/shipping-providers.js +0 -32
  25. package/dist-server/graphql/resolvers/shipping-provider/shipping-providers.js.map +0 -1
  26. package/dist-server/graphql/resolvers/warehouse-product/auto-link-warehouse-marketplace-product-variations.js +0 -63
  27. package/dist-server/graphql/resolvers/warehouse-product/auto-link-warehouse-marketplace-product-variations.js.map +0 -1
  28. package/dist-server/graphql/resolvers/warehouse-product/index.js +0 -6
  29. package/dist-server/graphql/resolvers/warehouse-product/index.js.map +0 -1
  30. package/dist-server/graphql/types/index.js +0 -33
  31. package/dist-server/graphql/types/index.js.map +0 -1
  32. package/dist-server/graphql/types/interface-with-hub/index.js +0 -29
  33. package/dist-server/graphql/types/interface-with-hub/index.js.map +0 -1
  34. package/dist-server/graphql/types/interface-with-hub/new-stock-replenishment.js +0 -34
  35. package/dist-server/graphql/types/interface-with-hub/new-stock-replenishment.js.map +0 -1
  36. package/dist-server/graphql/types/interface-with-hub/replenishment-order-product.js +0 -50
  37. package/dist-server/graphql/types/interface-with-hub/replenishment-order-product.js.map +0 -1
  38. package/dist-server/graphql/types/interface-with-hub/stock-replenishment-list.js +0 -16
  39. package/dist-server/graphql/types/interface-with-hub/stock-replenishment-list.js.map +0 -1
  40. package/dist-server/graphql/types/interface-with-hub/stock-replenishment.js +0 -47
  41. package/dist-server/graphql/types/interface-with-hub/stock-replenishment.js.map +0 -1
  42. package/dist-server/graphql/types/interface-with-hub/warehouse-inventory.js +0 -17
  43. package/dist-server/graphql/types/interface-with-hub/warehouse-inventory.js.map +0 -1
  44. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product-list.js +0 -14
  45. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product-list.js.map +0 -1
  46. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product.js +0 -20
  47. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product.js.map +0 -1
  48. package/dist-server/graphql/types/shipping-provider/index.js +0 -10
  49. package/dist-server/graphql/types/shipping-provider/index.js.map +0 -1
  50. package/dist-server/graphql/types/shipping-provider/shipping-provider-list.js +0 -13
  51. package/dist-server/graphql/types/shipping-provider/shipping-provider-list.js.map +0 -1
  52. package/dist-server/graphql/types/shipping-provider/shipping-provider.js +0 -13
  53. package/dist-server/graphql/types/shipping-provider/shipping-provider.js.map +0 -1
  54. package/dist-server/graphql/types/warehouse-product/index.js +0 -11
  55. package/dist-server/graphql/types/warehouse-product/index.js.map +0 -1
  56. package/dist-server/graphql/types/warehouse-product/warehouse-product.js +0 -12
  57. package/dist-server/graphql/types/warehouse-product/warehouse-product.js.map +0 -1
  58. package/dist-server/index.js +0 -34
  59. package/dist-server/index.js.map +0 -1
  60. package/dist-server/middlewares/index.js +0 -4
  61. package/dist-server/middlewares/index.js.map +0 -1
  62. package/dist-server/migrations/1599732967233-SeedCommonCode.js +0 -52
  63. package/dist-server/migrations/1599732967233-SeedCommonCode.js.map +0 -1
  64. package/dist-server/migrations/1608009991075-SeedUser.js +0 -51
  65. package/dist-server/migrations/1608009991075-SeedUser.js.map +0 -1
  66. package/dist-server/migrations/index.js +0 -12
  67. package/dist-server/migrations/index.js.map +0 -1
  68. package/dist-server/routers/etrax-router.js +0 -155
  69. package/dist-server/routers/etrax-router.js.map +0 -1
  70. package/dist-server/routers/shopify-pos-public-router.js +0 -109
  71. package/dist-server/routers/shopify-pos-public-router.js.map +0 -1
  72. package/dist-server/routes.js +0 -11
  73. package/dist-server/routes.js.map +0 -1
  74. package/dist-server/util/interface-helper.js +0 -53
  75. package/dist-server/util/interface-helper.js.map +0 -1
  76. package/dist-server/util/no-generator.js +0 -14
  77. package/dist-server/util/no-generator.js.map +0 -1
@@ -1,218 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.autoAddReleaseOrderResolver = void 0;
4
- const typeorm_1 = require("typeorm");
5
- const auth_base_1 = require("@things-factory/auth-base");
6
- const biz_base_1 = require("@things-factory/biz-base");
7
- const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
8
- const marketplace_base_1 = require("@things-factory/marketplace-base");
9
- const product_base_1 = require("@things-factory/product-base");
10
- const shell_1 = require("@things-factory/shell");
11
- exports.autoAddReleaseOrderResolver = {
12
- async autoAddReleaseOrder(_, { warehouseId }, context) {
13
- var _a, _b;
14
- const { domain } = context.state;
15
- const qb = (0, typeorm_1.createQueryBuilder)(marketplace_base_1.MarketplaceOrder, 'MO');
16
- const marketplaceOrders = await qb
17
- .leftJoinAndSelect('MO.marketplaceOrderItems', 'MOI')
18
- .leftJoinAndSelect('MOI.marketplaceOrderShippingItems', 'MOSI')
19
- .leftJoinAndSelect('MOSI.marketplaceOrderShipping', 'MOS')
20
- .leftJoinAndSelect('MOI.marketplaceProductVariation', 'MPV')
21
- .leftJoinAndSelect('MO.marketplaceStore', 'MPS')
22
- .where('MO.domain = :domainId', { domainId: domain.id })
23
- .andWhere('MO.releaseOrderId IS NULL')
24
- .andWhere('MO.status IN (:...status)', {
25
- status: ['ready_to_ship', 'unfulfilled', 'packed', 'processing', 'processed']
26
- })
27
- .andWhere('MPS.status = :marketplaceStatus', { marketplaceStatus: 'ACTIVE' })
28
- .getMany();
29
- var fulfilmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
30
- var centerId = fulfilmentCenter.centerId;
31
- var warehouseDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne({ where: { subdomain: centerId } });
32
- var customerBizplaces = await (0, biz_base_1.getCustomerBizplaces)(warehouseDomain);
33
- const customerBizplaceId = customerBizplaces.find(customerBizplace => customerBizplace.company.domain.id === domain.id).id;
34
- try {
35
- for (var i = 0; i < marketplaceOrders.length; i++) {
36
- const marketplaceOrder = marketplaceOrders[i];
37
- const marketplaceOrderItems = marketplaceOrder.marketplaceOrderItems;
38
- const qt = (0, typeorm_1.createQueryBuilder)(marketplace_base_1.MarketplaceOrderShipping, 'MOS');
39
- const marketplaceOrderShippings = await qt
40
- .leftJoinAndSelect('MOS.marketplaceOrderShippingItems', 'MOSI')
41
- .leftJoinAndSelect('MOSI.product', 'P')
42
- .leftJoinAndSelect('MOSI.marketplaceOrderItem', 'MOI')
43
- .where('MOS.domain = :domainId', { domainId: domain.id })
44
- .andWhere('MOS.orderNoRef = :orderNoRef', { orderNoRef: marketplaceOrder.orderNo })
45
- .andWhere('MOS.releaseOrderId IS NULL')
46
- .orderBy('MOS.subOrderNoRef', 'ASC')
47
- .addOrderBy('MOS.orderNoRef', 'ASC')
48
- .addOrderBy('MOS.createdAt', 'ASC')
49
- .getMany();
50
- for (let j = 0; j < marketplaceOrderShippings.length; j++) {
51
- let marketplaceOrderShipping = marketplaceOrderShippings[j];
52
- let marketplaceOrderShippingItems = marketplaceOrderShipping.marketplaceOrderShippingItems;
53
- if (!(marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.releaseOrderId)) {
54
- const date = new Date();
55
- const releaseDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date
56
- .getDate()
57
- .toString()
58
- .padStart(2, '0')}`;
59
- var newReleaseOrder = {
60
- releaseDate,
61
- type: 'b2c',
62
- source: auth_base_1.ApplicationType.MMS,
63
- transporter: marketplaceOrder.shippingProvider,
64
- trackingNo: (marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.ownTrackingNo)
65
- ? marketplaceOrderShipping.ownTrackingNo
66
- : marketplaceOrderShipping.trackingNo,
67
- packingOption: true,
68
- exportOption: false,
69
- ownTransport: true,
70
- courierOption: true,
71
- lmdOption: ((_a = marketplaceOrder === null || marketplaceOrder === void 0 ? void 0 : marketplaceOrder.marketplaceStore) === null || _a === void 0 ? void 0 : _a.lmdOption) || false,
72
- collectionOrderNo: marketplaceOrder.orderNo,
73
- refNo: marketplaceOrder.orderNo,
74
- refNo2: marketplaceOrderShippings.length > 1
75
- ? marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.subOrderNoRef
76
- : marketplaceOrder.orderNo,
77
- deliverTo: {
78
- deliveryAddress1: marketplaceOrderShipping.address1,
79
- deliveryAddress2: marketplaceOrderShipping.address2,
80
- deliveryAddress3: marketplaceOrderShipping.address3,
81
- deliveryAddress4: marketplaceOrderShipping.address4,
82
- deliveryAddress5: marketplaceOrderShipping.address5,
83
- attentionTo: marketplaceOrderShipping.attentionTo,
84
- city: marketplaceOrderShipping.city,
85
- postalCode: marketplaceOrderShipping.postCode,
86
- country: marketplaceOrderShipping.country,
87
- state: marketplaceOrderShipping.state,
88
- phone1: marketplaceOrderShipping.phone1,
89
- phone2: (marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.phone2) ? marketplaceOrderShipping.phone2 : null
90
- },
91
- marketplaceOrderStatus: marketplaceOrder.status,
92
- airwayBill: (marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.airwayBill) ? marketplaceOrderShipping.airwayBill : null,
93
- invoice: (marketplaceOrderShipping === null || marketplaceOrderShipping === void 0 ? void 0 : marketplaceOrderShipping.invoice) ? marketplaceOrderShipping.invoice : null,
94
- orderInventories: marketplaceOrderShippingItems.map(marketplaceOrderShippingItem => {
95
- return {
96
- product: {
97
- sku: marketplaceOrderShippingItem.product.sku
98
- },
99
- releaseQty: marketplaceOrderShippingItem.qty
100
- };
101
- })
102
- };
103
- try {
104
- let releaseOrder = await integration_fulfillment_1.FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
105
- customerBizplaceId,
106
- releaseOrder: newReleaseOrder
107
- });
108
- //if release order is not created, throw error
109
- if (!(releaseOrder === null || releaseOrder === void 0 ? void 0 : releaseOrder.id)) {
110
- throw new Error('Failed to create release order');
111
- }
112
- marketplaceOrderShipping.releaseOrderId = releaseOrder.id;
113
- marketplaceOrderShipping.fulfillmentCenter = fulfilmentCenter;
114
- await (0, typeorm_1.getRepository)(marketplace_base_1.MarketplaceOrderShipping).save(marketplaceOrderShipping);
115
- }
116
- catch (e) {
117
- console.error(e);
118
- }
119
- }
120
- }
121
- //fetch the latest updated of marketplaceOrderShipping
122
- const mos = await (0, typeorm_1.createQueryBuilder)(marketplace_base_1.MarketplaceOrderShipping, 'MOS')
123
- .where('MOS.domain = :domainId', { domainId: domain.id })
124
- .andWhere('MOS.orderNoRef = :orderNoRef', { orderNoRef: marketplaceOrder.orderNo })
125
- .distinctOn(['MOS.subOrderNoRef', 'MOS.orderNoRef'])
126
- .orderBy('MOS.subOrderNoRef', 'ASC')
127
- .addOrderBy('MOS.orderNoRef', 'ASC')
128
- .addOrderBy('MOS.createdAt', 'ASC')
129
- .getMany();
130
- //validation to prevent creating invoice if there is any failed release order
131
- if (mos.some(mos => mos.releaseOrderId === null || mos.releaseOrderId === '')) {
132
- continue;
133
- }
134
- //update marketplaceOrder with releaseOrderId if all ro is created
135
- if (mos.length > 0 && ((_b = mos[0]) === null || _b === void 0 ? void 0 : _b.releaseOrderId)) {
136
- await (0, typeorm_1.getRepository)(marketplace_base_1.MarketplaceOrder).update(marketplaceOrder.id, {
137
- releaseOrderId: mos[0].releaseOrderId,
138
- fulfillmentCenter: fulfilmentCenter
139
- });
140
- }
141
- try {
142
- var invoiceProducts = await Promise.all(marketplaceOrderItems.map(async (mi) => {
143
- let product = await (0, typeorm_1.getRepository)(product_base_1.Product).findOne({
144
- where: { domain, sku: mi.marketplaceProductVariation.sku }
145
- });
146
- let productBundle;
147
- if (!product) {
148
- productBundle = await (0, typeorm_1.getRepository)(product_base_1.ProductBundle).findOne({
149
- where: { domain, sku: mi.marketplaceProductVariation.sku }
150
- });
151
- }
152
- return {
153
- sku: product ? product.sku : productBundle.sku,
154
- name: product ? product.name : productBundle.name,
155
- description: product ? product.description : productBundle.description,
156
- qty: mi.qty,
157
- unitPrice: ((mi === null || mi === void 0 ? void 0 : mi.originalPrice) || 0) / mi.qty,
158
- paidPrice: ((mi === null || mi === void 0 ? void 0 : mi.paidPrice) || 0) / mi.qty,
159
- discount: (mi === null || mi === void 0 ? void 0 : mi.discount) || 0,
160
- shippingFeePaidByCustomer: (mi === null || mi === void 0 ? void 0 : mi.shippingFeePaidByCustomer) || 0
161
- };
162
- }));
163
- let newInvoice = {
164
- invoiceProducts,
165
- name: '-',
166
- refNo1: newReleaseOrder.refNo.toString(),
167
- refNo2: newReleaseOrder.refNo2.toString(),
168
- issuedOn: new Date(),
169
- from: marketplaceOrder.marketplaceStore.storeName,
170
- fromContactPhone: '-',
171
- fromAddress1: '-',
172
- fromAddress2: null,
173
- fromAddress3: null,
174
- fromAddress4: null,
175
- fromAddress5: null,
176
- fromPostcode: null,
177
- fromCity: null,
178
- fromState: null,
179
- fromCountry: null,
180
- deliverTo: newReleaseOrder.deliverTo.attentionTo || '-',
181
- deliverToPhone: newReleaseOrder.deliverTo.phone1 || '-',
182
- deliveryAddress1: newReleaseOrder.deliverTo.deliveryAddress1 || '-',
183
- deliveryAddress2: newReleaseOrder.deliverTo.deliveryAddress2,
184
- deliveryAddress3: newReleaseOrder.deliverTo.deliveryAddress3,
185
- deliveryAddress4: newReleaseOrder.deliverTo.deliveryAddress4,
186
- deliveryAddress5: newReleaseOrder.deliverTo.deliveryAddress5,
187
- deliveryPostcode: newReleaseOrder.deliverTo.postalCode || '-',
188
- deliveryCity: newReleaseOrder.deliverTo.city || '-',
189
- deliveryState: newReleaseOrder.deliverTo.state || '-',
190
- deliveryCountry: newReleaseOrder.deliverTo.country || '-',
191
- billTo: newReleaseOrder.deliverTo.attentionTo || '-',
192
- billToPhone: newReleaseOrder.deliverTo.phone1 || '-',
193
- billingAddress1: newReleaseOrder.deliverTo.billingAddress || newReleaseOrder.deliverTo.deliveryAddress1 || '-',
194
- billingAddress2: null,
195
- billingAddress3: null,
196
- billingAddress4: null,
197
- billingAddress5: null,
198
- billingPostcode: '-',
199
- billingCity: '-',
200
- billingState: '-',
201
- billingCountry: '-'
202
- };
203
- await integration_fulfillment_1.FulfillmentAPI.createSalesInvoice(fulfilmentCenter, {
204
- customerBizplaceId,
205
- invoice: newInvoice
206
- });
207
- }
208
- catch (e) {
209
- console.error(e);
210
- }
211
- }
212
- }
213
- catch (e) {
214
- console.error(e);
215
- }
216
- }
217
- };
218
- //# sourceMappingURL=auto-add-release-order.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto-add-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/auto-add-release-order.ts"],"names":[],"mappings":";;;AAAA,qCAA+E;AAE/E,yDAA2D;AAC3D,uDAAyE;AACzE,qFAAwE;AACxE,uEAKyC;AACzC,+DAAqE;AACrE,iDAA8C;AACjC,QAAA,2BAA2B,GAAG;IACzC,KAAK,CAAC,mBAAmB,CAAC,CAAO,EAAE,EAAE,WAAW,EAA2B,EAAE,OAAY;;QACvF,MAAM,EAAE,MAAM,EAAE,GAAuB,OAAO,CAAC,KAAK,CAAA;QAEpD,MAAM,EAAE,GAAyC,IAAA,4BAAkB,EAAC,mCAAgB,EAAE,IAAI,CAAC,CAAA;QAC3F,MAAM,iBAAiB,GAAuB,MAAM,EAAE;aACnD,iBAAiB,CAAC,0BAA0B,EAAE,KAAK,CAAC;aACpD,iBAAiB,CAAC,mCAAmC,EAAE,MAAM,CAAC;aAC9D,iBAAiB,CAAC,+BAA+B,EAAE,KAAK,CAAC;aACzD,iBAAiB,CAAC,iCAAiC,EAAE,KAAK,CAAC;aAC3D,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,CAAC;aAC/C,KAAK,CAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;aACvD,QAAQ,CAAC,2BAA2B,CAAC;aACrC,QAAQ,CAAC,2BAA2B,EAAE;YACrC,MAAM,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC;SAC9E,CAAC;aACD,QAAQ,CAAC,iCAAiC,EAAE,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;aAC5E,OAAO,EAAE,CAAA;QAEZ,IAAI,gBAAgB,GAAG,MAAM,wCAAc,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;QAC7E,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AC,CAAC,CAAA;iBACjB;aACF;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;SACjB;IACH,CAAC;CACF,CAAA"}
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = void 0;
4
- const typeorm_1 = require("typeorm");
5
- const env_1 = require("@things-factory/env");
6
- const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
7
- const integration_marketplace_1 = require("@things-factory/integration-marketplace");
8
- const marketplace_base_1 = require("@things-factory/marketplace-base");
9
- const product_base_1 = require("@things-factory/product-base");
10
- const shell_1 = require("@things-factory/shell");
11
- const warehouse_base_1 = require("@things-factory/warehouse-base");
12
- exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = {
13
- async autoUpdateAllMarketplaceProductVariationQuantity(_, { companyDomainId, warehouseId }, context) {
14
- const companyDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(companyDomainId);
15
- const marketplaceStores = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceStore).find({
16
- where: { domain: companyDomain, status: 'ACTIVE' },
17
- relations: ['marketplaceDistributors']
18
- });
19
- const fulfilmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
20
- const centerId = fulfilmentCenter.centerId;
21
- const warehouseDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne({ where: { subdomain: centerId } });
22
- let productLogs = [];
23
- let products = await (0, typeorm_1.getRepository)(product_base_1.Product).find({
24
- where: { domain: companyDomain },
25
- relations: ['productDetails']
26
- });
27
- let inventoryProducts = await Promise.all(products.map(async (product) => {
28
- const productDetails = product.productDetails;
29
- const defaultProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0];
30
- let qb = await (0, typeorm_1.getRepository)(warehouse_base_1.Inventory).createQueryBuilder('inv');
31
- qb.leftJoinAndSelect('inv.location', 'loc')
32
- .andWhere('"inv"."domain_id" = :domainId')
33
- .andWhere('"inv"."product_id" = :productId')
34
- .andWhere('"inv"."status" != :status')
35
- .andWhere('"loc"."type" NOT IN (:...locationTypes)')
36
- .setParameters({
37
- domainId: warehouseDomain.id,
38
- productId: product.id,
39
- status: warehouse_base_1.INVENTORY_STATUS.TERMINATED,
40
- locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
41
- });
42
- let inventories = await qb.getMany();
43
- const inventoryQty = inventories.reduce((total, currentValue) => {
44
- total += currentValue.qty;
45
- return total;
46
- }, 0);
47
- const inventoryLockedQty = inventories.reduce((total, currentValue) => {
48
- total += currentValue.lockedQty;
49
- return total;
50
- }, 0);
51
- return {
52
- product,
53
- sku: product.sku,
54
- name: product.name,
55
- packingType: defaultProductDetail.packingType,
56
- packingSize: defaultProductDetail.packingSize,
57
- uom: defaultProductDetail.uom,
58
- qty: inventoryQty - inventoryLockedQty
59
- };
60
- }));
61
- await (0, typeorm_1.getConnection)().transaction(async (tx) => {
62
- let bundleProductInventories = await (0, warehouse_base_1.getProductBundleInventory)(warehouseDomain, companyDomain, inventoryProducts, tx);
63
- bundleProductInventories.map(bundleProductInventory => {
64
- inventoryProducts.push(bundleProductInventory);
65
- });
66
- });
67
- for (let i = 0; i < marketplaceStores.length; i++) {
68
- try {
69
- const marketplaceStore = marketplaceStores[i];
70
- const marketplaceSetting = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceSetting).findOne({
71
- where: { marketplaceStore, category: 'stock_allocation' }
72
- });
73
- for (let j = 0; j < inventoryProducts.length; j++) {
74
- try {
75
- await (0, typeorm_1.getConnection)().transaction(async (tx) => {
76
- var _a, _b;
77
- const inventoryProduct = inventoryProducts[j];
78
- const marketplaceProductVariations = await tx
79
- .getRepository(marketplace_base_1.MarketplaceProductVariation)
80
- .find({
81
- where: { domain: companyDomain, sku: inventoryProduct.sku },
82
- relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
83
- });
84
- let storeProductVariations = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id);
85
- let percentageValue = 100;
86
- if (storeProductVariations) {
87
- for (let k = 0; k < storeProductVariations.length; k++) {
88
- let storeProductVariation = storeProductVariations[k];
89
- if (marketplaceSetting) {
90
- percentageValue = parseInt(marketplaceSetting.value);
91
- }
92
- let remainQty = Math.floor((inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100));
93
- if (remainQty < 0)
94
- remainQty = 0;
95
- let productVariationLocationId = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.locationId;
96
- let adjustQty = remainQty;
97
- if (marketplaceStore.platform === 'shopify') {
98
- let locationIds = JSON.parse(productVariationLocationId);
99
- adjustQty = adjustQty - storeProductVariation.qty;
100
- if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
101
- productVariationLocationId = locationIds[0].location_id;
102
- }
103
- let validMarketplaceDistributors = [];
104
- if (marketplaceStore.marketplaceDistributors) {
105
- validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
106
- }
107
- const hasVariation = (_b = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.marketplaceProduct) === null || _b === void 0 ? void 0 : _b.hasVariation;
108
- productLogs.push({
109
- itemId: storeProductVariation.marketplaceProduct.itemId,
110
- variationId: storeProductVariation.variationId,
111
- variationSku: storeProductVariation.variationSku,
112
- qty: adjustQty
113
- });
114
- if (hasVariation) {
115
- await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
116
- {
117
- itemId: storeProductVariation.marketplaceProduct.itemId,
118
- variationId: storeProductVariation.variationId,
119
- variationSku: storeProductVariation.variationSku,
120
- qty: adjustQty,
121
- locationId: productVariationLocationId,
122
- inventoryItemId: storeProductVariation.inventoryItemId,
123
- distributors: validMarketplaceDistributors
124
- }
125
- ]);
126
- }
127
- else {
128
- await integration_marketplace_1.StoreAPI.updateStoreProductStock(marketplaceStore, [
129
- {
130
- itemId: storeProductVariation.marketplaceProduct.itemId,
131
- variationId: storeProductVariation.variationId,
132
- variationSku: storeProductVariation.variationSku,
133
- qty: adjustQty,
134
- distributors: validMarketplaceDistributors
135
- }
136
- ]);
137
- }
138
- storeProductVariation.qty = remainQty;
139
- await tx.getRepository(marketplace_base_1.MarketplaceProductVariation).save(storeProductVariation);
140
- }
141
- }
142
- });
143
- }
144
- catch (error) {
145
- env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error === null || error === void 0 ? void 0 : error.message}`);
146
- }
147
- }
148
- }
149
- catch (e) {
150
- env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e === null || e === void 0 ? void 0 : e.message}`);
151
- }
152
- finally {
153
- env_1.logger.info(`quantity_logs[autoUpdateAllMarketplaceProductVariationQuantity] - ${JSON.stringify(productLogs)}`);
154
- }
155
- }
156
- return true;
157
- }
158
- };
159
- //# sourceMappingURL=auto-update-all-marketplace-product-variation-quantity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto-update-all-marketplace-product-variation-quantity.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAEtD,6CAA4C;AAC5C,qFAAwE;AACxE,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAqE;AACrE,iDAA8C;AAC9C,mEAAsH;AAEzG,QAAA,wDAAwD,GAAG;IACtE,KAAK,CAAC,gDAAgD,CAAC,CAAM,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,EAAE,OAAY;QAC3G,MAAM,aAAa,GAAW,MAAM,IAAA,uBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QAElF,MAAM,iBAAiB,GAAuB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KAAK,CAAC,0FAA0F,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,EAAE,CAAC,CAAA;aACrH;oBAAS;gBACR,YAAM,CAAC,IAAI,CAAC,qEAAqE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;aAChH;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateReplenishmentOrderResolver = void 0;
4
- const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
5
- const marketplace_base_1 = require("@things-factory/marketplace-base");
6
- const biz_base_1 = require("@things-factory/biz-base");
7
- exports.generateReplenishmentOrderResolver = {
8
- async generateReplenishmentOrder(_, { storeReplenishmentId, warehouseId }, context) {
9
- const { tx } = context.state;
10
- let storeReplenishment = await tx
11
- .getRepository(marketplace_base_1.StoreReplenishment)
12
- .findOne(storeReplenishmentId, {
13
- relations: ['storeReplenishmentItems']
14
- });
15
- var fulfillmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
16
- var centerId = fulfillmentCenter.centerId;
17
- var subdominBizplace = await (0, biz_base_1.getSubdomainBizplace)(centerId);
18
- var warehouseBizplaceId = subdominBizplace === null || subdominBizplace === void 0 ? void 0 : subdominBizplace.id;
19
- var arrivalNotice = await integration_fulfillment_1.FulfillmentAPI.createInboundOrder(fulfillmentCenter, {
20
- warehouseBizplaceId,
21
- storeReplenishment
22
- });
23
- storeReplenishment.arrivalNoticeId = arrivalNotice.id;
24
- await tx.getRepository(marketplace_base_1.StoreReplenishment).save(storeReplenishment);
25
- }
26
- };
27
- //# sourceMappingURL=generate-replenishment-order.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-replenishment-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/generate-replenishment-order.ts"],"names":[],"mappings":";;;AAAA,qFAAwE;AACxE,uEAAqE;AACrE,uDAAyE;AAG5D,QAAA,kCAAkC,GAAG;IAChD,KAAK,CAAC,0BAA0B,CAC9B,CAAO,EACP,EAAE,oBAAoB,EAAE,WAAW,EAAyD,EAC5F,OAAY;QAEZ,MAAM,EAAE,EAAE,EAAE,GAA0B,OAAO,CAAC,KAAK,CAAA;QAEnD,IAAI,kBAAkB,GAAuB,MAAM,EAAE;aAClD,aAAa,CAAC,qCAAkB,CAAC;aACjC,OAAO,CAAC,oBAAoB,EAAE;YAC7B,SAAS,EAAE,CAAC,yBAAyB,CAAC;SACvC,CAAC,CAAA;QAEJ,IAAI,iBAAiB,GAAG,MAAM,wCAAc,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;QAC9E,IAAI,QAAQ,GAAW,iBAAiB,CAAC,QAAQ,CAAA;QAEjD,IAAI,gBAAgB,GAAa,MAAM,IAAA,+BAAoB,EAAC,QAAQ,CAAC,CAAA;QACrE,IAAI,mBAAmB,GAAW,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,EAAE,CAAA;QAEtD,IAAI,aAAa,GAAG,MAAM,wCAAc,CAAC,kBAAkB,CAAC,iBAAiB,EAAE;YAC7E,mBAAmB;YACnB,kBAAkB;SACnB,CAAC,CAAA;QAEF,kBAAkB,CAAC,eAAe,GAAG,aAAa,CAAC,EAAE,CAAA;QACrD,MAAM,EAAE,CAAC,aAAa,CAAC,qCAAkB,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACrE,CAAC;CACF,CAAA"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.warehouseMarketplaceProduct = exports.Mutation = exports.Query = void 0;
4
- const add_release_order_1 = require("./add-release-order");
5
- const auto_add_release_order_1 = require("./auto-add-release-order");
6
- const auto_update_all_marketplace_product_variation_quantity_1 = require("./auto-update-all-marketplace-product-variation-quantity");
7
- const generate_replenishment_order_1 = require("./generate-replenishment-order");
8
- const warehouse_marketplace_products_1 = require("./warehouse-marketplace-products");
9
- Object.defineProperty(exports, "warehouseMarketplaceProduct", { enumerable: true, get: function () { return warehouse_marketplace_products_1.warehouseMarketplaceProduct; } });
10
- exports.Query = Object.assign({}, warehouse_marketplace_products_1.warehouseMarketplaceProductsResolver);
11
- exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign({}, add_release_order_1.addReleaseOrderResolver), auto_add_release_order_1.autoAddReleaseOrderResolver), generate_replenishment_order_1.generateReplenishmentOrderResolver), auto_update_all_marketplace_product_variation_quantity_1.autoUpdateAllMarketplaceProductVariationQuantityResolver);
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/index.ts"],"names":[],"mappings":";;;AAAA,2DAA6D;AAC7D,qEAAsE;AACtE,qIAAmI;AACnI,iFAAmF;AACnF,qFAAoH;AAa3G,4GAbA,4DAA2B,OAaA;AAXvB,QAAA,KAAK,qBACb,qEAAoC,EACxC;AAEY,QAAA,QAAQ,+DAChB,2CAAuB,GACvB,oDAA2B,GAC3B,iEAAkC,GAClC,iHAAwD,EAC5D"}
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.warehouseMarketplaceProduct = exports.warehouseMarketplaceProductsResolver = void 0;
4
- const biz_base_1 = require("@things-factory/biz-base");
5
- exports.warehouseMarketplaceProductsResolver = {
6
- async warehouseMarketplaceProducts(_, params, context) {
7
- try {
8
- const { domain, user, tx } = context.state;
9
- return warehouseMarketplaceProduct(params, domain, user, tx);
10
- }
11
- catch (error) {
12
- throw error;
13
- }
14
- }
15
- };
16
- async function warehouseMarketplaceProduct(params, domain, user, tx) {
17
- const productFilters = params.filters.filter(x => x.name == 'product_info');
18
- const filters = params.filters.filter(x => x.name != 'product_info');
19
- const companyBizplace = await (0, biz_base_1.getCompanyBizplace)(domain, user);
20
- const myBizplace = await (0, biz_base_1.getMyBizplace)(domain, user);
21
- params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }];
22
- const bizplaceIds = params.filters
23
- .find((filter) => filter.name === 'bizplace_id')
24
- .value.map((id) => `'${id}'`)
25
- .join();
26
- let productQuery = '';
27
- if (productFilters && productFilters.length > 0) {
28
- let productInfo = productFilters[0];
29
- productQuery = ` AND (
30
- Lower("Product"."sku") LIKE '${productInfo.value.toLowerCase()}'
31
- OR Lower("Product"."name") LIKE '${productInfo.value.toLowerCase()}'
32
- OR Lower("Product"."description") LIKE '${productInfo.value.toLowerCase()}')`;
33
- }
34
- await tx.query(`
35
- CREATE TEMP TABLE "temp_products" ON COMMIT DROP AS (
36
- SELECT * FROM (
37
- SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
38
- "Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
39
- "Product"."bizplace_id" AS "product_bizplace_id", 'PRODUCT' AS "type"
40
- FROM products "Product"
41
- WHERE "Product"."deleted_at" IS NULL
42
- AND "Product"."bizplace_id" IN (${bizplaceIds})
43
- ${productQuery}
44
- ) d1
45
- UNION ALL
46
- SELECT * FROM
47
- (
48
- SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
49
- "Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
50
- "Product"."bizplace_id" AS "product_bizplace_id", 'BUNDLE' AS "type"
51
- FROM product_bundles "Product"
52
- WHERE "Product"."status" = 'ACTIVATED'
53
- AND "Product"."bizplace_id" IN (${bizplaceIds})
54
- ${productQuery}
55
- ) d2
56
- )
57
- `);
58
- await tx.query(`
59
- CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
60
- select "product_id", array_to_json(array_agg(row_to_json(dt))) AS "Json_marketplaceProducts" FROM (
61
- select "dt"."marketplace_store_id", "dt"."product_id", "dt"."sku", array_agg(row_to_json(dt)) as product_variation
62
- from (
63
- select "mp"."marketplace_store_id" as "marketplace_store_id", "mpv"."sku", "mpv"."id" as "marketplace_product_variation_id",
64
- concat("mpv"."variation_sku", ' (', "mpv"."name", ')') as "name", "mpv"."qty" as "qty", "mpv"."reserve_qty" as "reserve_qty",
65
- "Product"."product_id" AS "product_id"
66
- from marketplace_product_variations "mpv"
67
- inner join marketplace_products "mp" on "mp"."id" = "mpv"."marketplace_product_id"
68
- inner join temp_products "Product" on "mpv"."sku" = "Product"."product_sku"
69
- ) as "dt"
70
- group by "dt"."marketplace_store_id", "dt"."sku", "dt"."product_id"
71
- ) "dt" group by "dt"."product_id"
72
- )
73
- `);
74
- await tx.query(`
75
- CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
76
- select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
77
- select wboi.domain_id, fc.id as fulfillment_id, fc.name as fulfillment_name,
78
- coalesce(wboi.product_id, wboi.product_bundle_id) as product_id, wboi.qty - wboi.remain_qty as inventory_locked_qty, wboi.qty as inventory_qty
79
- from warehouse_bizplace_onhand_inventories wboi
80
- inner join domains d on d.id = wboi.domain_id
81
- inner join fulfillment_centers fc on fc.center_id = d.subdomain
82
- inner join bizplaces b on b.id = wboi.bizplace_id
83
- inner join companies c on c.id = b.company_id
84
- inner join bizplaces b2 on b2.domain_id = c.domain_id
85
- where fc.domain_id = $1 and b2.id IN (${bizplaceIds})
86
- ) "dt" group by "dt"."product_id"
87
- )
88
- `, [domain.id]);
89
- await tx.query(`
90
- CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
91
- SELECT "Product"."product_id" AS "Product_id", "Product"."product_sku" AS "Product_sku",
92
- "Product"."product_name" AS "Product_name", "Product"."product_description" AS "Product_description",
93
- "Product"."product_bizplace_id" AS "Product_bizplace_id",
94
- "Product"."creator_id" AS "Product_creator_id", "Product"."updater_id" AS "Product_updater_id",
95
- "Bizplace"."name" AS "Bizplace_name", "Bizplace"."description" AS "Bizplace_description", "Bizplace"."address" AS "Bizplace_address", "Bizplace"."postal_code" AS "Bizplace_postal_code",
96
- "Bizplace"."latlng" AS "Bizplace_latlng", "Bizplace"."status" AS "Bizplace_status", "Bizplace"."created_at" AS "Bizplace_created_at", "Bizplace"."updated_at" AS "Bizplace_updated_at",
97
- "Bizplace"."domain_id" AS "Bizplace_domain_id", "Bizplace"."company_id" AS "Bizplace_company_id", "Bizplace"."creator_id" AS "Bizplace_creator_id", "Bizplace"."updater_id" AS "Bizplace_updater_id",
98
- "Creator"."id" AS "Creator_id", "Creator"."name" AS "Creator_name", "Creator"."description" AS "Creator_description", "Creator"."email" AS "Creator_email",
99
- "Updater"."id" AS "Updater_id", "Updater"."name" AS "Updater_name", "Updater"."description" AS "Updater_description", "Updater"."email" AS "Updater_email"
100
- ,COALESCE("whInv"."Json_warehouseInventory", null) AS "Json_warehouseInventory"
101
- ,COALESCE("mktPrd"."Json_marketplaceProducts", null) AS "Json_marketplaceProducts"
102
- FROM "temp_products" "Product"
103
- LEFT JOIN "bizplaces" "Bizplace" ON "Bizplace"."id" = "Product"."product_bizplace_id"
104
- LEFT JOIN "users" "Creator" ON "Creator"."id"="Product"."creator_id"
105
- LEFT JOIN "users" "Updater" ON "Updater"."id"="Product"."updater_id"
106
- LEFT JOIN "temp_json_warehouse_inventory" "whInv" ON "whInv"."product_id" = "Product"."product_id"
107
- LEFT JOIN "temp_json_warehouse_marketplace_products" "mktPrd" ON "mktPrd"."product_id" = "Product"."product_id"
108
- )
109
- `);
110
- const offsetQuery = (params === null || params === void 0 ? void 0 : params.pagination)
111
- ? `OFFSET ${(params.pagination.page - 1) * params.pagination.limit} LIMIT ${params.pagination.limit}`
112
- : '';
113
- const total = await tx.query(`select count(*) from temp_warehouse_marketplace_products`);
114
- const items = await tx.query(`
115
- select * from temp_warehouse_marketplace_products ${offsetQuery}
116
- `);
117
- return {
118
- items: items.map((itm, index) => {
119
- return {
120
- seq: index + ((params === null || params === void 0 ? void 0 : params.pagination) ? (params.pagination.page - 1) * params.pagination.limit + 1 : 0),
121
- id: itm.Product_id,
122
- sku: itm.Product_sku,
123
- name: itm.Product_name,
124
- description: itm.Product_description,
125
- marketplaceProduct: itm.Json_marketplaceProducts
126
- ? itm.Json_marketplaceProducts.map(product => {
127
- return {
128
- marketplaceStore: { id: product.marketplace_store_id },
129
- marketplaceProductVariations: product.product_variation.map(variation => {
130
- return {
131
- id: variation.marketplace_product_variation_id,
132
- name: variation.name,
133
- qty: variation.qty,
134
- reserveQty: variation.reserve_qty
135
- };
136
- })
137
- };
138
- })
139
- : null,
140
- warehouseInventory: itm.Json_warehouseInventory
141
- ? itm.Json_warehouseInventory.map(inventory => {
142
- return {
143
- bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },
144
- product: { id: inventory.product_id },
145
- qty: inventory.inventory_qty,
146
- lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,
147
- remainQty: inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)
148
- };
149
- })
150
- : null
151
- };
152
- }),
153
- total: total[0].count
154
- };
155
- }
156
- exports.warehouseMarketplaceProduct = warehouseMarketplaceProduct;
157
- //# sourceMappingURL=warehouse-marketplace-products.js.map