@things-factory/integration-sftp 4.1.0 → 4.1.4
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/herbalife/apis/create-shipment.js +23 -0
- package/dist-server/controllers/herbalife/apis/create-shipment.js.map +1 -0
- package/dist-server/controllers/herbalife/apis/get-outbound-order.js +48 -18
- package/dist-server/controllers/herbalife/apis/get-outbound-order.js.map +1 -1
- package/dist-server/controllers/herbalife/apis/index.js +1 -0
- package/dist-server/controllers/herbalife/apis/index.js.map +1 -1
- package/dist-server/controllers/herbalife/herbalife.js +67 -0
- package/dist-server/controllers/herbalife/herbalife.js.map +1 -1
- package/dist-server/controllers/sftp-api/index.js +7 -0
- package/dist-server/controllers/sftp-api/index.js.map +1 -1
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/sftp/sftp-mutation.js +31 -13
- package/dist-server/service/sftp/sftp-mutation.js.map +1 -1
- package/dist-server/sftp-s3.js +15 -8
- package/dist-server/sftp-s3.js.map +1 -1
- package/dist-server/util/generate-file.js +4 -2
- package/dist-server/util/generate-file.js.map +1 -1
- package/package.json +7 -7
- package/server/controllers/herbalife/apis/create-shipment.ts +19 -0
- package/server/controllers/herbalife/apis/get-outbound-order.ts +61 -24
- package/server/controllers/herbalife/apis/index.ts +1 -0
- package/server/controllers/herbalife/herbalife.ts +79 -0
- package/server/controllers/sftp-api/index.ts +3 -0
- package/server/index.ts +1 -0
- package/server/service/sftp/sftp-mutation.ts +33 -14
- package/server/sftp-s3.ts +22 -12
- package/server/util/generate-file.ts +5 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createShipment = void 0;
|
|
4
|
+
function createShipment() {
|
|
5
|
+
return {
|
|
6
|
+
method: 'post',
|
|
7
|
+
path: '{folderPath}/{folderType}/outbound_complete/data',
|
|
8
|
+
denormalize(req) {
|
|
9
|
+
const { releaseGood, orderInventories, sftp } = req;
|
|
10
|
+
const { folderPath } = sftp;
|
|
11
|
+
const folderType = sftp.isDevelopment ? `development` : `production`;
|
|
12
|
+
return {
|
|
13
|
+
resource: { folderPath, folderType },
|
|
14
|
+
payload: { releaseGood, orderInventories, sftp, folderType }
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
normalize(res) {
|
|
18
|
+
return res;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.createShipment = createShipment;
|
|
23
|
+
//# sourceMappingURL=create-shipment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-shipment.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/create-shipment.ts"],"names":[],"mappings":";;;AAAA,SAAgB,cAAc;IAC5B,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,kDAAkD;QACxD,WAAW,CAAC,GAAG;YACb,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;YACnD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;YAC3B,MAAM,UAAU,GAAW,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAA;YAE5E,OAAO;gBACL,QAAQ,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE;gBACpC,OAAO,EAAE,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,EAAE;aAC7D,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AAlBD,wCAkBC"}
|
|
@@ -11,21 +11,45 @@ function getOutboundOrder() {
|
|
|
11
11
|
resource: { folderPath, folderType, fileKey }
|
|
12
12
|
};
|
|
13
13
|
},
|
|
14
|
-
normalize(res) {
|
|
14
|
+
normalize(res, { sftp }) {
|
|
15
15
|
const { Order } = res;
|
|
16
|
+
let isAccept = false;
|
|
17
|
+
const responseFilePattern = JSON.parse(sftp.responseFilePattern);
|
|
18
|
+
const acceptOrderTypes = responseFilePattern.acceptOrderTypes; // ['RSO', 'MSO', 'MSBO']
|
|
19
|
+
const acceptNTSStatuses = responseFilePattern.acceptNTSStatuses; //['', 'BACKORDER']
|
|
20
|
+
const acceptWarehouseNumber = responseFilePattern.acceptWarehouseNumber; //['NK']
|
|
21
|
+
const acceptCommand = responseFilePattern.acceptCommand; //['NTS', '']
|
|
22
|
+
const acceptFreightCode = responseFilePattern.acceptFreightCode; // ['PU']
|
|
16
23
|
let orderHeader = Order.OrderHeader;
|
|
17
24
|
let generalInfo = orderHeader.General;
|
|
18
25
|
let distributorDetails = orderHeader.DistributorDetails;
|
|
26
|
+
let shippingInstructions = Order.ShippingInstructions;
|
|
27
|
+
let orderType = generalInfo.OrderType._text;
|
|
28
|
+
let ntsStatus = generalInfo.NTSStatus._text || '';
|
|
29
|
+
let command = generalInfo.Command._text || '';
|
|
30
|
+
let warehouseNumber = generalInfo.WarehouseNumber._text;
|
|
31
|
+
let freightCode = shippingInstructions.FreightCode._text;
|
|
32
|
+
if (acceptWarehouseNumber.includes(warehouseNumber) &&
|
|
33
|
+
acceptOrderTypes.includes(orderType) &&
|
|
34
|
+
acceptNTSStatuses.includes(ntsStatus) &&
|
|
35
|
+
acceptCommand.includes(command) &&
|
|
36
|
+
acceptFreightCode.includes(freightCode)) {
|
|
37
|
+
isAccept = true;
|
|
38
|
+
}
|
|
39
|
+
let shippingInstruction = shippingInstructions.ShippingInstructions._text;
|
|
19
40
|
let ntsDateParts = generalInfo.NTS_Date._text.split('/');
|
|
20
41
|
let releaseDate = ntsDateParts[2] + '-' + ntsDateParts[1] + '-' + ntsDateParts[0];
|
|
21
42
|
let orderInfo = {
|
|
22
43
|
refNo: generalInfo.OrderNumber._text,
|
|
44
|
+
refNo2: warehouseNumber,
|
|
23
45
|
type: 'b2c',
|
|
24
46
|
releaseDate,
|
|
25
47
|
collectionOrderNo: generalInfo.OrderNumber._text,
|
|
48
|
+
marketplaceOrderStatus: ntsStatus,
|
|
26
49
|
ownTransport: true,
|
|
27
50
|
exportOption: false,
|
|
28
51
|
packingOption: true,
|
|
52
|
+
remark: shippingInstruction,
|
|
29
53
|
billTo: {
|
|
30
54
|
billingAddress: distributorDetails.BillTo.BillToAddress._text
|
|
31
55
|
},
|
|
@@ -33,38 +57,44 @@ function getOutboundOrder() {
|
|
|
33
57
|
deliveryAddress1: distributorDetails.ShipTo.Address1._text,
|
|
34
58
|
deliveryAddress2: distributorDetails.ShipTo.Address2._text,
|
|
35
59
|
deliveryAddress3: distributorDetails.ShipTo.Address3._text,
|
|
36
|
-
deliveryAddress4: '-',
|
|
37
|
-
deliveryAddress5: '-',
|
|
38
60
|
attentionTo: distributorDetails.ShipTo.Name._text,
|
|
39
61
|
city: distributorDetails.ShipTo.City._text,
|
|
40
62
|
state: distributorDetails.ShipTo.ShipToState._text,
|
|
41
63
|
postalCode: distributorDetails.ShipTo.Zipcode._text,
|
|
42
64
|
country: distributorDetails.ShipTo.Country._text,
|
|
43
|
-
phone1: distributorDetails.ShipTo.Phone._text
|
|
44
|
-
phone2: '-',
|
|
45
|
-
email: '-'
|
|
65
|
+
phone1: distributorDetails.ShipTo.Phone._text
|
|
46
66
|
}
|
|
47
67
|
};
|
|
48
68
|
let OrderLine = Order.PickList;
|
|
49
69
|
let totalItems = parseFloat(Order.PickList.LinesInPickList._text);
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
let itemsToPick = [];
|
|
71
|
+
if (totalItems == 1) {
|
|
72
|
+
if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {
|
|
73
|
+
itemsToPick.push({
|
|
53
74
|
product: {
|
|
54
75
|
sku: OrderLine.Item.StockingSKU._text
|
|
55
76
|
},
|
|
56
77
|
releaseQty: parseFloat(OrderLine.Item.QuantityReleased._text)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
OrderLine.Item.map(line => {
|
|
83
|
+
if (parseFloat(line.QuantityReleased._text) > 0) {
|
|
84
|
+
itemsToPick.push({
|
|
85
|
+
product: {
|
|
86
|
+
sku: line.StockingSKU._text
|
|
87
|
+
},
|
|
88
|
+
releaseQty: parseFloat(line.QuantityReleased._text)
|
|
89
|
+
});
|
|
57
90
|
}
|
|
58
|
-
]
|
|
59
|
-
: OrderLine.Item.map(line => {
|
|
60
|
-
return {
|
|
61
|
-
product: {
|
|
62
|
-
sku: line.StockingSKU._text
|
|
63
|
-
},
|
|
64
|
-
releaseQty: parseFloat(line.QuantityReleased._text)
|
|
65
|
-
};
|
|
66
91
|
});
|
|
67
|
-
|
|
92
|
+
}
|
|
93
|
+
if (itemsToPick.length == 0) {
|
|
94
|
+
isAccept = false;
|
|
95
|
+
}
|
|
96
|
+
let orderItems = itemsToPick;
|
|
97
|
+
let result = Object.assign(Object.assign({}, orderInfo), { orderInventories: orderItems, isAccept });
|
|
68
98
|
return result;
|
|
69
99
|
}
|
|
70
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-outbound-order.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/get-outbound-order.ts"],"names":[],"mappings":";;;AAAA,SAAgB,gBAAgB;IAC9B,OAAO;QACL,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,0DAA0D;QAChE,WAAW,CAAC,GAAG;YACb,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;YAC/C,OAAO;gBACL,QAAQ,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE;aAC9C,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;
|
|
1
|
+
{"version":3,"file":"get-outbound-order.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/get-outbound-order.ts"],"names":[],"mapp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C,IAAI,CAAC;4BACf,OAAO,EAAE;gCACP,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK;6BAC5B;4BACD,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;yBACpD,CAAC,CAAA;qBACH;gBACH,CAAC,CAAC,CAAA;aACH;YAED,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE;gBAC3B,QAAQ,GAAG,KAAK,CAAA;aACjB;YAED,IAAI,UAAU,GAAU,WAAW,CAAA;YAEnC,IAAI,MAAM,mCACL,SAAS,KACZ,gBAAgB,EAAE,UAAU,EAC5B,QAAQ,GACT,CAAA;YAED,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC;AAhHD,4CAgHC"}
|
|
@@ -12,4 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./echo"), exports);
|
|
14
14
|
__exportStar(require("./get-outbound-order"), exports);
|
|
15
|
+
__exportStar(require("./create-shipment"), exports);
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,uDAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAsB;AACtB,uDAAoC;AACpC,oDAAiC"}
|
|
@@ -4,6 +4,7 @@ exports.Herbalife = void 0;
|
|
|
4
4
|
require("../../sftp-s3");
|
|
5
5
|
const xml_js_1 = require("xml-js");
|
|
6
6
|
const sftp_const_1 = require("../../sftp-const");
|
|
7
|
+
const generate_file_1 = require("../../util/generate-file");
|
|
7
8
|
const debug = require('debug')('things-factory:integration-sftp:herbalife');
|
|
8
9
|
class Herbalife {
|
|
9
10
|
constructor() { }
|
|
@@ -15,6 +16,72 @@ class Herbalife {
|
|
|
15
16
|
const result = Object.assign({}, item);
|
|
16
17
|
return result;
|
|
17
18
|
}
|
|
19
|
+
async post(path, data = {}) {
|
|
20
|
+
let sftp = data.sftp;
|
|
21
|
+
let releaseGood = data.releaseGood;
|
|
22
|
+
let orderInventories = data.orderInventories;
|
|
23
|
+
let responseFilePattern = JSON.parse(sftp.responseFilePattern);
|
|
24
|
+
const { suffix, warehouseCode, fileExtension, runningNumberDigit, sequence } = responseFilePattern;
|
|
25
|
+
let newSeq = parseFloat(sequence) + 1;
|
|
26
|
+
let newSequence = newSeq.toString().padStart(runningNumberDigit, '0');
|
|
27
|
+
let newResponseFilePattern = JSON.stringify(Object.assign(Object.assign({}, responseFilePattern), { sequence: newSeq.toString() }));
|
|
28
|
+
sftp = Object.assign(Object.assign({}, sftp), { responseFilePattern: newResponseFilePattern });
|
|
29
|
+
const warehouseNumber = releaseGood.refNo2;
|
|
30
|
+
let title = suffix ? suffix : ``;
|
|
31
|
+
title += newSequence;
|
|
32
|
+
title += warehouseNumber ? `_` + warehouseNumber : ``;
|
|
33
|
+
title += fileExtension ? `.` + fileExtension : ``;
|
|
34
|
+
const orderNoColumn = 15;
|
|
35
|
+
const shipmentColumn = 27;
|
|
36
|
+
const trackingNoColumn = 20;
|
|
37
|
+
const refNoLength = releaseGood.refNo.length;
|
|
38
|
+
let content = `1710` + releaseGood.refNo;
|
|
39
|
+
let spaceNeeded = orderNoColumn - refNoLength;
|
|
40
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
41
|
+
content += ` `;
|
|
42
|
+
}
|
|
43
|
+
content += warehouseNumber;
|
|
44
|
+
content += `001000001`;
|
|
45
|
+
for (let i = 0; i < shipmentColumn; i++) {
|
|
46
|
+
content += ` `;
|
|
47
|
+
}
|
|
48
|
+
content += `000000 `;
|
|
49
|
+
for (let i = 0; i < trackingNoColumn; i++) {
|
|
50
|
+
content += ` `;
|
|
51
|
+
}
|
|
52
|
+
content += `000000000000 `;
|
|
53
|
+
const today = new Date();
|
|
54
|
+
const year = today.getFullYear().toString();
|
|
55
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0');
|
|
56
|
+
const day = today.getDate().toString().padStart(2, '0');
|
|
57
|
+
const newDate = year + month + day;
|
|
58
|
+
content += newDate + '\n';
|
|
59
|
+
for (let i = 0; i < orderInventories.length; i++) {
|
|
60
|
+
const orderInventory = orderInventories[i];
|
|
61
|
+
let sku = orderInventory.product.brandSku;
|
|
62
|
+
content += `1810` + releaseGood.refNo;
|
|
63
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
64
|
+
content += ` `;
|
|
65
|
+
}
|
|
66
|
+
const idx = (i + 1).toString().padStart(2, '0');
|
|
67
|
+
const productCode = sku.substring(0, 4);
|
|
68
|
+
content += idx + `000000` + productCode;
|
|
69
|
+
let productCodeSpaceNeeded = 7 - productCode.length;
|
|
70
|
+
for (let i = 0; i < productCodeSpaceNeeded; i++) {
|
|
71
|
+
content += ` `;
|
|
72
|
+
}
|
|
73
|
+
const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0');
|
|
74
|
+
const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0');
|
|
75
|
+
content += orderedQty + pickedQty + '\n';
|
|
76
|
+
}
|
|
77
|
+
const params = {
|
|
78
|
+
title,
|
|
79
|
+
uploadPath: path,
|
|
80
|
+
content
|
|
81
|
+
};
|
|
82
|
+
await (0, generate_file_1.generateFile)(params);
|
|
83
|
+
return sftp;
|
|
84
|
+
}
|
|
18
85
|
}
|
|
19
86
|
exports.Herbalife = Herbalife;
|
|
20
87
|
//# sourceMappingURL=herbalife.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"herbalife.js","sourceRoot":"","sources":["../../../server/controllers/herbalife/herbalife.ts"],"names":[],"mappings":";;;AAAA,yBAAsB;AAEtB,mCAA+B;
|
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AE,CAAC,EAAE,EAAE;gBAC/C,OAAO,IAAI,GAAG,CAAA;aACf;YACD,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YACxE,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YACtE,OAAO,IAAI,UAAU,GAAG,SAAS,GAAG,IAAI,CAAA;SACzC;QAED,MAAM,MAAM,GAAQ;YAClB,KAAK;YACL,UAAU,EAAE,IAAI;YAChB,OAAO;SACR,CAAA;QACD,MAAM,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAA;QAE1B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAxFD,8BAwFC"}
|
|
@@ -32,6 +32,7 @@ class SftpAPI {
|
|
|
32
32
|
}
|
|
33
33
|
static echo(sftp, req) { }
|
|
34
34
|
static getOutboundOrder(sftp, req) { }
|
|
35
|
+
static createShipment(sftp, req) { }
|
|
35
36
|
}
|
|
36
37
|
SftpAPI.platforms = {};
|
|
37
38
|
__decorate([
|
|
@@ -46,5 +47,11 @@ __decorate([
|
|
|
46
47
|
__metadata("design:paramtypes", [Object, Object]),
|
|
47
48
|
__metadata("design:returntype", Object)
|
|
48
49
|
], SftpAPI, "getOutboundOrder", null);
|
|
50
|
+
__decorate([
|
|
51
|
+
decorators_1.api,
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
54
|
+
__metadata("design:returntype", Object)
|
|
55
|
+
], SftpAPI, "createShipment", null);
|
|
49
56
|
exports.SftpAPI = SftpAPI;
|
|
50
57
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sftp-api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AA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AAO,MAAM,UAAU,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE,EAAE,EAAE,EAAE;YACb,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;IACJ,CAAC;IAGD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAQ,CAAC;IAG9B,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,IAAQ,CAAC;IAG1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,IAAQ,CAAC;;AA5BjC,iBAAS,GAAG,EAAE,CAAA;AAsBrB;IADC,gBAAG;;;;yBAC0B;AAG9B;IADC,gBAAG;;;;qCACsC;AAG1C;IADC,gBAAG;;;;mCACoC;AA7B1C,0BA8BC"}
|
package/dist-server/index.js
CHANGED
|
@@ -14,5 +14,6 @@ require("./routes");
|
|
|
14
14
|
__exportStar(require("./middlewares"), exports);
|
|
15
15
|
__exportStar(require("./service"), exports);
|
|
16
16
|
__exportStar(require("./sftp-const"), exports);
|
|
17
|
+
__exportStar(require("./controllers"), exports);
|
|
17
18
|
__exportStar(require("./util"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oBAAiB;AAEjB,gDAA6B;AAC7B,4CAAyB;AACzB,+CAA4B;AAC5B,yCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oBAAiB;AAEjB,gDAA6B;AAC7B,4CAAyB;AACzB,+CAA4B;AAC5B,gDAA6B;AAC7B,yCAAsB"}
|
|
@@ -101,21 +101,39 @@ let SftpMutation = class SftpMutation {
|
|
|
101
101
|
const lastSlashIdx = fileKey.lastIndexOf('/');
|
|
102
102
|
const fileString = fileKey.substring(lastSlashIdx + 1, fileKey.length);
|
|
103
103
|
try {
|
|
104
|
-
const sftp =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
const sftp = sftpUser;
|
|
105
|
+
let result = await controllers_1.SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString });
|
|
106
|
+
let isAccept = result.isAccept;
|
|
107
|
+
if (isAccept) {
|
|
108
|
+
delete result.isAccept;
|
|
109
|
+
if (result) {
|
|
110
|
+
let { items: releaseOrders } = await integration_fulfillment_1.FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
|
|
111
|
+
customerBizplaceId,
|
|
112
|
+
refNo: result.refNo
|
|
113
|
+
});
|
|
114
|
+
if (releaseOrders) {
|
|
115
|
+
result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1);
|
|
116
|
+
}
|
|
117
|
+
var releaseOrder = await integration_fulfillment_1.FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
118
|
+
customerBizplaceId,
|
|
119
|
+
releaseOrder: result
|
|
120
|
+
});
|
|
121
|
+
if (releaseOrder) {
|
|
122
|
+
let movePaths = {
|
|
123
|
+
source: dataPath += fileString,
|
|
124
|
+
destination: successPath += fileString
|
|
125
|
+
};
|
|
126
|
+
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
127
|
+
}
|
|
117
128
|
}
|
|
118
129
|
}
|
|
130
|
+
else {
|
|
131
|
+
let movePaths = {
|
|
132
|
+
source: dataPath += fileString,
|
|
133
|
+
destination: failedPath += fileString
|
|
134
|
+
};
|
|
135
|
+
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
136
|
+
}
|
|
119
137
|
}
|
|
120
138
|
catch (e) {
|
|
121
139
|
let movePaths = {
|
|
@@ -1 +1 @@
|
|
|
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uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAC9C,WAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;8CAK7C;AAID;IAFC,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,0BAA0B,EAAE,CAAC;IACvD,WAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAAiB,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;+CASpE;AAID;IAFC,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;IAE3E,WAAA,IAAA,kBAAG,EAAC,kBAAkB,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;IACvC,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;kDAmFP;AA1LU,YAAY;IADxB,IAAA,uBAAQ,EAAC,WAAI,CAAC;GACF,YAAY,CA2LxB;AA3LY,oCAAY"}
|
package/dist-server/sftp-s3.js
CHANGED
|
@@ -7,6 +7,8 @@ const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
|
7
7
|
const v4_1 = __importDefault(require("uuid/v4"));
|
|
8
8
|
const env_1 = require("@things-factory/env");
|
|
9
9
|
const sftp_const_1 = require("./sftp-const");
|
|
10
|
+
const { PassThrough } = require('stream');
|
|
11
|
+
const path = require('path');
|
|
10
12
|
const { fs } = require('memfs');
|
|
11
13
|
if (sftp_const_1.SFTPFILESTORAGE && sftp_const_1.SFTPFILESTORAGE.type == 's3') {
|
|
12
14
|
const S3 = new aws_sdk_1.default.S3({
|
|
@@ -48,16 +50,21 @@ if (sftp_const_1.SFTPFILESTORAGE && sftp_const_1.SFTPFILESTORAGE.type == 's3') {
|
|
|
48
50
|
return true;
|
|
49
51
|
};
|
|
50
52
|
/* upload file */
|
|
51
|
-
sftp_const_1.SFTPFILESTORAGE.uploadFile = ({ filename, uploadPath }) => {
|
|
53
|
+
sftp_const_1.SFTPFILESTORAGE.uploadFile = ({ stream, filename, uploadPath }) => {
|
|
52
54
|
const id = (0, v4_1.default)();
|
|
53
55
|
let size = 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return new Promise((resolve, reject) => stream
|
|
57
|
+
.pipe((() => {
|
|
58
|
+
var pass = new PassThrough();
|
|
59
|
+
S3.upload({
|
|
60
|
+
Bucket: sftp_const_1.SFTPFILESTORAGE.bucketName,
|
|
61
|
+
Key: uploadPath + '/' + filename,
|
|
62
|
+
Body: pass
|
|
63
|
+
}, (err, data) => (err ? reject(err) : resolve({ id, path: uploadPath, size })));
|
|
64
|
+
return pass;
|
|
65
|
+
})())
|
|
66
|
+
.on('error', error => reject(error))
|
|
67
|
+
.on('data', chunk => (size += chunk.length)));
|
|
61
68
|
};
|
|
62
69
|
env_1.logger.info('S3 Bucket Storage is Ready.');
|
|
63
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-s3.js","sourceRoot":"","sources":["../server/sftp-s3.ts"],"names":[],"mappings":";;;;;AAAA,sDAAyB;AACzB,iDAA0B;AAE1B,6CAA4C;AAE5C,6CAA8C;AAE9C,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/B,IAAI,4BAAe,IAAI,4BAAe,CAAC,IAAI,IAAI,IAAI,EAAE;IACnD,MAAM,EAAE,GAAG,IAAI,iBAAG,CAAC,EAAE,CAAC;QACpB,WAAW,EAAE,4BAAe,CAAC,WAAW;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MAAM;aACH,IAAI,CACH,CAAC,GAAG,EAAE;YACJ,IAAI,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;YAE5B,EAAE,CAAC,MAAM,CACP;gBACE,MAAM,EAAE,4BAAe,CAAC,UAAU;gBAClC,GAAG,EAAE,UAAU,GAAG,GAAG,GAAG,QAAQ;gBAChC,IAAI,EAAE,IAAI;aACX,EACD,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAC7E,CAAA;YAED,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,EAAE,CACL;aACA,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACnC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAC/C,CAAA;IACH,CAAC,CAAA;IAED,YAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;CAC3C"}
|
|
@@ -4,7 +4,7 @@ exports.generateFile = void 0;
|
|
|
4
4
|
require("../sftp-s3");
|
|
5
5
|
const sftp_const_1 = require("../sftp-const");
|
|
6
6
|
const fs = require('fs');
|
|
7
|
-
async function generateFile(params
|
|
7
|
+
async function generateFile(params) {
|
|
8
8
|
const { uploadPath, content, title } = params;
|
|
9
9
|
const fileDirectory = './uploaded-files';
|
|
10
10
|
if (!fs.existsSync(fileDirectory)) {
|
|
@@ -17,8 +17,10 @@ async function generateFile(params, context) {
|
|
|
17
17
|
console.log('File is created successfully.');
|
|
18
18
|
});
|
|
19
19
|
if (uploadPath) {
|
|
20
|
-
|
|
20
|
+
const stream = fs.createReadStream(filePath);
|
|
21
|
+
await sftp_const_1.SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath });
|
|
21
22
|
}
|
|
23
|
+
fs.rmdirSync(fileDirectory, { recursive: true });
|
|
22
24
|
return true;
|
|
23
25
|
}
|
|
24
26
|
exports.generateFile = generateFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-file.js","sourceRoot":"","sources":["../../server/util/generate-file.ts"],"names":[],"mappings":";;;AAAA,sBAAmB;AAEnB,8CAA+C;AAE/C,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjB,KAAK,UAAU,YAAY,CAAC,MAAW
|
|
1
|
+
{"version":3,"file":"generate-file.js","sourceRoot":"","sources":["../../server/util/generate-file.ts"],"names":[],"mappings":";;;AAAA,sBAAmB;AAEnB,8CAA+C;AAE/C,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjB,KAAK,UAAU,YAAY,CAAC,MAAW;IAC5C,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAC7C,MAAM,aAAa,GAAG,kBAAkB,CAAA;IAExC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;QACjC,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;KAC5B;IAED,MAAM,QAAQ,GAAG,aAAa,GAAG,GAAG,GAAG,KAAK,CAAA;IAE5C,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG;QAC3C,IAAI,GAAG;YAAE,MAAM,GAAG,CAAA;QAClB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,IAAI,UAAU,EAAE;QACd,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QAC5C,MAAM,4BAAe,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAA;KAC1E;IAED,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAEhD,OAAO,IAAI,CAAA;AACb,CAAC;AAvBD,oCAuBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-sftp",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^4.
|
|
28
|
-
"@things-factory/biz-base": "^4.
|
|
29
|
-
"@things-factory/env": "^4.
|
|
30
|
-
"@things-factory/integration-fulfillment": "^4.1.
|
|
31
|
-
"@things-factory/shell": "^4.
|
|
27
|
+
"@things-factory/auth-base": "^4.1.2",
|
|
28
|
+
"@things-factory/biz-base": "^4.1.2",
|
|
29
|
+
"@things-factory/env": "^4.1.2",
|
|
30
|
+
"@things-factory/integration-fulfillment": "^4.1.3",
|
|
31
|
+
"@things-factory/shell": "^4.1.2",
|
|
32
32
|
"aws-sdk": "^2.960.0",
|
|
33
33
|
"xml-js": "^1.6.11"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "fe43ed4363f25856ee6b7028a726f228b1aec945"
|
|
36
36
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function createShipment() {
|
|
2
|
+
return {
|
|
3
|
+
method: 'post',
|
|
4
|
+
path: '{folderPath}/{folderType}/outbound_complete/data',
|
|
5
|
+
denormalize(req) {
|
|
6
|
+
const { releaseGood, orderInventories, sftp } = req
|
|
7
|
+
const { folderPath } = sftp
|
|
8
|
+
const folderType: string = sftp.isDevelopment ? `development` : `production`
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
resource: { folderPath, folderType },
|
|
12
|
+
payload: { releaseGood, orderInventories, sftp, folderType }
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
normalize(res) {
|
|
16
|
+
return res
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -8,22 +8,52 @@ export function getOutboundOrder() {
|
|
|
8
8
|
resource: { folderPath, folderType, fileKey }
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
|
-
normalize(res) {
|
|
11
|
+
normalize(res, { sftp }) {
|
|
12
12
|
const { Order } = res
|
|
13
|
+
let isAccept: boolean = false
|
|
14
|
+
|
|
15
|
+
const responseFilePattern = JSON.parse(sftp.responseFilePattern)
|
|
16
|
+
const acceptOrderTypes = responseFilePattern.acceptOrderTypes // ['RSO', 'MSO', 'MSBO']
|
|
17
|
+
const acceptNTSStatuses = responseFilePattern.acceptNTSStatuses //['', 'BACKORDER']
|
|
18
|
+
const acceptWarehouseNumber = responseFilePattern.acceptWarehouseNumber //['NK']
|
|
19
|
+
const acceptCommand = responseFilePattern.acceptCommand //['NTS', '']
|
|
20
|
+
const acceptFreightCode = responseFilePattern.acceptFreightCode // ['PU']
|
|
13
21
|
|
|
14
22
|
let orderHeader: any = Order.OrderHeader
|
|
15
23
|
let generalInfo: any = orderHeader.General
|
|
16
24
|
let distributorDetails: any = orderHeader.DistributorDetails
|
|
25
|
+
let shippingInstructions: any = Order.ShippingInstructions
|
|
26
|
+
|
|
27
|
+
let orderType: string = generalInfo.OrderType._text
|
|
28
|
+
let ntsStatus: string = generalInfo.NTSStatus._text || ''
|
|
29
|
+
let command: string = generalInfo.Command._text || ''
|
|
30
|
+
let warehouseNumber: string = generalInfo.WarehouseNumber._text
|
|
31
|
+
let freightCode: string = shippingInstructions.FreightCode._text
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
acceptWarehouseNumber.includes(warehouseNumber) &&
|
|
35
|
+
acceptOrderTypes.includes(orderType) &&
|
|
36
|
+
acceptNTSStatuses.includes(ntsStatus) &&
|
|
37
|
+
acceptCommand.includes(command) &&
|
|
38
|
+
acceptFreightCode.includes(freightCode)
|
|
39
|
+
) {
|
|
40
|
+
isAccept = true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let shippingInstruction: string = shippingInstructions.ShippingInstructions._text
|
|
17
44
|
let ntsDateParts = generalInfo.NTS_Date._text.split('/')
|
|
18
45
|
let releaseDate: string = ntsDateParts[2] + '-' + ntsDateParts[1] + '-' + ntsDateParts[0]
|
|
19
46
|
let orderInfo: any = {
|
|
20
47
|
refNo: generalInfo.OrderNumber._text,
|
|
48
|
+
refNo2: warehouseNumber,
|
|
21
49
|
type: 'b2c',
|
|
22
50
|
releaseDate,
|
|
23
51
|
collectionOrderNo: generalInfo.OrderNumber._text,
|
|
52
|
+
marketplaceOrderStatus: ntsStatus,
|
|
24
53
|
ownTransport: true,
|
|
25
54
|
exportOption: false,
|
|
26
55
|
packingOption: true,
|
|
56
|
+
remark: shippingInstruction,
|
|
27
57
|
billTo: {
|
|
28
58
|
billingAddress: distributorDetails.BillTo.BillToAddress._text
|
|
29
59
|
},
|
|
@@ -31,43 +61,50 @@ export function getOutboundOrder() {
|
|
|
31
61
|
deliveryAddress1: distributorDetails.ShipTo.Address1._text,
|
|
32
62
|
deliveryAddress2: distributorDetails.ShipTo.Address2._text,
|
|
33
63
|
deliveryAddress3: distributorDetails.ShipTo.Address3._text,
|
|
34
|
-
deliveryAddress4: '-',
|
|
35
|
-
deliveryAddress5: '-',
|
|
36
64
|
attentionTo: distributorDetails.ShipTo.Name._text,
|
|
37
65
|
city: distributorDetails.ShipTo.City._text,
|
|
38
66
|
state: distributorDetails.ShipTo.ShipToState._text,
|
|
39
67
|
postalCode: distributorDetails.ShipTo.Zipcode._text,
|
|
40
68
|
country: distributorDetails.ShipTo.Country._text,
|
|
41
|
-
phone1: distributorDetails.ShipTo.Phone._text
|
|
42
|
-
phone2: '-',
|
|
43
|
-
email: '-'
|
|
69
|
+
phone1: distributorDetails.ShipTo.Phone._text
|
|
44
70
|
}
|
|
45
71
|
}
|
|
46
72
|
|
|
47
73
|
let OrderLine = Order.PickList
|
|
48
74
|
let totalItems: number = parseFloat(Order.PickList.LinesInPickList._text)
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
75
|
+
let itemsToPick: any[] = []
|
|
76
|
+
if (totalItems == 1) {
|
|
77
|
+
if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {
|
|
78
|
+
itemsToPick.push({
|
|
79
|
+
product: {
|
|
80
|
+
sku: OrderLine.Item.StockingSKU._text
|
|
81
|
+
},
|
|
82
|
+
releaseQty: parseFloat(OrderLine.Item.QuantityReleased._text)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
OrderLine.Item.map(line => {
|
|
87
|
+
if (parseFloat(line.QuantityReleased._text) > 0) {
|
|
88
|
+
itemsToPick.push({
|
|
89
|
+
product: {
|
|
90
|
+
sku: line.StockingSKU._text
|
|
91
|
+
},
|
|
92
|
+
releaseQty: parseFloat(line.QuantityReleased._text)
|
|
66
93
|
})
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (itemsToPick.length == 0) {
|
|
99
|
+
isAccept = false
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let orderItems: any[] = itemsToPick
|
|
67
103
|
|
|
68
104
|
let result: any = {
|
|
69
105
|
...orderInfo,
|
|
70
|
-
orderInventories: orderItems
|
|
106
|
+
orderInventories: orderItems,
|
|
107
|
+
isAccept
|
|
71
108
|
}
|
|
72
109
|
|
|
73
110
|
return result
|
|
@@ -2,7 +2,9 @@ import '../../sftp-s3'
|
|
|
2
2
|
|
|
3
3
|
import { xml2js } from 'xml-js'
|
|
4
4
|
|
|
5
|
+
import { Sftp } from '../../service'
|
|
5
6
|
import { SFTPFILESTORAGE } from '../../sftp-const'
|
|
7
|
+
import { generateFile } from '../../util/generate-file'
|
|
6
8
|
|
|
7
9
|
const debug = require('debug')('things-factory:integration-sftp:herbalife')
|
|
8
10
|
|
|
@@ -19,4 +21,81 @@ export class Herbalife {
|
|
|
19
21
|
const result: any = { ...item }
|
|
20
22
|
return result
|
|
21
23
|
}
|
|
24
|
+
|
|
25
|
+
async post(path: string, data: any = {}) {
|
|
26
|
+
let sftp: Sftp = data.sftp
|
|
27
|
+
let releaseGood: any = data.releaseGood
|
|
28
|
+
let orderInventories: any[] = data.orderInventories
|
|
29
|
+
|
|
30
|
+
let responseFilePattern: any = JSON.parse(sftp.responseFilePattern)
|
|
31
|
+
const { suffix, warehouseCode, fileExtension, runningNumberDigit, sequence } = responseFilePattern
|
|
32
|
+
let newSeq: number = parseFloat(sequence) + 1
|
|
33
|
+
let newSequence = newSeq.toString().padStart(runningNumberDigit, '0')
|
|
34
|
+
let newResponseFilePattern: string = JSON.stringify({
|
|
35
|
+
...responseFilePattern,
|
|
36
|
+
sequence: newSeq.toString()
|
|
37
|
+
})
|
|
38
|
+
sftp = { ...sftp, responseFilePattern: newResponseFilePattern }
|
|
39
|
+
|
|
40
|
+
const warehouseNumber: string = releaseGood.refNo2
|
|
41
|
+
let title: string = suffix ? suffix : ``
|
|
42
|
+
title += newSequence
|
|
43
|
+
title += warehouseNumber ? `_` + warehouseNumber : ``
|
|
44
|
+
title += fileExtension ? `.` + fileExtension : ``
|
|
45
|
+
|
|
46
|
+
const orderNoColumn: number = 15
|
|
47
|
+
const shipmentColumn: number = 27
|
|
48
|
+
const trackingNoColumn: number = 20
|
|
49
|
+
|
|
50
|
+
const refNoLength: number = releaseGood.refNo.length
|
|
51
|
+
let content: string = `1710` + releaseGood.refNo
|
|
52
|
+
let spaceNeeded: number = orderNoColumn - refNoLength
|
|
53
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
54
|
+
content += ` `
|
|
55
|
+
}
|
|
56
|
+
content += warehouseNumber
|
|
57
|
+
content += `001000001`
|
|
58
|
+
for (let i = 0; i < shipmentColumn; i++) {
|
|
59
|
+
content += ` `
|
|
60
|
+
}
|
|
61
|
+
content += `000000 `
|
|
62
|
+
for (let i = 0; i < trackingNoColumn; i++) {
|
|
63
|
+
content += ` `
|
|
64
|
+
}
|
|
65
|
+
content += `000000000000 `
|
|
66
|
+
const today = new Date()
|
|
67
|
+
const year = today.getFullYear().toString()
|
|
68
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0')
|
|
69
|
+
const day = today.getDate().toString().padStart(2, '0')
|
|
70
|
+
const newDate = year + month + day
|
|
71
|
+
content += newDate + '\n'
|
|
72
|
+
|
|
73
|
+
for (let i = 0; i < orderInventories.length; i++) {
|
|
74
|
+
const orderInventory: any = orderInventories[i]
|
|
75
|
+
let sku: string = orderInventory.product.brandSku
|
|
76
|
+
content += `1810` + releaseGood.refNo
|
|
77
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
78
|
+
content += ` `
|
|
79
|
+
}
|
|
80
|
+
const idx = (i + 1).toString().padStart(2, '0')
|
|
81
|
+
const productCode: string = sku.substring(0, 4)
|
|
82
|
+
content += idx + `000000` + productCode
|
|
83
|
+
let productCodeSpaceNeeded = 7 - productCode.length
|
|
84
|
+
for (let i = 0; i < productCodeSpaceNeeded; i++) {
|
|
85
|
+
content += ` `
|
|
86
|
+
}
|
|
87
|
+
const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0')
|
|
88
|
+
const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0')
|
|
89
|
+
content += orderedQty + pickedQty + '\n'
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const params: any = {
|
|
93
|
+
title,
|
|
94
|
+
uploadPath: path,
|
|
95
|
+
content
|
|
96
|
+
}
|
|
97
|
+
await generateFile(params)
|
|
98
|
+
|
|
99
|
+
return sftp
|
|
100
|
+
}
|
|
22
101
|
}
|
package/server/index.ts
CHANGED
|
@@ -153,22 +153,41 @@ export class SftpMutation {
|
|
|
153
153
|
const lastSlashIdx = fileKey.lastIndexOf('/')
|
|
154
154
|
const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)
|
|
155
155
|
try {
|
|
156
|
-
const sftp: any =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
156
|
+
const sftp: any = sftpUser
|
|
157
|
+
let result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })
|
|
158
|
+
let isAccept: boolean = result.isAccept
|
|
159
|
+
|
|
160
|
+
if (isAccept) {
|
|
161
|
+
delete result.isAccept
|
|
162
|
+
if (result) {
|
|
163
|
+
let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
|
|
164
|
+
customerBizplaceId,
|
|
165
|
+
refNo: result.refNo
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
if (releaseOrders) {
|
|
169
|
+
result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1)
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
+
|
|
172
|
+
var releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
173
|
+
customerBizplaceId,
|
|
174
|
+
releaseOrder: result
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
if (releaseOrder) {
|
|
178
|
+
let movePaths = {
|
|
179
|
+
source: dataPath += fileString,
|
|
180
|
+
destination: successPath += fileString
|
|
181
|
+
}
|
|
182
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
let movePaths = {
|
|
187
|
+
source: dataPath += fileString,
|
|
188
|
+
destination: failedPath += fileString
|
|
171
189
|
}
|
|
190
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
172
191
|
}
|
|
173
192
|
} catch (e) {
|
|
174
193
|
let movePaths = {
|
package/server/sftp-s3.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { logger } from '@things-factory/env'
|
|
|
5
5
|
|
|
6
6
|
import { SFTPFILESTORAGE } from './sftp-const'
|
|
7
7
|
|
|
8
|
+
const { PassThrough } = require('stream')
|
|
9
|
+
const path = require('path')
|
|
8
10
|
const { fs } = require('memfs')
|
|
9
11
|
|
|
10
12
|
if (SFTPFILESTORAGE && SFTPFILESTORAGE.type == 's3') {
|
|
@@ -60,22 +62,30 @@ if (SFTPFILESTORAGE && SFTPFILESTORAGE.type == 's3') {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/* upload file */
|
|
63
|
-
SFTPFILESTORAGE.uploadFile = ({ filename, uploadPath }) => {
|
|
65
|
+
SFTPFILESTORAGE.uploadFile = ({ stream, filename, uploadPath }) => {
|
|
64
66
|
const id = uuid()
|
|
65
67
|
let size: number = 0
|
|
66
68
|
|
|
67
|
-
// Read content from the file
|
|
68
|
-
const fileContent = fs.readFileSync(filename)
|
|
69
|
-
|
|
70
69
|
return new Promise<{ id: string; path: string; size: number }>((resolve, reject) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
stream
|
|
71
|
+
.pipe(
|
|
72
|
+
(() => {
|
|
73
|
+
var pass = new PassThrough()
|
|
74
|
+
|
|
75
|
+
S3.upload(
|
|
76
|
+
{
|
|
77
|
+
Bucket: SFTPFILESTORAGE.bucketName,
|
|
78
|
+
Key: uploadPath + '/' + filename,
|
|
79
|
+
Body: pass
|
|
80
|
+
},
|
|
81
|
+
(err, data) => (err ? reject(err) : resolve({ id, path: uploadPath, size }))
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return pass
|
|
85
|
+
})()
|
|
86
|
+
)
|
|
87
|
+
.on('error', error => reject(error))
|
|
88
|
+
.on('data', chunk => (size += chunk.length))
|
|
79
89
|
)
|
|
80
90
|
}
|
|
81
91
|
|
|
@@ -4,7 +4,7 @@ import { SFTPFILESTORAGE } from '../sftp-const'
|
|
|
4
4
|
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
|
|
7
|
-
export async function generateFile(params: any
|
|
7
|
+
export async function generateFile(params: any) {
|
|
8
8
|
const { uploadPath, content, title } = params
|
|
9
9
|
const fileDirectory = './uploaded-files'
|
|
10
10
|
|
|
@@ -20,8 +20,11 @@ export async function generateFile(params: any, context: any) {
|
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
if (uploadPath) {
|
|
23
|
-
|
|
23
|
+
const stream = fs.createReadStream(filePath)
|
|
24
|
+
await SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath })
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
fs.rmdirSync(fileDirectory, { recursive: true })
|
|
28
|
+
|
|
26
29
|
return true
|
|
27
30
|
}
|