@things-factory/integration-sftp 5.0.0-alpha.38 → 5.0.0-alpha.39
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-serial-number.js +46 -0
- package/dist-server/controllers/herbalife/apis/create-serial-number.js.map +1 -0
- package/dist-server/controllers/herbalife/apis/create-shipment.js +59 -3
- package/dist-server/controllers/herbalife/apis/create-shipment.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 +15 -62
- 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/sftp-const.js +5 -1
- package/dist-server/sftp-const.js.map +1 -1
- package/dist-server/util/generate-files.js +30 -0
- package/dist-server/util/generate-files.js.map +1 -0
- package/dist-server/util/index.js +1 -1
- package/dist-server/util/index.js.map +1 -1
- package/package.json +7 -7
- package/server/controllers/herbalife/apis/create-serial-number.ts +50 -0
- package/server/controllers/herbalife/apis/create-shipment.ts +68 -3
- package/server/controllers/herbalife/apis/index.ts +1 -0
- package/server/controllers/herbalife/herbalife.ts +18 -71
- package/server/controllers/sftp-api/index.ts +3 -0
- package/server/sftp-const.ts +4 -0
- package/server/util/generate-files.ts +33 -0
- package/server/util/index.ts +1 -1
- package/server/util/generate-file.ts +0 -30
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSerialNumber = void 0;
|
|
4
|
+
const sftp_const_1 = require("../../../sftp-const");
|
|
5
|
+
function createSerialNumber() {
|
|
6
|
+
return {
|
|
7
|
+
method: 'post',
|
|
8
|
+
path: '{folderPath}/{folderType}/sn/data',
|
|
9
|
+
denormalize(req) {
|
|
10
|
+
let { releaseGood, inventoryItems, sftp } = req;
|
|
11
|
+
let { folderPath, platform } = sftp;
|
|
12
|
+
const folderType = sftp.isDevelopment ? `dev` : `prd`;
|
|
13
|
+
const backupPath = `${sftp_const_1.BACKUPPATH}${platform}/${folderType}`;
|
|
14
|
+
let responseFilePattern = JSON.parse(sftp.responseFilePattern);
|
|
15
|
+
const { snSuffix, fileExtension, snRunningNumberDigit, snSequence } = responseFilePattern;
|
|
16
|
+
let newSeq = parseFloat(snSequence) + 1;
|
|
17
|
+
let newSequence = newSeq.toString().padStart(snRunningNumberDigit, '0');
|
|
18
|
+
let newResponseFilePattern = JSON.stringify(Object.assign(Object.assign({}, responseFilePattern), { snSequence: newSeq.toString() }));
|
|
19
|
+
sftp = Object.assign(Object.assign({}, sftp), { responseFilePattern: newResponseFilePattern });
|
|
20
|
+
const today = new Date();
|
|
21
|
+
const year = today.getFullYear().toString();
|
|
22
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0');
|
|
23
|
+
const day = today.getDate().toString().padStart(2, '0');
|
|
24
|
+
const newDate = day + month + year;
|
|
25
|
+
let title = snSuffix ? snSuffix : ``;
|
|
26
|
+
title += `_` + newDate;
|
|
27
|
+
title += `_` + newSequence;
|
|
28
|
+
title += fileExtension ? `.` + fileExtension : ``;
|
|
29
|
+
let content = '';
|
|
30
|
+
const orderNo = releaseGood.refNo;
|
|
31
|
+
for (let i = 0; i < inventoryItems.length; i++) {
|
|
32
|
+
let serialNumber = inventoryItems[i].serialNumber;
|
|
33
|
+
content += orderNo + '|' + serialNumber + '\n';
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
resource: { folderPath, folderType },
|
|
37
|
+
payload: { title, content, sftp, backupPath }
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
normalize(res) {
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.createSerialNumber = createSerialNumber;
|
|
46
|
+
//# sourceMappingURL=create-serial-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-serial-number.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/create-serial-number.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD,SAAgB,kBAAkB;IAChC,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,mCAAmC;QACzC,WAAW,CAAC,GAAG;YACb,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;YAC/C,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAA;YACnC,MAAM,UAAU,GAAW,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;YAC7D,MAAM,UAAU,GAAW,GAAG,uBAAU,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAA;YAEnE,IAAI,mBAAmB,GAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;YACnE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAA;YACzF,IAAI,MAAM,GAAW,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;YAC/C,IAAI,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAA;YACvE,IAAI,sBAAsB,GAAW,IAAI,CAAC,SAAS,iCAC9C,mBAAmB,KACtB,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,IAC7B,CAAA;YACF,IAAI,mCAAQ,IAAI,KAAE,mBAAmB,EAAE,sBAAsB,GAAE,CAAA;YAE/D,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;YACxB,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAA;YAC3C,MAAM,KAAK,G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|
3
3
|
exports.createShipment = void 0;
|
|
4
|
+
const sftp_const_1 = require("../../../sftp-const");
|
|
4
5
|
function createShipment() {
|
|
5
6
|
return {
|
|
6
7
|
method: 'post',
|
|
7
8
|
path: '{folderPath}/{folderType}/oc/data',
|
|
8
9
|
denormalize(req) {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
let { releaseGood, orderInventories, sftp } = req;
|
|
11
|
+
let { folderPath, platform } = sftp;
|
|
11
12
|
const folderType = sftp.isDevelopment ? `dev` : `prd`;
|
|
13
|
+
const backupPath = `${sftp_const_1.BACKUPPATH}${platform}/${folderType}`;
|
|
14
|
+
let responseFilePattern = JSON.parse(sftp.responseFilePattern);
|
|
15
|
+
const { suffix, fileExtension, runningNumberDigit, sequence } = responseFilePattern;
|
|
16
|
+
let newSeq = parseFloat(sequence) + 1;
|
|
17
|
+
let newSequence = newSeq.toString().padStart(runningNumberDigit, '0');
|
|
18
|
+
let newResponseFilePattern = JSON.stringify(Object.assign(Object.assign({}, responseFilePattern), { sequence: newSeq.toString() }));
|
|
19
|
+
sftp = Object.assign(Object.assign({}, sftp), { responseFilePattern: newResponseFilePattern });
|
|
20
|
+
const warehouseNumber = releaseGood.refNo2;
|
|
21
|
+
let title = suffix ? suffix : ``;
|
|
22
|
+
title += newSequence;
|
|
23
|
+
title += warehouseNumber ? `_` + warehouseNumber : ``;
|
|
24
|
+
title += fileExtension ? `.` + fileExtension : ``;
|
|
25
|
+
const orderNoColumn = 15;
|
|
26
|
+
const shipmentColumn = 27;
|
|
27
|
+
const trackingNoColumn = 20;
|
|
28
|
+
const refNoLength = releaseGood.refNo.length;
|
|
29
|
+
let content = `1710` + releaseGood.refNo;
|
|
30
|
+
let spaceNeeded = orderNoColumn - refNoLength;
|
|
31
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
32
|
+
content += ` `;
|
|
33
|
+
}
|
|
34
|
+
content += warehouseNumber;
|
|
35
|
+
content += `001000001`;
|
|
36
|
+
for (let i = 0; i < shipmentColumn; i++) {
|
|
37
|
+
content += ` `;
|
|
38
|
+
}
|
|
39
|
+
content += `000000 `;
|
|
40
|
+
for (let i = 0; i < trackingNoColumn; i++) {
|
|
41
|
+
content += ` `;
|
|
42
|
+
}
|
|
43
|
+
content += `000000000000 `;
|
|
44
|
+
const today = new Date();
|
|
45
|
+
const year = today.getFullYear().toString();
|
|
46
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0');
|
|
47
|
+
const day = today.getDate().toString().padStart(2, '0');
|
|
48
|
+
const newDate = year + month + day;
|
|
49
|
+
content += newDate + '\n';
|
|
50
|
+
for (let i = 0; i < orderInventories.length; i++) {
|
|
51
|
+
const orderInventory = orderInventories[i];
|
|
52
|
+
let sku = orderInventory.product.brandSku;
|
|
53
|
+
content += `1810` + releaseGood.refNo;
|
|
54
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
55
|
+
content += ` `;
|
|
56
|
+
}
|
|
57
|
+
const idx = (i + 1).toString().padStart(2, '0');
|
|
58
|
+
const productCode = sku.substring(0, 4);
|
|
59
|
+
content += idx + `000000` + productCode;
|
|
60
|
+
let productCodeSpaceNeeded = 7 - productCode.length;
|
|
61
|
+
for (let i = 0; i < productCodeSpaceNeeded; i++) {
|
|
62
|
+
content += ` `;
|
|
63
|
+
}
|
|
64
|
+
const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0');
|
|
65
|
+
const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0');
|
|
66
|
+
content += orderedQty + pickedQty + '\n';
|
|
67
|
+
}
|
|
12
68
|
return {
|
|
13
69
|
resource: { folderPath, folderType },
|
|
14
|
-
payload: {
|
|
70
|
+
payload: { title, content, sftp, backupPath }
|
|
15
71
|
};
|
|
16
72
|
},
|
|
17
73
|
normalize(res) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-shipment.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/create-shipment.ts"],"names":[],"mappings":";;;AAAA,SAAgB,cAAc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,CAAA;gBACxE,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;gBACtE,OAAO,IAAI,UAAU,GAAG,SAAS,GAAG,IAAI,CAAA;aACzC;YAED,OAAO;gBACL,QAAQ,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE;gBACpC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE;aAC9C,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AAjFD,wCAiFC"}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./echo"), exports);
|
|
18
18
|
__exportStar(require("./get-outbound-order"), exports);
|
|
19
19
|
__exportStar(require("./create-shipment"), exports);
|
|
20
|
+
__exportStar(require("./create-serial-number"), exports);
|
|
20
21
|
//# 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;AACpC,oDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,uDAAoC;AACpC,oDAAiC;AACjC,yDAAsC"}
|
|
@@ -4,7 +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
|
|
7
|
+
const generate_files_1 = require("../../util/generate-files");
|
|
8
8
|
const debug = require('debug')('things-factory:integration-sftp:herbalife');
|
|
9
9
|
class Herbalife {
|
|
10
10
|
constructor() { }
|
|
@@ -17,69 +17,22 @@ class Herbalife {
|
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
19
|
async post(path, data = {}) {
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 += ` `;
|
|
20
|
+
const { title, content, sftp, backupPath } = data;
|
|
21
|
+
let params = [
|
|
22
|
+
{
|
|
23
|
+
title,
|
|
24
|
+
uploadPath: path,
|
|
25
|
+
content
|
|
72
26
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
27
|
+
];
|
|
28
|
+
if (backupPath) {
|
|
29
|
+
params.push({
|
|
30
|
+
title,
|
|
31
|
+
uploadPath: backupPath,
|
|
32
|
+
content
|
|
33
|
+
});
|
|
76
34
|
}
|
|
77
|
-
|
|
78
|
-
title,
|
|
79
|
-
uploadPath: path,
|
|
80
|
-
content
|
|
81
|
-
};
|
|
82
|
-
await (0, generate_file_1.generateFile)(params);
|
|
35
|
+
await (0, generate_files_1.generateFiles)(params);
|
|
83
36
|
return sftp;
|
|
84
37
|
}
|
|
85
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"herbalife.js","sourceRoot":"","sources":["../../../server/controllers/herbalife/herbalife.ts"],"names":[],"mappings":";;;AAAA,yBAAsB;AAEtB,mCAA+B;AAG/B,iDAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"herbalife.js","sourceRoot":"","sources":["../../../server/controllers/herbalife/herbalife.ts"],"names":[],"mappings":";;;AAAA,yBAAsB;AAEtB,mCAA+B;AAG/B,iDAAkD;AAClD,8DAAyD;AAEzD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2CAA2C,CAAC,CAAA;AAI3E,MAAa,SAAS;IACpB,gBAAe,CAAC;IAEhB,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAAY,EAAE;QACpC,MAAM,UAAU,GAAQ,MAAM,4BAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACrE,MAAM,IAAI,GAAQ,IAAA,eAAM,EAAC,UAAU,EAAE;YACnC,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QACF,MAAM,MAAM,qBAAa,IAAI,CAAE,CAAA;QAC/B,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,OAAY,EAAE;QACrC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GACxC,IAAI,CAAA;QAEN,IAAI,MAAM,GAAU;YAClB;gBACE,KAAK;gBACL,UAAU,EAAE,IAAI;gBAChB,OAAO;aACR;SACF,CAAA;QAED,IAAI,UAAU,EAAE;YACd,MAAM,CAAC,IAAI,CAAC;gBACV,KAAK;gBACL,UAAU,EAAE,UAAU;gBACtB,OAAO;aACR,CAAC,CAAA;SACH;QACD,MAAM,IAAA,8BAAa,EAAC,MAAM,CAAC,CAAA;QAE3B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAnCD,8BAmCC"}
|
|
@@ -33,6 +33,7 @@ class SftpAPI {
|
|
|
33
33
|
static echo(sftp, req) { }
|
|
34
34
|
static getOutboundOrder(sftp, req) { }
|
|
35
35
|
static createShipment(sftp, req) { }
|
|
36
|
+
static createSerialNumber(sftp, req) { }
|
|
36
37
|
}
|
|
37
38
|
SftpAPI.platforms = {};
|
|
38
39
|
__decorate([
|
|
@@ -53,5 +54,11 @@ __decorate([
|
|
|
53
54
|
__metadata("design:paramtypes", [Object, Object]),
|
|
54
55
|
__metadata("design:returntype", Object)
|
|
55
56
|
], SftpAPI, "createShipment", null);
|
|
57
|
+
__decorate([
|
|
58
|
+
decorators_1.api,
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
61
|
+
__metadata("design:returntype", Object)
|
|
62
|
+
], SftpAPI, "createSerialNumber", null);
|
|
56
63
|
exports.SftpAPI = SftpAPI;
|
|
57
64
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sftp-api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;AAEvC,2CAAoC;AACpC,6CAAkC;AAElC,MAAa,OAAO;IAGlB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI;QACxC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YACxB,MAAM;YACN,IAAI;SACL,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAI;QACrB,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QACrB,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,cAAI,CAAC,CAAA;QACtC,OAAO,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;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sftp-api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;AAEvC,2CAAoC;AACpC,6CAAkC;AAElC,MAAa,OAAO;IAGlB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI;QACxC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG;YACxB,MAAM;YACN,IAAI;SACL,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAI;QACrB,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QACrB,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,cAAI,CAAC,CAAA;QACtC,OAAO,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;IAGxC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,GAAG,IAAQ,CAAC;;AA/BrC,iBAAS,GAAG,EAAE,CAAA;AAsBrB;IADC,gBAAG;;;;yBAC0B;AAG9B;IADC,gBAAG;;;;qCACsC;AAG1C;IADC,gBAAG;;;;mCACoC;AAGxC;IADC,gBAAG;;;;uCACwC;AAhC9C,0BAiCC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.COMPLETEFAILEDDATAPATH = exports.COMPLETESUCCESSDATAPATH = exports.COMPLETEDATAPATH = exports.FAILEDDATAPATH = exports.SUCCESSDATAPATH = exports.SUBMITDATAPATH = exports.SFTPFILESTORAGE = void 0;
|
|
3
|
+
exports.BACKUPPATH = exports.SNFAILEDDATAPATH = exports.SNSUCCESSDATAPATH = exports.SNSUBMITDATAPATH = exports.COMPLETEFAILEDDATAPATH = exports.COMPLETESUCCESSDATAPATH = exports.COMPLETEDATAPATH = exports.FAILEDDATAPATH = exports.SUCCESSDATAPATH = exports.SUBMITDATAPATH = exports.SFTPFILESTORAGE = void 0;
|
|
4
4
|
const env_1 = require("@things-factory/env");
|
|
5
5
|
exports.SFTPFILESTORAGE = env_1.config.get('sftpFileStorage');
|
|
6
6
|
exports.SUBMITDATAPATH = '/sob/data';
|
|
@@ -9,4 +9,8 @@ exports.FAILEDDATAPATH = '/sob/failed';
|
|
|
9
9
|
exports.COMPLETEDATAPATH = '/oc/data';
|
|
10
10
|
exports.COMPLETESUCCESSDATAPATH = '/oc/success';
|
|
11
11
|
exports.COMPLETEFAILEDDATAPATH = '/oc/failed';
|
|
12
|
+
exports.SNSUBMITDATAPATH = '/sn/data';
|
|
13
|
+
exports.SNSUCCESSDATAPATH = '/sn/success';
|
|
14
|
+
exports.SNFAILEDDATAPATH = '/sn/failed';
|
|
15
|
+
exports.BACKUPPATH = 'hatiosea/';
|
|
12
16
|
//# sourceMappingURL=sftp-const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-const.js","sourceRoot":"","sources":["../server/sftp-const.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAEjC,QAAA,eAAe,GAAQ,YAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AACpD,QAAA,cAAc,GAAW,WAAW,CAAA;AACpC,QAAA,eAAe,GAAW,cAAc,CAAA;AACxC,QAAA,cAAc,GAAW,aAAa,CAAA;AACtC,QAAA,gBAAgB,GAAW,UAAU,CAAA;AACrC,QAAA,uBAAuB,GAAW,aAAa,CAAA;AAC/C,QAAA,sBAAsB,GAAW,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"sftp-const.js","sourceRoot":"","sources":["../server/sftp-const.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAEjC,QAAA,eAAe,GAAQ,YAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;AACpD,QAAA,cAAc,GAAW,WAAW,CAAA;AACpC,QAAA,eAAe,GAAW,cAAc,CAAA;AACxC,QAAA,cAAc,GAAW,aAAa,CAAA;AACtC,QAAA,gBAAgB,GAAW,UAAU,CAAA;AACrC,QAAA,uBAAuB,GAAW,aAAa,CAAA;AAC/C,QAAA,sBAAsB,GAAW,YAAY,CAAA;AAC7C,QAAA,gBAAgB,GAAW,UAAU,CAAA;AACrC,QAAA,iBAAiB,GAAW,aAAa,CAAA;AACzC,QAAA,gBAAgB,GAAW,YAAY,CAAA;AACvC,QAAA,UAAU,GAAW,WAAW,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateFiles = void 0;
|
|
4
|
+
require("../sftp-s3");
|
|
5
|
+
const sftp_const_1 = require("../sftp-const");
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
async function generateFiles(params) {
|
|
8
|
+
const fileDirectory = './uploaded-files';
|
|
9
|
+
for (let i = 0; i < params.length; i++) {
|
|
10
|
+
let param = params[i];
|
|
11
|
+
const { uploadPath, content, title } = param;
|
|
12
|
+
if (!fs.existsSync(fileDirectory)) {
|
|
13
|
+
fs.mkdirSync(fileDirectory);
|
|
14
|
+
}
|
|
15
|
+
const filePath = fileDirectory + '/' + title;
|
|
16
|
+
fs.writeFile(filePath, content, function (err) {
|
|
17
|
+
if (err)
|
|
18
|
+
throw err;
|
|
19
|
+
console.log('File is created successfully.');
|
|
20
|
+
});
|
|
21
|
+
if (uploadPath) {
|
|
22
|
+
const stream = fs.createReadStream(filePath);
|
|
23
|
+
await sftp_const_1.SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
fs.rm(fileDirectory, { recursive: true });
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
exports.generateFiles = generateFiles;
|
|
30
|
+
//# sourceMappingURL=generate-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-files.js","sourceRoot":"","sources":["../../server/util/generate-files.ts"],"names":[],"mappings":";;;AAAA,sBAAmB;AAEnB,8CAA+C;AAE/C,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjB,KAAK,UAAU,aAAa,CAAC,MAAa;IAC/C,MAAM,aAAa,GAAG,kBAAkB,CAAA;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,IAAI,KAAK,GAAQ,MAAM,CAAC,CAAC,CAAC,CAAA;QAC1B,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAA;QAE5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YACjC,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;SAC5B;QAED,MAAM,QAAQ,GAAG,aAAa,GAAG,GAAG,GAAG,KAAK,CAAA;QAE5C,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG;YAC3C,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAA;YAClB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;QAC9C,CAAC,CAAC,CAAA;QAEF,IAAI,UAAU,EAAE;YACd,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;YAC5C,MAAM,4BAAe,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAA;SAC1E;KACF;IAED,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAEzC,OAAO,IAAI,CAAA;AACb,CAAC;AA1BD,sCA0BC"}
|
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./get-permitted-directories"), exports);
|
|
18
|
-
__exportStar(require("./generate-
|
|
18
|
+
__exportStar(require("./generate-files"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA2C;AAC3C,mDAAgC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-sftp",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.39",
|
|
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": "^5.0.0-alpha.
|
|
28
|
-
"@things-factory/biz-base": "^5.0.0-alpha.
|
|
29
|
-
"@things-factory/env": "^5.0.0-alpha.
|
|
30
|
-
"@things-factory/integration-fulfillment": "^5.0.0-alpha.
|
|
31
|
-
"@things-factory/shell": "^5.0.0-alpha.
|
|
27
|
+
"@things-factory/auth-base": "^5.0.0-alpha.39",
|
|
28
|
+
"@things-factory/biz-base": "^5.0.0-alpha.39",
|
|
29
|
+
"@things-factory/env": "^5.0.0-alpha.39",
|
|
30
|
+
"@things-factory/integration-fulfillment": "^5.0.0-alpha.39",
|
|
31
|
+
"@things-factory/shell": "^5.0.0-alpha.39",
|
|
32
32
|
"aws-sdk": "^2.960.0",
|
|
33
33
|
"xml-js": "^1.6.11"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "23e58562a4724f157c3bc492cdedb7e32efee6a1"
|
|
36
36
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BACKUPPATH } from '../../../sftp-const'
|
|
2
|
+
|
|
3
|
+
export function createSerialNumber() {
|
|
4
|
+
return {
|
|
5
|
+
method: 'post',
|
|
6
|
+
path: '{folderPath}/{folderType}/sn/data',
|
|
7
|
+
denormalize(req) {
|
|
8
|
+
let { releaseGood, inventoryItems, sftp } = req
|
|
9
|
+
let { folderPath, platform } = sftp
|
|
10
|
+
const folderType: string = sftp.isDevelopment ? `dev` : `prd`
|
|
11
|
+
const backupPath: string = `${BACKUPPATH}${platform}/${folderType}`
|
|
12
|
+
|
|
13
|
+
let responseFilePattern: any = JSON.parse(sftp.responseFilePattern)
|
|
14
|
+
const { snSuffix, fileExtension, snRunningNumberDigit, snSequence } = responseFilePattern
|
|
15
|
+
let newSeq: number = parseFloat(snSequence) + 1
|
|
16
|
+
let newSequence = newSeq.toString().padStart(snRunningNumberDigit, '0')
|
|
17
|
+
let newResponseFilePattern: string = JSON.stringify({
|
|
18
|
+
...responseFilePattern,
|
|
19
|
+
snSequence: newSeq.toString()
|
|
20
|
+
})
|
|
21
|
+
sftp = { ...sftp, responseFilePattern: newResponseFilePattern }
|
|
22
|
+
|
|
23
|
+
const today = new Date()
|
|
24
|
+
const year = today.getFullYear().toString()
|
|
25
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0')
|
|
26
|
+
const day = today.getDate().toString().padStart(2, '0')
|
|
27
|
+
const newDate = day + month + year
|
|
28
|
+
|
|
29
|
+
let title: string = snSuffix ? snSuffix : ``
|
|
30
|
+
title += `_` + newDate
|
|
31
|
+
title += `_` + newSequence
|
|
32
|
+
title += fileExtension ? `.` + fileExtension : ``
|
|
33
|
+
|
|
34
|
+
let content: string = ''
|
|
35
|
+
const orderNo: string = releaseGood.refNo
|
|
36
|
+
for (let i = 0; i < inventoryItems.length; i++) {
|
|
37
|
+
let serialNumber: string = inventoryItems[i].serialNumber
|
|
38
|
+
content += orderNo + '|' + serialNumber + '\n'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
resource: { folderPath, folderType },
|
|
43
|
+
payload: { title, content, sftp, backupPath }
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
normalize(res) {
|
|
47
|
+
return res
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,15 +1,80 @@
|
|
|
1
|
+
import { BACKUPPATH } from '../../../sftp-const'
|
|
2
|
+
|
|
1
3
|
export function createShipment() {
|
|
2
4
|
return {
|
|
3
5
|
method: 'post',
|
|
4
6
|
path: '{folderPath}/{folderType}/oc/data',
|
|
5
7
|
denormalize(req) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
let { releaseGood, orderInventories, sftp } = req
|
|
9
|
+
let { folderPath, platform } = sftp
|
|
8
10
|
const folderType: string = sftp.isDevelopment ? `dev` : `prd`
|
|
11
|
+
const backupPath: string = `${BACKUPPATH}${platform}/${folderType}`
|
|
12
|
+
|
|
13
|
+
let responseFilePattern: any = JSON.parse(sftp.responseFilePattern)
|
|
14
|
+
const { suffix, fileExtension, runningNumberDigit, sequence } = responseFilePattern
|
|
15
|
+
let newSeq: number = parseFloat(sequence) + 1
|
|
16
|
+
let newSequence = newSeq.toString().padStart(runningNumberDigit, '0')
|
|
17
|
+
let newResponseFilePattern: string = JSON.stringify({
|
|
18
|
+
...responseFilePattern,
|
|
19
|
+
sequence: newSeq.toString()
|
|
20
|
+
})
|
|
21
|
+
sftp = { ...sftp, responseFilePattern: newResponseFilePattern }
|
|
22
|
+
|
|
23
|
+
const warehouseNumber: string = releaseGood.refNo2
|
|
24
|
+
let title: string = suffix ? suffix : ``
|
|
25
|
+
title += newSequence
|
|
26
|
+
title += warehouseNumber ? `_` + warehouseNumber : ``
|
|
27
|
+
title += fileExtension ? `.` + fileExtension : ``
|
|
28
|
+
|
|
29
|
+
const orderNoColumn: number = 15
|
|
30
|
+
const shipmentColumn: number = 27
|
|
31
|
+
const trackingNoColumn: number = 20
|
|
32
|
+
|
|
33
|
+
const refNoLength: number = releaseGood.refNo.length
|
|
34
|
+
let content: string = `1710` + releaseGood.refNo
|
|
35
|
+
let spaceNeeded: number = orderNoColumn - refNoLength
|
|
36
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
37
|
+
content += ` `
|
|
38
|
+
}
|
|
39
|
+
content += warehouseNumber
|
|
40
|
+
content += `001000001`
|
|
41
|
+
for (let i = 0; i < shipmentColumn; i++) {
|
|
42
|
+
content += ` `
|
|
43
|
+
}
|
|
44
|
+
content += `000000 `
|
|
45
|
+
for (let i = 0; i < trackingNoColumn; i++) {
|
|
46
|
+
content += ` `
|
|
47
|
+
}
|
|
48
|
+
content += `000000000000 `
|
|
49
|
+
const today = new Date()
|
|
50
|
+
const year = today.getFullYear().toString()
|
|
51
|
+
const month = (today.getMonth() + 1).toString().padStart(2, '0')
|
|
52
|
+
const day = today.getDate().toString().padStart(2, '0')
|
|
53
|
+
const newDate = year + month + day
|
|
54
|
+
content += newDate + '\n'
|
|
55
|
+
|
|
56
|
+
for (let i = 0; i < orderInventories.length; i++) {
|
|
57
|
+
const orderInventory: any = orderInventories[i]
|
|
58
|
+
let sku: string = orderInventory.product.brandSku
|
|
59
|
+
content += `1810` + releaseGood.refNo
|
|
60
|
+
for (let i = 0; i < spaceNeeded; i++) {
|
|
61
|
+
content += ` `
|
|
62
|
+
}
|
|
63
|
+
const idx = (i + 1).toString().padStart(2, '0')
|
|
64
|
+
const productCode: string = sku.substring(0, 4)
|
|
65
|
+
content += idx + `000000` + productCode
|
|
66
|
+
let productCodeSpaceNeeded = 7 - productCode.length
|
|
67
|
+
for (let i = 0; i < productCodeSpaceNeeded; i++) {
|
|
68
|
+
content += ` `
|
|
69
|
+
}
|
|
70
|
+
const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0')
|
|
71
|
+
const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0')
|
|
72
|
+
content += orderedQty + pickedQty + '\n'
|
|
73
|
+
}
|
|
9
74
|
|
|
10
75
|
return {
|
|
11
76
|
resource: { folderPath, folderType },
|
|
12
|
-
payload: {
|
|
77
|
+
payload: { title, content, sftp, backupPath }
|
|
13
78
|
}
|
|
14
79
|
},
|
|
15
80
|
normalize(res) {
|
|
@@ -4,7 +4,7 @@ import { xml2js } from 'xml-js'
|
|
|
4
4
|
|
|
5
5
|
import { Sftp } from '../../service'
|
|
6
6
|
import { SFTPFILESTORAGE } from '../../sftp-const'
|
|
7
|
-
import {
|
|
7
|
+
import { generateFiles } from '../../util/generate-files'
|
|
8
8
|
|
|
9
9
|
const debug = require('debug')('things-factory:integration-sftp:herbalife')
|
|
10
10
|
|
|
@@ -23,78 +23,25 @@ export class Herbalife {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async post(path: string, data: any = {}) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 += ` `
|
|
26
|
+
const { title, content, sftp, backupPath }: { title: string; content: string; sftp: Sftp; backupPath: string } =
|
|
27
|
+
data
|
|
28
|
+
|
|
29
|
+
let params: any[] = [
|
|
30
|
+
{
|
|
31
|
+
title,
|
|
32
|
+
uploadPath: path,
|
|
33
|
+
content
|
|
79
34
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
if (backupPath) {
|
|
38
|
+
params.push({
|
|
39
|
+
title,
|
|
40
|
+
uploadPath: backupPath,
|
|
41
|
+
content
|
|
42
|
+
})
|
|
96
43
|
}
|
|
97
|
-
await
|
|
44
|
+
await generateFiles(params)
|
|
98
45
|
|
|
99
46
|
return sftp
|
|
100
47
|
}
|
package/server/sftp-const.ts
CHANGED
|
@@ -7,3 +7,7 @@ export var FAILEDDATAPATH: string = '/sob/failed'
|
|
|
7
7
|
export var COMPLETEDATAPATH: string = '/oc/data'
|
|
8
8
|
export var COMPLETESUCCESSDATAPATH: string = '/oc/success'
|
|
9
9
|
export var COMPLETEFAILEDDATAPATH: string = '/oc/failed'
|
|
10
|
+
export var SNSUBMITDATAPATH: string = '/sn/data'
|
|
11
|
+
export var SNSUCCESSDATAPATH: string = '/sn/success'
|
|
12
|
+
export var SNFAILEDDATAPATH: string = '/sn/failed'
|
|
13
|
+
export var BACKUPPATH: string = 'hatiosea/'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import '../sftp-s3'
|
|
2
|
+
|
|
3
|
+
import { SFTPFILESTORAGE } from '../sftp-const'
|
|
4
|
+
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
|
|
7
|
+
export async function generateFiles(params: any[]) {
|
|
8
|
+
const fileDirectory = './uploaded-files'
|
|
9
|
+
for (let i = 0; i < params.length; i++) {
|
|
10
|
+
let param: any = params[i]
|
|
11
|
+
const { uploadPath, content, title } = param
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(fileDirectory)) {
|
|
14
|
+
fs.mkdirSync(fileDirectory)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const filePath = fileDirectory + '/' + title
|
|
18
|
+
|
|
19
|
+
fs.writeFile(filePath, content, function (err) {
|
|
20
|
+
if (err) throw err
|
|
21
|
+
console.log('File is created successfully.')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (uploadPath) {
|
|
25
|
+
const stream = fs.createReadStream(filePath)
|
|
26
|
+
await SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath })
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fs.rm(fileDirectory, { recursive: true })
|
|
31
|
+
|
|
32
|
+
return true
|
|
33
|
+
}
|
package/server/util/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './get-permitted-directories'
|
|
2
|
-
export * from './generate-
|
|
2
|
+
export * from './generate-files'
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import '../sftp-s3'
|
|
2
|
-
|
|
3
|
-
import { SFTPFILESTORAGE } from '../sftp-const'
|
|
4
|
-
|
|
5
|
-
const fs = require('fs')
|
|
6
|
-
|
|
7
|
-
export async function generateFile(params: any) {
|
|
8
|
-
const { uploadPath, content, title } = params
|
|
9
|
-
const fileDirectory = './uploaded-files'
|
|
10
|
-
|
|
11
|
-
if (!fs.existsSync(fileDirectory)) {
|
|
12
|
-
fs.mkdirSync(fileDirectory)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const filePath = fileDirectory + '/' + title
|
|
16
|
-
|
|
17
|
-
fs.writeFile(filePath, content, function (err) {
|
|
18
|
-
if (err) throw err
|
|
19
|
-
console.log('File is created successfully.')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
if (uploadPath) {
|
|
23
|
-
const stream = fs.createReadStream(filePath)
|
|
24
|
-
await SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath })
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fs.rmdirSync(fileDirectory, { recursive: true })
|
|
28
|
-
|
|
29
|
-
return true
|
|
30
|
-
}
|