@things-factory/integration-sftp 4.3.14 → 4.3.15
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.
|
@@ -81,63 +81,72 @@ let SftpMutation = class SftpMutation {
|
|
|
81
81
|
return true;
|
|
82
82
|
}
|
|
83
83
|
async syncSftpOrders(customerDomainId, context) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
84
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
85
|
+
var e_1, _a;
|
|
86
|
+
const customerDomain = await tx.getRepository(shell_1.Domain).findOne(customerDomainId);
|
|
87
|
+
const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
|
|
88
|
+
where: { domain: customerDomain }
|
|
89
|
+
});
|
|
90
|
+
const customerBizplaceId = customerBizplace.id;
|
|
91
|
+
const sftpUsers = await tx.getRepository(sftp_1.Sftp).find({
|
|
92
|
+
where: { domain: customerDomain, status: 'ACTIVE' },
|
|
93
|
+
relations: ['fulfillmentCenter']
|
|
94
|
+
});
|
|
95
|
+
for (var i = 0; i < sftpUsers.length; i++) {
|
|
96
|
+
const sftpUser = sftpUsers[i];
|
|
97
|
+
const fulfilmentCenter = sftpUser.fulfillmentCenter;
|
|
98
|
+
const isDevelopment = sftpUser.isDevelopment;
|
|
99
|
+
const folderPath = sftpUser.folderPath;
|
|
100
|
+
const folderType = isDevelopment ? 'dev' : 'prd';
|
|
101
|
+
let initialDataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
|
|
102
|
+
const results = await (0, util_1.getPermittedDirectories)({ path: initialDataPath }, context);
|
|
103
|
+
const filesDirectories = results.filter(result => result.Size > 0);
|
|
104
|
+
try {
|
|
105
|
+
for (var filesDirectories_1 = (e_1 = void 0, __asyncValues(filesDirectories)), filesDirectories_1_1; filesDirectories_1_1 = await filesDirectories_1.next(), !filesDirectories_1_1.done;) {
|
|
106
|
+
let fileDirectory = filesDirectories_1_1.value;
|
|
107
|
+
let dataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
|
|
108
|
+
let successPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUCCESSDATAPATH}/`;
|
|
109
|
+
let failedPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.FAILEDDATAPATH}/`;
|
|
110
|
+
const fileKey = fileDirectory.Key;
|
|
111
|
+
const lastSlashIdx = fileKey.lastIndexOf('/');
|
|
112
|
+
const fileString = fileKey.substring(lastSlashIdx + 1, fileKey.length);
|
|
113
|
+
try {
|
|
114
|
+
const sftp = sftpUser;
|
|
115
|
+
let result = await controllers_1.SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString });
|
|
116
|
+
let isAccept = result.isAccept;
|
|
117
|
+
if (isAccept) {
|
|
118
|
+
delete result.isAccept;
|
|
119
|
+
if (result) {
|
|
120
|
+
let { items: releaseOrders } = await integration_fulfillment_1.FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
|
|
121
|
+
customerBizplaceId,
|
|
122
|
+
refNo: result.refNo
|
|
123
|
+
});
|
|
124
|
+
if (releaseOrders) {
|
|
125
|
+
result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1);
|
|
126
|
+
}
|
|
127
|
+
result.requiredDraft = false;
|
|
128
|
+
const releaseOrder = await integration_fulfillment_1.FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
129
|
+
customerBizplaceId,
|
|
130
|
+
releaseOrder: result
|
|
131
|
+
});
|
|
132
|
+
if (releaseOrder) {
|
|
133
|
+
let movePaths = {
|
|
134
|
+
source: (dataPath += fileString),
|
|
135
|
+
destination: (successPath += fileString)
|
|
136
|
+
};
|
|
137
|
+
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
138
|
+
}
|
|
137
139
|
}
|
|
138
140
|
}
|
|
141
|
+
else {
|
|
142
|
+
let movePaths = {
|
|
143
|
+
source: (dataPath += fileString),
|
|
144
|
+
destination: (failedPath += fileString)
|
|
145
|
+
};
|
|
146
|
+
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
147
|
+
}
|
|
139
148
|
}
|
|
140
|
-
|
|
149
|
+
catch (e) {
|
|
141
150
|
let movePaths = {
|
|
142
151
|
source: (dataPath += fileString),
|
|
143
152
|
destination: (failedPath += fileString)
|
|
@@ -145,23 +154,16 @@ let SftpMutation = class SftpMutation {
|
|
|
145
154
|
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
|
-
catch (e) {
|
|
149
|
-
let movePaths = {
|
|
150
|
-
source: (dataPath += fileString),
|
|
151
|
-
destination: (failedPath += fileString)
|
|
152
|
-
};
|
|
153
|
-
await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
|
|
154
|
-
}
|
|
155
157
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
159
|
+
finally {
|
|
160
|
+
try {
|
|
161
|
+
if (filesDirectories_1_1 && !filesDirectories_1_1.done && (_a = filesDirectories_1.return)) await _a.call(filesDirectories_1);
|
|
162
|
+
}
|
|
163
|
+
finally { if (e_1) throw e_1.error; }
|
|
161
164
|
}
|
|
162
|
-
finally { if (e_1) throw e_1.error; }
|
|
163
165
|
}
|
|
164
|
-
}
|
|
166
|
+
});
|
|
165
167
|
return true;
|
|
166
168
|
}
|
|
167
169
|
};
|
|
@@ -212,7 +214,6 @@ __decorate([
|
|
|
212
214
|
__metadata("design:returntype", Promise)
|
|
213
215
|
], SftpMutation.prototype, "deleteSftps", null);
|
|
214
216
|
__decorate([
|
|
215
|
-
(0, type_graphql_1.Directive)('@transaction'),
|
|
216
217
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To sync all orders from sftp' }),
|
|
217
218
|
__param(0, (0, type_graphql_1.Arg)('customerDomainId', type => String)),
|
|
218
219
|
__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sftp-mutation.js","sourceRoot":"","sources":["../../../server/service/sftp/sftp-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAsB;AAEtB,+CAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"sftp-mutation.js","sourceRoot":"","sources":["../../../server/service/sftp/sftp-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAsB;AAEtB,+CAAsE;AACtE,qCAA0D;AAE1D,uDAAmD;AACnD,qFAA2F;AAC3F,iDAA8C;AAE9C,mDAA2C;AAC3C,iDAAmG;AACnG,qCAAoD;AACpD,iCAA6B;AAC7B,2CAAgD;AAGhD,IAAa,YAAY,GAAzB,MAAa,YAAY;IAGvB,KAAK,CAAC,UAAU,CAAc,IAAa,EAAS,OAAY;QAC9D,MAAM,E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AAA,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;AAGD;IADC,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;;;;kDAqFP;AA3LU,YAAY;IADxB,IAAA,uBAAQ,EAAC,WAAI,CAAC;GACF,YAAY,CA4LxB;AA5LY,oCAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-sftp",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.15",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@things-factory/auth-base": "^4.3.14",
|
|
28
28
|
"@things-factory/biz-base": "^4.3.14",
|
|
29
29
|
"@things-factory/env": "^4.3.14",
|
|
30
|
-
"@things-factory/integration-fulfillment": "^4.3.
|
|
30
|
+
"@things-factory/integration-fulfillment": "^4.3.15",
|
|
31
31
|
"@things-factory/shell": "^4.3.14",
|
|
32
32
|
"aws-sdk": "^2.960.0",
|
|
33
33
|
"xml-js": "^1.6.11"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "df335351b9bbb891dc6c4eb81dc9cafecc9c39bb"
|
|
36
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../../sftp-s3'
|
|
2
2
|
|
|
3
3
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
4
|
-
import { In } from 'typeorm'
|
|
4
|
+
import { EntityManager, getConnection, In } from 'typeorm'
|
|
5
5
|
|
|
6
6
|
import { Bizplace } from '@things-factory/biz-base'
|
|
7
7
|
import { FulfillmentAPI, FulFillmentCenter } from '@things-factory/integration-fulfillment'
|
|
@@ -113,91 +113,92 @@ export class SftpMutation {
|
|
|
113
113
|
return true
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
@Directive('@transaction')
|
|
117
116
|
@Mutation(returns => Boolean, { description: 'To sync all orders from sftp' })
|
|
118
117
|
async syncSftpOrders(
|
|
119
118
|
@Arg('customerDomainId', type => String) customerDomainId: string,
|
|
120
119
|
@Ctx() context: any
|
|
121
120
|
): Promise<boolean> {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
121
|
+
await getConnection().transaction(async (tx: EntityManager) => {
|
|
122
|
+
const customerDomain: Domain = await tx.getRepository(Domain).findOne(customerDomainId)
|
|
123
|
+
|
|
124
|
+
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
|
|
125
|
+
where: { domain: customerDomain }
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const customerBizplaceId: string = customerBizplace.id
|
|
129
|
+
|
|
130
|
+
const sftpUsers: Sftp[] = await tx.getRepository(Sftp).find({
|
|
131
|
+
where: { domain: customerDomain, status: 'ACTIVE' },
|
|
132
|
+
relations: ['fulfillmentCenter']
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
for (var i = 0; i < sftpUsers.length; i++) {
|
|
136
|
+
const sftpUser: Sftp = sftpUsers[i]
|
|
137
|
+
|
|
138
|
+
const fulfilmentCenter: FulFillmentCenter = sftpUser.fulfillmentCenter
|
|
139
|
+
const isDevelopment: boolean = sftpUser.isDevelopment
|
|
140
|
+
const folderPath: string = sftpUser.folderPath
|
|
141
|
+
const folderType: string = isDevelopment ? 'dev' : 'prd'
|
|
142
|
+
let initialDataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
|
|
143
|
+
const results: any[] = await getPermittedDirectories({ path: initialDataPath }, context)
|
|
144
|
+
const filesDirectories: any[] = results.filter(result => result.Size > 0)
|
|
145
|
+
|
|
146
|
+
for await (let fileDirectory of filesDirectories) {
|
|
147
|
+
let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
|
|
148
|
+
let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`
|
|
149
|
+
let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`
|
|
150
|
+
const fileKey: string = fileDirectory.Key
|
|
151
|
+
const lastSlashIdx = fileKey.lastIndexOf('/')
|
|
152
|
+
const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)
|
|
153
|
+
try {
|
|
154
|
+
const sftp: any = sftpUser
|
|
155
|
+
let result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })
|
|
156
|
+
let isAccept: boolean = result.isAccept
|
|
157
|
+
|
|
158
|
+
if (isAccept) {
|
|
159
|
+
delete result.isAccept
|
|
160
|
+
if (result) {
|
|
161
|
+
let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
|
|
162
|
+
customerBizplaceId,
|
|
163
|
+
refNo: result.refNo
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
if (releaseOrders) {
|
|
167
|
+
result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1)
|
|
168
|
+
}
|
|
136
169
|
|
|
137
|
-
|
|
138
|
-
const sftpUser: Sftp = sftpUsers[i]
|
|
139
|
-
|
|
140
|
-
const fulfilmentCenter: FulFillmentCenter = sftpUser.fulfillmentCenter
|
|
141
|
-
const isDevelopment: boolean = sftpUser.isDevelopment
|
|
142
|
-
const folderPath: string = sftpUser.folderPath
|
|
143
|
-
const folderType: string = isDevelopment ? 'dev' : 'prd'
|
|
144
|
-
let initialDataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
|
|
145
|
-
const results: any[] = await getPermittedDirectories({ path: initialDataPath }, context)
|
|
146
|
-
const filesDirectories: any[] = results.filter(result => result.Size > 0)
|
|
147
|
-
|
|
148
|
-
for await (let fileDirectory of filesDirectories) {
|
|
149
|
-
let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
|
|
150
|
-
let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`
|
|
151
|
-
let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`
|
|
152
|
-
const fileKey: string = fileDirectory.Key
|
|
153
|
-
const lastSlashIdx = fileKey.lastIndexOf('/')
|
|
154
|
-
const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)
|
|
155
|
-
try {
|
|
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)
|
|
170
|
-
}
|
|
170
|
+
result.requiredDraft = false
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
const releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
|
|
173
|
+
customerBizplaceId,
|
|
174
|
+
releaseOrder: result
|
|
175
|
+
})
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
if (releaseOrder) {
|
|
178
|
+
let movePaths = {
|
|
179
|
+
source: (dataPath += fileString),
|
|
180
|
+
destination: (successPath += fileString)
|
|
181
|
+
}
|
|
182
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
181
183
|
}
|
|
182
|
-
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
183
184
|
}
|
|
185
|
+
} else {
|
|
186
|
+
let movePaths = {
|
|
187
|
+
source: (dataPath += fileString),
|
|
188
|
+
destination: (failedPath += fileString)
|
|
189
|
+
}
|
|
190
|
+
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
184
191
|
}
|
|
185
|
-
}
|
|
192
|
+
} catch (e) {
|
|
186
193
|
let movePaths = {
|
|
187
194
|
source: (dataPath += fileString),
|
|
188
195
|
destination: (failedPath += fileString)
|
|
189
196
|
}
|
|
190
197
|
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
191
198
|
}
|
|
192
|
-
} catch (e) {
|
|
193
|
-
let movePaths = {
|
|
194
|
-
source: (dataPath += fileString),
|
|
195
|
-
destination: (failedPath += fileString)
|
|
196
|
-
}
|
|
197
|
-
await SFTPFILESTORAGE.moveFile(movePaths)
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
|
-
}
|
|
201
|
+
})
|
|
201
202
|
|
|
202
203
|
return true
|
|
203
204
|
}
|