@things-factory/operato-hub 4.2.12 → 4.3.0

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 (44) hide show
  1. package/client/pages/constants/setting.js +1 -0
  2. package/dist-server/controllers/bizplace-initializer/dataset/codes.js +9 -0
  3. package/dist-server/controllers/bizplace-initializer/dataset/codes.js.map +1 -1
  4. package/dist-server/controllers/bizplace-initializer/dataset/settings.js +10 -0
  5. package/dist-server/controllers/bizplace-initializer/dataset/settings.js.map +1 -1
  6. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js +171 -0
  7. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js.map +1 -0
  8. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js +85 -75
  9. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js.map +1 -1
  10. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +147 -35
  11. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
  12. package/dist-server/routers/api/restful-apis/unstable/index.js +1 -0
  13. package/dist-server/routers/api/restful-apis/unstable/index.js.map +1 -1
  14. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js +171 -0
  15. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js.map +1 -0
  16. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js +85 -75
  17. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js.map +1 -1
  18. package/dist-server/routers/api/restful-apis/v1/add-release-order.js +146 -34
  19. package/dist-server/routers/api/restful-apis/v1/add-release-order.js.map +1 -1
  20. package/dist-server/routers/api/restful-apis/v1/index.js +1 -0
  21. package/dist-server/routers/api/restful-apis/v1/index.js.map +1 -1
  22. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js +171 -0
  23. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js.map +1 -0
  24. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js +85 -75
  25. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js.map +1 -1
  26. package/dist-server/routers/api/restful-apis/v2/add-release-order.js +149 -34
  27. package/dist-server/routers/api/restful-apis/v2/add-release-order.js.map +1 -1
  28. package/dist-server/routers/api/restful-apis/v2/index.js +1 -0
  29. package/dist-server/routers/api/restful-apis/v2/index.js.map +1 -1
  30. package/package.json +44 -44
  31. package/server/controllers/bizplace-initializer/dataset/codes.ts +9 -0
  32. package/server/controllers/bizplace-initializer/dataset/settings.ts +10 -0
  33. package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +196 -0
  34. package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +97 -85
  35. package/server/routers/api/restful-apis/unstable/add-release-order.ts +211 -28
  36. package/server/routers/api/restful-apis/unstable/index.ts +1 -0
  37. package/server/routers/api/restful-apis/v1/add-draft-release-order.ts +196 -0
  38. package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +97 -85
  39. package/server/routers/api/restful-apis/v1/add-release-order.ts +209 -26
  40. package/server/routers/api/restful-apis/v1/index.ts +1 -0
  41. package/server/routers/api/restful-apis/v2/add-draft-release-order.ts +196 -0
  42. package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +97 -85
  43. package/server/routers/api/restful-apis/v2/add-release-order.ts +212 -26
  44. package/server/routers/api/restful-apis/v2/index.ts +1 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.checkMandatoryKey = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const typeorm_1 = require("typeorm");
9
+ const api_1 = require("@things-factory/api");
10
+ const biz_base_1 = require("@things-factory/biz-base");
11
+ const business_middleware_1 = require("../../../../middlewares/business-middleware");
12
+ const warehouse_middleware_1 = require("../../../../middlewares/warehouse-middleware");
13
+ const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-draft-release-order');
14
+ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-draft-release-order', business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
15
+ return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
17
+ const { client, domain } = context.state;
18
+ const { warehouseId: customerBizplaceId } = context.params;
19
+ const { t } = context;
20
+ if (!customerBizplaceId)
21
+ context.throw(404, t('error.warehouse id not found'));
22
+ let bodyReq = context.request.body;
23
+ if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
24
+ context.throw(400, t('error.invalid body request format'));
25
+ }
26
+ debug('post:/add-draft-release-order request.body', bodyReq);
27
+ await checkMandatoryKey(context, bodyReq);
28
+ // get customer company's bizplace
29
+ const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
30
+ where: { id: customerBizplaceId }
31
+ });
32
+ const orderInventories = bodyReq.orderInventories;
33
+ context.body = {
34
+ result: (await client.mutate({
35
+ mutation: (0, graphql_tag_1.default) `
36
+ mutation upsertDraftReleaseGood(
37
+ $draftReleaseGood: DraftReleaseGoodPatch!
38
+ $orderProducts: [OrderProductPatch!]!
39
+ $files: [Upload!]
40
+ ) {
41
+ upsertDraftReleaseGood(
42
+ draftReleaseGood: $draftReleaseGood
43
+ orderProducts: $orderProducts
44
+ files: $files
45
+ ) {
46
+ id
47
+ name
48
+ refNo
49
+ refNo2
50
+ refNo3
51
+ status
52
+ truckNo
53
+ ownTransport
54
+ marketplaceOrderStatus
55
+ billingAddress
56
+ deliveryAddress1
57
+ deliveryAddress2
58
+ deliveryAddress3
59
+ deliveryAddress4
60
+ deliveryAddress5
61
+ attentionTo
62
+ attentionCompany
63
+ city
64
+ state
65
+ postalCode
66
+ country
67
+ phone1
68
+ phone2
69
+ email
70
+ type
71
+ exportOption
72
+ releaseDate
73
+ collectionOrderNo
74
+ bizplace {
75
+ name
76
+ }
77
+ orderProducts {
78
+ product {
79
+ sku
80
+ name
81
+ description
82
+ }
83
+ packingType
84
+ packingSize
85
+ releaseQty
86
+ }
87
+ }
88
+ }
89
+ `,
90
+ variables: {
91
+ draftReleaseGood: {
92
+ bizplace: {
93
+ id: customerBizplace.id
94
+ },
95
+ courierOption: bodyReq.courierOption,
96
+ collectionOrderNo: bodyReq.collectionOrderNo,
97
+ exportOption: bodyReq.exportOption,
98
+ ownTransport: bodyReq.ownTransport,
99
+ packingOption: bodyReq.packingOption,
100
+ refNo: bodyReq.refNo,
101
+ refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
102
+ refNo3: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo3,
103
+ releaseDate: bodyReq.releaseDate,
104
+ type: bodyReq.type,
105
+ marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
106
+ remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
107
+ billingAddress: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _b === void 0 ? void 0 : _b.billingAddress) || null,
108
+ deliveryAddress1: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress1) || null,
109
+ deliveryAddress2: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress2) || null,
110
+ deliveryAddress3: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress3) || null,
111
+ deliveryAddress4: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress4) || null,
112
+ deliveryAddress5: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress5) || null,
113
+ attentionTo: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionTo) || null,
114
+ attentionCompany: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionCompany) || null,
115
+ city: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.city) || null,
116
+ state: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.state) || null,
117
+ postalCode: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.postalCode) || null,
118
+ country: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.country) || null,
119
+ phone1: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone1) || null,
120
+ phone2: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone2) || null,
121
+ email: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.email) || null
122
+ },
123
+ orderProducts: orderInventories,
124
+ files: []
125
+ },
126
+ context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
127
+ domain, type: 'api' }) })
128
+ })).data
129
+ };
130
+ });
131
+ });
132
+ async function checkMandatoryKey(context, params) {
133
+ let noparams = ['releaseDate', 'exportOption'].filter(param => !(param in params));
134
+ if ('ownTransport' in params) {
135
+ if (params.ownTransport == true) {
136
+ if (!params.hasOwnProperty('collectionOrderNo')) {
137
+ noparams.push('collectionOrderNo');
138
+ }
139
+ }
140
+ }
141
+ else {
142
+ noparams.push('ownTransport');
143
+ }
144
+ if ('exportOption' in params) {
145
+ if (params.exportOption === true) {
146
+ if (params.exportOption.filter(record => !record.containerNo || !record.containerArrivalDate || !record.containerLeavingDate || !record.shipName).length) {
147
+ noparams.push('exportOption');
148
+ }
149
+ }
150
+ }
151
+ if ('orderInventories' in params) {
152
+ params.orderInventories.forEach((param, key) => {
153
+ let noSubParams = [];
154
+ if (!(param === null || param === void 0 ? void 0 : param.releaseQty))
155
+ noSubParams.push('releaseQty');
156
+ if (!(param === null || param === void 0 ? void 0 : param.product))
157
+ noSubParams.push('product');
158
+ if (noSubParams === null || noSubParams === void 0 ? void 0 : noSubParams.length)
159
+ context.throw(400, context.t('error.required param x not found', { x: `${noSubParams.join(', ')}` }));
160
+ });
161
+ }
162
+ else {
163
+ noparams.push('orderInventories');
164
+ }
165
+ if (noparams === null || noparams === void 0 ? void 0 : noparams.length) {
166
+ context.throw(400, context.t('error.required param x not found', { x: `${noparams.join(', ')}` }));
167
+ }
168
+ return params;
169
+ }
170
+ exports.checkMandatoryKey = checkMandatoryKey;
171
+ //# sourceMappingURL=add-draft-release-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-draft-release-order.js","sourceRoot":"","sources":["../../../../../server/routers/api/restful-apis/v2/add-draft-release-order.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAC7B,qCAAsD;AAEtD,6CAAgE;AAChE,uDAAmD;AAGnD,qFAAgF;AAChF,uFAAkF;AAElF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,yEAAyE,CAAC,CAAA;AAEzG,sBAAM,CAAC,IAAI,CACT,oDAAoD,EACpD,wCAAkB,EAClB,0CAAmB,EACnB,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACtB,OAAO,MAAM,IAAA,uBAAa,GAAE,CAAC,WAAW,CAAC,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WAAW,CAAE,MAAM;gBACrB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,kCAAkC,EAAE,EAAE,CAAC,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QACzG,CAAC,CAAC,CAAA;KACH;SAAM;QACL,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;KAClC;IAED,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,kCAAkC,EAAE,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;KACnG;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA9CD,8CA8CC"}
@@ -9,92 +9,102 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.checkMandatoryKey = void 0;
10
10
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
11
11
  const api_1 = require("@things-factory/api");
12
+ const typeorm_1 = require("typeorm");
13
+ const marketplace_base_1 = require("@things-factory/marketplace-base");
12
14
  const business_middleware_1 = require("../../../../middlewares/business-middleware");
13
15
  const store_middleware_1 = require("../../../../middlewares/store-middleware");
14
16
  const debug = require('debug')('things-factory:operato-hub:restful-api:v2:add-marketplace-order');
15
17
  api_1.restfulApiRouter.post('/v2/warehouse/:storeId/add-marketplace-order', business_middleware_1.businessMiddleware, store_middleware_1.storeMiddleware, async (context, next) => {
16
- var _a;
17
- const { client, marketplaceStore, domain } = context.state;
18
- const { t } = context;
19
- const bodyReq = context.request.body;
20
- if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
21
- context.throw(400, t('error.invalid body request format'));
22
- }
23
- await checkMandatoryKey(context, bodyReq);
24
- debug('post:/add-marketplace-order body request', bodyReq);
25
- context.body = {
26
- result: (await client.mutate({
27
- mutation: (0, graphql_tag_1.default) `
28
- mutation generateMarketplaceOrder($marketplaceOrder: NewMarketplaceOrder!) {
29
- generateMarketplaceOrder(marketplaceOrder: $marketplaceOrder) {
30
- id
31
- orderNo
32
- currency
33
- itemCount
34
- totalAmount
35
- paymentMethod
36
- remark
37
- giftOption
38
- orderCreatedAt
39
- orderUpdatedAt
40
- marketplaceStore {
41
- storeId
42
- }
43
- marketplaceOrderItems {
18
+ return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
19
+ var _a;
20
+ const { client, marketplaceStore, domain } = context.state;
21
+ const { t } = context;
22
+ const bodyReq = context.request.body;
23
+ if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
24
+ context.throw(400, t('error.invalid body request format'));
25
+ }
26
+ await checkMandatoryKey(context, bodyReq);
27
+ debug('post:/add-marketplace-order body request', bodyReq);
28
+ let existingMarketplaceOrder = await tx.getRepository(marketplace_base_1.MarketplaceOrder).findOne({
29
+ where: { name: bodyReq.name, domain, marketplaceStore }
30
+ });
31
+ if (existingMarketplaceOrder) {
32
+ context.throw(400, `error.duplicate entry for order ${bodyReq.name}`);
33
+ }
34
+ context.body = {
35
+ result: (await client.mutate({
36
+ mutation: (0, graphql_tag_1.default) `
37
+ mutation generateMarketplaceOrder($marketplaceOrder: NewMarketplaceOrder!) {
38
+ generateMarketplaceOrder(marketplaceOrder: $marketplaceOrder) {
44
39
  id
45
- name
46
- qty
47
- cancelBy
48
- returnStatus
49
- paidPrice
50
- packageId
51
- invoiceNo
52
- status
53
- marketplaceOrderShippingItems {
54
- marketplaceOrderShipping {
55
- attentionTo
56
- address1
57
- address2
58
- address3
59
- address4
60
- address5
61
- state
62
- city
63
- postCode
64
- country
65
- phone1
66
- phone2
67
- email
68
- orderType
69
- freightType
70
- parcelType
71
- goodsType
72
- deliveryMethod
73
- totalWeight
74
- totalVolume
75
- transporter
76
- }
40
+ orderNo
41
+ currency
42
+ itemCount
43
+ totalAmount
44
+ paymentMethod
45
+ remark
46
+ giftOption
47
+ orderCreatedAt
48
+ orderUpdatedAt
49
+ marketplaceStore {
50
+ storeId
77
51
  }
78
- marketplaceProductVariation {
52
+ marketplaceOrderItems {
79
53
  id
80
- sku
81
- variationId
82
- variationSku
83
- channelSku
84
54
  name
85
- costPrice
86
- sellPrice
87
- marketplaceStatus
55
+ qty
56
+ cancelBy
57
+ returnStatus
58
+ paidPrice
59
+ packageId
60
+ invoiceNo
61
+ status
62
+ marketplaceOrderShippingItems {
63
+ marketplaceOrderShipping {
64
+ attentionTo
65
+ address1
66
+ address2
67
+ address3
68
+ address4
69
+ address5
70
+ state
71
+ city
72
+ postCode
73
+ country
74
+ phone1
75
+ phone2
76
+ email
77
+ orderType
78
+ freightType
79
+ parcelType
80
+ goodsType
81
+ deliveryMethod
82
+ totalWeight
83
+ totalVolume
84
+ transporter
85
+ }
86
+ }
87
+ marketplaceProductVariation {
88
+ id
89
+ sku
90
+ variationId
91
+ variationSku
92
+ channelSku
93
+ name
94
+ costPrice
95
+ sellPrice
96
+ marketplaceStatus
97
+ }
88
98
  }
89
99
  }
90
100
  }
91
- }
92
- `,
93
- variables: { marketplaceOrder: bodyReq },
94
- context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { marketplaceStore,
95
- domain, type: 'api' }) })
96
- })).data
97
- };
101
+ `,
102
+ variables: { marketplaceOrder: bodyReq },
103
+ context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { marketplaceStore,
104
+ domain, type: 'api' }) })
105
+ })).data
106
+ };
107
+ });
98
108
  });
99
109
  function checkMandatoryKey(context, params) {
100
110
  let noparams = [];
@@ -1 +1 @@
1
- {"version":3,"file":"add-marketplace-order.js","sourceRoot":"","sources":["../../../../../server/routers/api/restful-apis/v2/add-marketplace-order.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,kBAAkB;AA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AAC,CAAC,CAAA;KACH;SAAM;QACL,QAAQ,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;KACvC;IAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,kCAAkC,EAAE,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;KACnG;AACH,CAAC;AAjCD,8CAiCC"}
1
+ {"version":3,"file":"add-marketplace-order.js","sourceRoot":"","sources":["../../../../../server/routers/api/restful-apis/v2/add-marketplace-order.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,kBAAkB;AAClB,iBAAiB;;;;;;AAEjB,8DAA6B;AAE7B,6CAAgE;AAChE,qCAAsD;AACtD,uEAAmE;AAEnE,qFAAgF;AAChF,+EAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,iEAAiE,CAAC,CAAA;AAEjG,sBAAM,CAAC,IAAI,CACT,8CAA8C,EAC9C,wCAAkB,EAClB,kCAAe,EACf,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACtB,OAAO,MAAM,IAAA,uBAAa,GAAE,CAAC,WAAW,CAAC,KAAK,EAAE,EAAiB,EAAE,EAAE;;QACnE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1D,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAAA;QACrB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;QAEpC,IAAI,OAAO,OAAO,KAAK,SAAS,IAAI,CAAC,CAAA,MAAA,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,0CAAE,MAAM,CAAA,EAAE;YACjE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,m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KACnG;AACH,CAAC;AAjCD,8CAiCC"}
@@ -17,7 +17,7 @@ const warehouse_middleware_1 = require("../../../../middlewares/warehouse-middle
17
17
  const debug = require('debug')('things-factory:operato-hub:restful-api:v2:add-release-order');
18
18
  api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
19
19
  return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
20
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
20
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
21
21
  const { client, domain } = context.state;
22
22
  const { warehouseId: customerBizplaceId } = context.params;
23
23
  const { t } = context;
@@ -152,7 +152,6 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
152
152
  // Case 1. Every order inventories has specified batch id
153
153
  if (newOrderInventories.every((orderInventory) => orderInventory.batchId)) {
154
154
  finalOrderInventories = await Promise.all(newOrderInventories.map(async (orderInventory) => {
155
- var _a;
156
155
  let filters = [
157
156
  {
158
157
  name: 'batchId',
@@ -214,12 +213,18 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
214
213
  });
215
214
  if (!response.errors) {
216
215
  const items = response.data.inventoriesByPallet.items || [];
217
- if (!(items === null || items === void 0 ? void 0 : items.length))
218
- context.throw(404, t(`error.no inventories found for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku} with batch ID ${orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.batchId}`));
219
- items.forEach(item => {
220
- var _a;
216
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
217
+ context.body = {
218
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
219
+ };
220
+ return;
221
+ }
222
+ items.forEach(async (item) => {
221
223
  if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
222
- context.throw(404, t(`error.invalid release qty for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku}`));
224
+ context.body = {
225
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
226
+ };
227
+ return;
223
228
  }
224
229
  // 3. add more information to orderInventory
225
230
  orderInventory.product.id = item.product.id;
@@ -231,8 +236,12 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
231
236
  });
232
237
  return orderInventory;
233
238
  }
234
- else
235
- context.throw(404, t('error.failed to fetch inventory'));
239
+ else {
240
+ context.body = {
241
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
242
+ };
243
+ return;
244
+ }
236
245
  }));
237
246
  }
238
247
  else {
@@ -309,14 +318,30 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
309
318
  break;
310
319
  }
311
320
  let inventories = await qb.getMany();
312
- if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length))
313
- context.throw(404, t(`error.no inventories found for ${product.sku}`));
321
+ if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length)) {
322
+ context.body = {
323
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
324
+ };
325
+ return;
326
+ }
314
327
  inventories = inventories
315
328
  .map(inventory => {
316
329
  return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
317
330
  })
318
331
  .filter(inventory => inventory.remainQty > 0);
319
- const targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
332
+ let targetInventories;
333
+ try {
334
+ targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
335
+ }
336
+ catch (e) {
337
+ context.body = {
338
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
339
+ };
340
+ return;
341
+ }
342
+ targetInventories.map(item => {
343
+ finalOrderInventories.push(item.targetInventory);
344
+ });
320
345
  targetInventories.map(item => {
321
346
  finalOrderInventories.push(item.targetInventory);
322
347
  });
@@ -357,12 +382,18 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
357
382
  });
358
383
  if (!response.errors) {
359
384
  const items = response.data.inventoryProductGroup.items || [];
360
- if (!(items === null || items === void 0 ? void 0 : items.length))
361
- context.throw(404, t(`error.no inventories found for ${(_b = orderInventory.product) === null || _b === void 0 ? void 0 : _b.sku} with batch ID ${orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.batchId}`));
362
- items.forEach(item => {
363
- var _a;
385
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
386
+ context.body = {
387
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
388
+ };
389
+ return;
390
+ }
391
+ items.forEach(async (item) => {
364
392
  if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
365
- context.throw(404, t(`error.invalid release qty for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku}`));
393
+ context.body = {
394
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
395
+ };
396
+ return;
366
397
  }
367
398
  // 3. add more information to orderInventory
368
399
  orderInventory.product = { id: item.productId };
@@ -375,8 +406,12 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
375
406
  delete orderInventory.uomValue;
376
407
  finalOrderInventories.push(orderInventory);
377
408
  }
378
- else
379
- context.throw(404, t('error.failed to fetch inventory'));
409
+ else {
410
+ context.body = {
411
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
412
+ };
413
+ return;
414
+ }
380
415
  }
381
416
  }
382
417
  }
@@ -478,21 +513,21 @@ api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', busi
478
513
  type: bodyReq.type,
479
514
  marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
480
515
  remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
481
- billingAddress: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _c === void 0 ? void 0 : _c.billingAddress) || null,
482
- deliveryAddress1: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress1) || null,
483
- deliveryAddress2: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress2) || null,
484
- deliveryAddress3: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress3) || null,
485
- deliveryAddress4: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress4) || null,
486
- deliveryAddress5: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.deliveryAddress5) || null,
487
- attentionTo: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionTo) || null,
488
- attentionCompany: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.attentionCompany) || null,
489
- city: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.city) || null,
490
- state: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.state) || null,
491
- postalCode: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.postalCode) || null,
492
- country: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.country) || null,
493
- phone1: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone1) || null,
494
- phone2: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.phone2) || null,
495
- email: ((_s = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _s === void 0 ? void 0 : _s.email) || null,
516
+ billingAddress: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _b === void 0 ? void 0 : _b.billingAddress) || null,
517
+ deliveryAddress1: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress1) || null,
518
+ deliveryAddress2: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress2) || null,
519
+ deliveryAddress3: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress3) || null,
520
+ deliveryAddress4: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress4) || null,
521
+ deliveryAddress5: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress5) || null,
522
+ attentionTo: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionTo) || null,
523
+ attentionCompany: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionCompany) || null,
524
+ city: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.city) || null,
525
+ state: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.state) || null,
526
+ postalCode: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.postalCode) || null,
527
+ country: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.country) || null,
528
+ phone1: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone1) || null,
529
+ phone2: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone2) || null,
530
+ email: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.email) || null,
496
531
  transporter: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.transporter,
497
532
  trackingNo: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.trackingNo,
498
533
  airwayBill: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.airwayBill,
@@ -620,4 +655,84 @@ function combineItems(inventoryList) {
620
655
  });
621
656
  return mappedList;
622
657
  }
658
+ async function createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx) {
659
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
660
+ return (await client.mutate({
661
+ mutation: (0, graphql_tag_1.default) `
662
+ mutation upsertDraftReleaseGood(
663
+ $draftReleaseGood: DraftReleaseGoodPatch!
664
+ $orderProducts: [OrderProductPatch!]!
665
+ ) {
666
+ upsertDraftReleaseGood(draftReleaseGood: $draftReleaseGood, orderProducts: $orderProducts) {
667
+ id
668
+ name
669
+ refNo
670
+ refNo2
671
+ status
672
+ truckNo
673
+ ownTransport
674
+ marketplaceOrderStatus
675
+ billingAddress
676
+ deliveryAddress1
677
+ deliveryAddress2
678
+ deliveryAddress3
679
+ deliveryAddress4
680
+ deliveryAddress5
681
+ attentionTo
682
+ attentionCompany
683
+ city
684
+ state
685
+ postalCode
686
+ country
687
+ phone1
688
+ phone2
689
+ email
690
+ type
691
+ exportOption
692
+ releaseDate
693
+ collectionOrderNo
694
+ bizplace {
695
+ name
696
+ }
697
+ }
698
+ }
699
+ `,
700
+ variables: {
701
+ draftReleaseGood: {
702
+ bizplace: {
703
+ id: customerBizplace.id
704
+ },
705
+ courierOption: bodyReq.courierOption,
706
+ collectionOrderNo: bodyReq.collectionOrderNo,
707
+ exportOption: bodyReq.exportOption,
708
+ ownTransport: bodyReq.ownTransport,
709
+ packingOption: bodyReq.packingOption,
710
+ refNo: bodyReq.refNo,
711
+ refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
712
+ releaseDate: bodyReq.releaseDate,
713
+ type: bodyReq.type,
714
+ marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
715
+ remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
716
+ billingAddress: ((_a = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _a === void 0 ? void 0 : _a.billingAddress) || null,
717
+ deliveryAddress1: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _b === void 0 ? void 0 : _b.deliveryAddress1) || null,
718
+ deliveryAddress2: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress2) || null,
719
+ deliveryAddress3: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress3) || null,
720
+ deliveryAddress4: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress4) || null,
721
+ deliveryAddress5: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress5) || null,
722
+ attentionTo: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.attentionTo) || null,
723
+ attentionCompany: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionCompany) || null,
724
+ city: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.city) || null,
725
+ state: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.state) || null,
726
+ postalCode: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.postalCode) || null,
727
+ country: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.country) || null,
728
+ phone1: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.phone1) || null,
729
+ phone2: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone2) || null,
730
+ email: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.email) || null
731
+ },
732
+ orderProducts: orderInventories
733
+ },
734
+ context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
735
+ domain, type: 'api' }) })
736
+ })).data;
737
+ }
623
738
  //# sourceMappingURL=add-release-order.js.map