@things-factory/integration-sftp 5.0.7 → 6.0.0-alpha.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 (50) hide show
  1. package/dist-server/controllers/herbalife/apis/create-serial-number.js.map +1 -1
  2. package/dist-server/controllers/herbalife/apis/create-shipment.js +42 -38
  3. package/dist-server/controllers/herbalife/apis/create-shipment.js.map +1 -1
  4. package/dist-server/controllers/herbalife/apis/echo.js.map +1 -1
  5. package/dist-server/controllers/herbalife/apis/get-outbound-order.js +6 -1
  6. package/dist-server/controllers/herbalife/apis/get-outbound-order.js.map +1 -1
  7. package/dist-server/controllers/herbalife/apis/index.js +5 -18
  8. package/dist-server/controllers/herbalife/apis/index.js.map +1 -1
  9. package/dist-server/controllers/herbalife/herbalife.js.map +1 -1
  10. package/dist-server/controllers/herbalife/index.js +3 -28
  11. package/dist-server/controllers/herbalife/index.js.map +1 -1
  12. package/dist-server/controllers/herbalife/platform-action.js.map +1 -1
  13. package/dist-server/controllers/index.js +2 -15
  14. package/dist-server/controllers/index.js.map +1 -1
  15. package/dist-server/controllers/sftp-api/decorators.js +2 -4
  16. package/dist-server/controllers/sftp-api/decorators.js.map +1 -1
  17. package/dist-server/controllers/sftp-api/index.js +19 -27
  18. package/dist-server/controllers/sftp-api/index.js.map +1 -1
  19. package/dist-server/controllers/sftp-api/types.js.map +1 -1
  20. package/dist-server/index.js +6 -19
  21. package/dist-server/index.js.map +1 -1
  22. package/dist-server/middlewares/index.js.map +1 -1
  23. package/dist-server/routes.js.map +1 -1
  24. package/dist-server/service/index.js +2 -15
  25. package/dist-server/service/index.js.map +1 -1
  26. package/dist-server/service/sftp/index.js.map +1 -1
  27. package/dist-server/service/sftp/sftp-mutation.js +157 -137
  28. package/dist-server/service/sftp/sftp-mutation.js.map +1 -1
  29. package/dist-server/service/sftp/sftp-query.js +35 -48
  30. package/dist-server/service/sftp/sftp-query.js.map +1 -1
  31. package/dist-server/service/sftp/sftp-type.js +48 -56
  32. package/dist-server/service/sftp/sftp-type.js.map +1 -1
  33. package/dist-server/service/sftp/sftp.js +52 -55
  34. package/dist-server/service/sftp/sftp.js.map +1 -1
  35. package/dist-server/sftp-const.js.map +1 -1
  36. package/dist-server/sftp-s3.js +2 -4
  37. package/dist-server/sftp-s3.js.map +1 -1
  38. package/dist-server/tsconfig.tsbuildinfo +1 -0
  39. package/dist-server/util/generate-files.js.map +1 -1
  40. package/dist-server/util/get-permitted-directories.js.map +1 -1
  41. package/dist-server/util/index.js +3 -16
  42. package/dist-server/util/index.js.map +1 -1
  43. package/package.json +8 -8
  44. package/server/controllers/herbalife/apis/create-shipment.ts +43 -42
  45. package/server/controllers/herbalife/apis/get-outbound-order.ts +7 -1
  46. package/server/controllers/sftp-api/index.ts +1 -1
  47. package/server/service/sftp/sftp-mutation.ts +114 -78
  48. package/server/service/sftp/sftp-query.ts +7 -8
  49. package/server/service/sftp/sftp.ts +4 -0
  50. package/server/util/get-permitted-directories.ts +1 -1
@@ -1 +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"}
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","sourcesContent":["import '../sftp-s3'\n\nimport { SFTPFILESTORAGE } from '../sftp-const'\n\nconst fs = require('fs')\n\nexport async function generateFiles(params: any[]) {\n const fileDirectory = './uploaded-files'\n for (let i = 0; i < params.length; i++) {\n let param: any = params[i]\n const { uploadPath, content, title } = param\n\n if (!fs.existsSync(fileDirectory)) {\n fs.mkdirSync(fileDirectory)\n }\n\n const filePath = fileDirectory + '/' + title\n\n fs.writeFile(filePath, content, function (err) {\n if (err) throw err\n console.log('File is created successfully.')\n })\n\n if (uploadPath) {\n const stream = fs.createReadStream(filePath)\n await SFTPFILESTORAGE.uploadFile({ stream, filename: title, uploadPath })\n }\n }\n\n fs.rm(fileDirectory, { recursive: true })\n\n return true\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"get-permitted-directories.js","sourceRoot":"","sources":["../../server/util/get-permitted-directories.ts"],"names":[],"mappings":";;;AAAA,sBAAmB;AAEnB,8CAA+C;AAExC,KAAK,UAAU,uBAAuB,CAAC,MAAW,EAAE,OAAY;IACrE,MAAM,eAAe,GAAU,MAAM,4BAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAExE,OAAO,eAAe,CAAA;AACxB,CAAC;AAJD,0DAIC;AAEM,KAAK,UAAU,QAAQ,CAAC,OAAY;IACzC,MAAM,IAAI,GAAQ,MAAM,4BAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAElE,OAAO,IAAI,CAAA;AACb,CAAC;AAJD,4BAIC"}
1
+ {"version":3,"file":"get-permitted-directories.js","sourceRoot":"","sources":["../../server/util/get-permitted-directories.ts"],"names":[],"mappings":";;;AAAA,sBAAmB;AAEnB,8CAA+C;AAExC,KAAK,UAAU,uBAAuB,CAAC,MAAW,EAAE,OAAwB;IACjF,MAAM,eAAe,GAAU,MAAM,4BAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAExE,OAAO,eAAe,CAAA;AACxB,CAAC;AAJD,0DAIC;AAEM,KAAK,UAAU,QAAQ,CAAC,OAAY;IACzC,MAAM,IAAI,GAAQ,MAAM,4BAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAElE,OAAO,IAAI,CAAA;AACb,CAAC;AAJD,4BAIC","sourcesContent":["import '../sftp-s3'\n\nimport { SFTPFILESTORAGE } from '../sftp-const'\n\nexport async function getPermittedDirectories(params: any, context: ResolverContext) {\n const sftpDirectories: any[] = await SFTPFILESTORAGE.readFolders(params)\n\n return sftpDirectories\n}\n\nexport async function readFile(fileKey: any) {\n const file: any = await SFTPFILESTORAGE.readFile(fileKey, 'utf-8')\n\n return file\n}\n"]}
@@ -1,19 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./get-permitted-directories"), exports);
18
- __exportStar(require("./generate-files"), exports);
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./get-permitted-directories"), exports);
5
+ tslib_1.__exportStar(require("./generate-files"), exports);
19
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA2C;AAC3C,mDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/util/index.ts"],"names":[],"mappings":";;;AAAA,sEAA2C;AAC3C,2DAAgC","sourcesContent":["export * from './get-permitted-directories'\nexport * from './generate-files'\n"]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@things-factory/integration-sftp",
3
- "version": "5.0.7",
3
+ "version": "6.0.0-alpha.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
7
7
  "license": "MIT",
8
- "author": "heartyoh",
8
+ "author": "heartyoh <heartyoh@hatiolab.com>",
9
9
  "description": "Integration With SFTP",
10
10
  "publishConfig": {
11
11
  "access": "public",
@@ -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.7",
28
- "@things-factory/biz-base": "^5.0.7",
29
- "@things-factory/env": "^5.0.0",
30
- "@things-factory/integration-fulfillment": "^5.0.7",
31
- "@things-factory/shell": "^5.0.7",
27
+ "@things-factory/auth-base": "^6.0.0-alpha.0",
28
+ "@things-factory/biz-base": "^6.0.0-alpha.0",
29
+ "@things-factory/env": "^6.0.0-alpha.0",
30
+ "@things-factory/integration-fulfillment": "^6.0.0-alpha.0",
31
+ "@things-factory/shell": "^6.0.0-alpha.0",
32
32
  "aws-sdk": "^2.960.0",
33
33
  "xml-js": "^1.6.11"
34
34
  },
35
- "gitHead": "1c7c7618e2e3c9ef8b07d730c3df84c8bc01b35f"
35
+ "gitHead": "e5b9823ab3ebc5d6ae5bcb4b5aa60c1306e4dd7e"
36
36
  }
@@ -5,7 +5,7 @@ export function createShipment() {
5
5
  method: 'post',
6
6
  path: '{folderPath}/{folderType}{shipmentCompletePath}',
7
7
  denormalize(req) {
8
- let { releaseGood, orderInventories, sftp } = req
8
+ let { releaseGoods, sftp } = req
9
9
  let { folderPath, platform } = sftp
10
10
  const folderType: string = sftp.isDevelopment ? `dev` : `prd`
11
11
  const shipmentCompletePath: string = COMPLETEDATAPATH
@@ -21,63 +21,64 @@ export function createShipment() {
21
21
  })
22
22
  sftp = { ...sftp, responseFilePattern: newResponseFilePattern }
23
23
 
24
- const warehouseNumber: string = releaseGood.refNo2
24
+ const warehouseNumber: string = releaseGoods[0].refNo2
25
25
  let title: string = suffix ? suffix : ``
26
26
  title += newSequence
27
27
  title += warehouseNumber ? `_` + warehouseNumber : ``
28
28
  title += fileExtension ? `.` + fileExtension : ``
29
29
 
30
- let backupTitle: string = releaseGood.refNo + '_' + title
31
-
30
+ let backupTitle: string = releaseGoods[0].refNo + '_' + title
32
31
  const orderNoColumn: number = 15
33
32
  const shipmentColumn: number = 27
34
33
  const trackingNoColumn: number = 20
35
-
36
- const refNoLength: number = releaseGood.refNo.length
37
- let content: string = `1710` + releaseGood.refNo
38
- let spaceNeeded: number = orderNoColumn - refNoLength
39
- for (let i = 0; i < spaceNeeded; i++) {
40
- content += ` `
41
- }
42
- content += warehouseNumber
43
- content += `001000001`
44
- for (let i = 0; i < shipmentColumn; i++) {
45
- content += ` `
46
- }
47
- content += `000000 `
48
- for (let i = 0; i < trackingNoColumn; i++) {
49
- content += ` `
50
- }
51
- content += `000000000000 `
52
- const today = new Date()
53
- const year = today.getFullYear().toString()
54
- const month = (today.getMonth() + 1).toString().padStart(2, '0')
55
- const day = today.getDate().toString().padStart(2, '0')
56
- const newDate = year + month + day
57
- content += newDate + '\n'
58
-
59
- for (let i = 0; i < orderInventories.length; i++) {
60
- const orderInventory: any = orderInventories[i]
61
- let sku: string = orderInventory.product.brandSku
62
- content += `1810` + releaseGood.refNo
34
+ let bulkContent = ''
35
+ for (let releaseGood of releaseGoods) {
36
+ const refNoLength: number = releaseGood.refNo.length
37
+ let content: string = `1710` + releaseGood.refNo
38
+ let spaceNeeded: number = orderNoColumn - refNoLength
63
39
  for (let i = 0; i < spaceNeeded; i++) {
64
40
  content += ` `
65
41
  }
66
- const idx = (i + 1).toString().padStart(2, '0')
67
- const productCode: string = sku.substring(0, 4)
68
- content += idx + `000000` + productCode
69
- let productCodeSpaceNeeded = 7 - productCode.length
70
- for (let i = 0; i < productCodeSpaceNeeded; i++) {
42
+ content += warehouseNumber
43
+ content += `001000001`
44
+ for (let i = 0; i < shipmentColumn; i++) {
71
45
  content += ` `
72
46
  }
73
- const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0')
74
- const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0')
75
- content += orderedQty + pickedQty + '\n'
76
- }
47
+ content += `000000 `
48
+ for (let i = 0; i < trackingNoColumn; i++) {
49
+ content += ` `
50
+ }
51
+ content += `000000000000 `
52
+ const today = new Date()
53
+ const year = today.getFullYear().toString()
54
+ const month = (today.getMonth() + 1).toString().padStart(2, '0')
55
+ const day = today.getDate().toString().padStart(2, '0')
56
+ const newDate = year + month + day
57
+ content += newDate + '\n'
77
58
 
59
+ for (let i = 0; i < releaseGood.orderInventories.length; i++) {
60
+ const orderInventory: any = releaseGood.orderInventories[i]
61
+ let sku: string = 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: string = 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
+ bulkContent += content
78
+ }
78
79
  return {
79
80
  resource: { folderPath, folderType, shipmentCompletePath },
80
- payload: { title, backupTitle, content, sftp, backupPath }
81
+ payload: { title, backupTitle, content: bulkContent, sftp, backupPath }
81
82
  }
82
83
  },
83
84
  normalize(res) {
@@ -73,6 +73,7 @@ export function getOutboundOrder() {
73
73
  let OrderLine = Order.PickList
74
74
  let totalItems: number = parseFloat(Order.PickList.LinesInPickList._text)
75
75
  let itemsToPick: any[] = []
76
+ let checkDuplicationValidation
76
77
  if (totalItems == 1) {
77
78
  if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {
78
79
  itemsToPick.push({
@@ -95,6 +96,10 @@ export function getOutboundOrder() {
95
96
  })
96
97
  }
97
98
 
99
+ if (ntsStatus == 'BACKORDER' && OrderLine.Item.some(itm => itm.QuantityReleased._text == 0)) {
100
+ checkDuplicationValidation = false
101
+ }
102
+
98
103
  if (itemsToPick.length == 0) {
99
104
  isAccept = false
100
105
  }
@@ -104,7 +109,8 @@ export function getOutboundOrder() {
104
109
  let result: any = {
105
110
  ...orderInfo,
106
111
  orderInventories: orderItems,
107
- isAccept
112
+ isAccept,
113
+ checkDuplicationValidation
108
114
  }
109
115
 
110
116
  return result
@@ -1,4 +1,4 @@
1
- import { getRepository } from 'typeorm'
1
+ import { getRepository } from '@things-factory/shell'
2
2
 
3
3
  import { Sftp } from '../../service'
4
4
  import { api } from './decorators'
@@ -4,20 +4,20 @@ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
4
4
  import { EntityManager, getConnection, In } from 'typeorm'
5
5
 
6
6
  import { Bizplace } from '@things-factory/biz-base'
7
- import { FulfillmentAPI, FulFillmentCenter } from '@things-factory/integration-fulfillment'
7
+ import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
8
8
  import { Domain } from '@things-factory/shell'
9
9
 
10
10
  import { SftpAPI } from '../../controllers'
11
11
  import { FAILEDDATAPATH, SFTPFILESTORAGE, SUBMITDATAPATH, SUCCESSDATAPATH } from '../../sftp-const'
12
12
  import { getPermittedDirectories } from '../../util'
13
- import { Sftp } from './sftp'
13
+ import { Sftp, SftpStatus } from './sftp'
14
14
  import { NewSftp, SftpPatch } from './sftp-type'
15
15
 
16
16
  @Resolver(Sftp)
17
17
  export class SftpMutation {
18
18
  @Directive('@transaction')
19
19
  @Mutation(returns => Sftp, { description: 'To create new Sftp' })
20
- async createSftp(@Arg('sftp') sftp: NewSftp, @Ctx() context: any): Promise<Sftp> {
20
+ async createSftp(@Arg('sftp') sftp: NewSftp, @Ctx() context: ResolverContext): Promise<Sftp> {
21
21
  const { domain, user, tx } = context.state
22
22
 
23
23
  return await tx.getRepository(Sftp).save({
@@ -30,12 +30,16 @@ export class SftpMutation {
30
30
 
31
31
  @Directive('@transaction')
32
32
  @Mutation(returns => Sftp, { description: 'To modify Sftp information' })
33
- async updateSftp(@Arg('id') id: string, @Arg('patch') patch: SftpPatch, @Ctx() context: any): Promise<Sftp> {
33
+ async updateSftp(
34
+ @Arg('id') id: string,
35
+ @Arg('patch') patch: SftpPatch,
36
+ @Ctx() context: ResolverContext
37
+ ): Promise<Sftp> {
34
38
  const { domain, user, tx } = context.state
35
39
 
36
40
  const repository = tx.getRepository(Sftp)
37
41
  const sftp = await repository.findOne({
38
- where: { domain, id }
42
+ where: { domain: { id: domain.id }, id }
39
43
  })
40
44
 
41
45
  return await repository.save({
@@ -49,7 +53,7 @@ export class SftpMutation {
49
53
  @Mutation(returns => [Sftp], { description: "To modify multiple Sftps' information" })
50
54
  async updateMultipleSftp(
51
55
  @Arg('patches', type => [SftpPatch]) patches: SftpPatch[],
52
- @Ctx() context: any
56
+ @Ctx() context: ResolverContext
53
57
  ): Promise<Sftp[]> {
54
58
  const { domain, user, tx } = context.state
55
59
 
@@ -76,7 +80,7 @@ export class SftpMutation {
76
80
  if (_updateRecords.length > 0) {
77
81
  for (let i = 0; i < _updateRecords.length; i++) {
78
82
  const newRecord = _updateRecords[i]
79
- const sftp = await sftpRepo.findOne(newRecord.id)
83
+ const sftp = await sftpRepo.findOneBy({ id: newRecord.id })
80
84
 
81
85
  const result = await sftpRepo.save({
82
86
  ...sftp,
@@ -93,20 +97,20 @@ export class SftpMutation {
93
97
 
94
98
  @Directive('@transaction')
95
99
  @Mutation(returns => Boolean, { description: 'To delete Sftp' })
96
- async deleteSftp(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
100
+ async deleteSftp(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
97
101
  const { domain, tx } = context.state
98
102
 
99
- await tx.getRepository(Sftp).delete({ domain, id })
103
+ await tx.getRepository(Sftp).delete({ domain: { id: domain.id }, id })
100
104
  return true
101
105
  }
102
106
 
103
107
  @Directive('@transaction')
104
108
  @Mutation(returns => Boolean, { description: 'To delete multiple sftps' })
105
- async deleteSftps(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
109
+ async deleteSftps(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
106
110
  const { domain, tx } = context.state
107
111
 
108
112
  await tx.getRepository(Sftp).delete({
109
- domain,
113
+ domain: { id: domain.id },
110
114
  id: In(ids)
111
115
  })
112
116
 
@@ -116,90 +120,122 @@ export class SftpMutation {
116
120
  @Mutation(returns => Boolean, { description: 'To sync all orders from sftp' })
117
121
  async syncSftpOrders(
118
122
  @Arg('customerDomainId', type => String) customerDomainId: string,
119
- @Ctx() context: any
123
+ @Ctx() context: ResolverContext
120
124
  ): Promise<boolean> {
121
125
  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
- })
126
+ const customerDomain: Domain = await tx.getRepository(Domain).findOneBy({ id: customerDomainId })
127
127
 
128
- const customerBizplaceId: string = customerBizplace.id
128
+ const customerBizplace: Bizplace = await getCustomerBizplace(customerDomainId, tx)
129
129
 
130
130
  const sftpUsers: Sftp[] = await tx.getRepository(Sftp).find({
131
- where: { domain: customerDomain, status: 'ACTIVE' },
131
+ where: { domain: { id: customerDomainId }, status: SftpStatus.ACTIVE },
132
132
  relations: ['fulfillmentCenter']
133
133
  })
134
134
 
135
135
  for (var i = 0; i < sftpUsers.length; i++) {
136
136
  const sftpUser: Sftp = sftpUsers[i]
137
+ processSftp(sftpUser, context, customerBizplace.id)
138
+ }
139
+ })
137
140
 
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
- }
169
-
170
- result.requiredDraft = false
171
-
172
- const 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)
189
- }
190
- await SFTPFILESTORAGE.moveFile(movePaths)
191
- }
192
- } catch (e) {
141
+ return true
142
+ }
143
+
144
+ @Directive('@transaction')
145
+ @Mutation(returns => Boolean, { description: 'Calls syncSftpOrders for all domain Ids' })
146
+ async syncAllSftpOrders(@Ctx() context: ResolverContext): Promise<Boolean> {
147
+ try {
148
+ await getConnection().transaction(async tx => {
149
+ const sftps = await tx
150
+ .getRepository(Sftp)
151
+ .createQueryBuilder('s')
152
+ .where('s.status = :status', { status: 'ACTIVE' })
153
+ .getMany()
154
+
155
+ if (sftps.length === 0) return
156
+ for (const sftp of sftps) {
157
+ const customerBizplace = await getCustomerBizplace(sftp.domainId, tx)
158
+ await processSftp(sftp, context, customerBizplace.id)
159
+ }
160
+ })
161
+ } catch (e) {
162
+ console.log(e)
163
+ }
164
+ return true
165
+ }
166
+ }
167
+
168
+ export async function processSftp(sftpUser, context, customerBizplaceId) {
169
+ const fulfilmentCenter: FulfillmentCenter = sftpUser.fulfillmentCenter
170
+ const isDevelopment: boolean = sftpUser.isDevelopment
171
+ const folderPath: string = sftpUser.folderPath
172
+ const folderType: string = isDevelopment ? 'dev' : 'prd'
173
+ let initialDataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
174
+ const results: any[] = await getPermittedDirectories({ path: initialDataPath }, context)
175
+ const filesDirectories: any[] = results.filter(result => result.Size > 0)
176
+
177
+ for await (let fileDirectory of filesDirectories) {
178
+ let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`
179
+ let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`
180
+ let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`
181
+ const fileKey: string = fileDirectory.Key
182
+ const lastSlashIdx = fileKey.lastIndexOf('/')
183
+ const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)
184
+ try {
185
+ const sftp: any = sftpUser
186
+ let result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })
187
+ let isAccept: boolean = result.isAccept
188
+
189
+ if (isAccept) {
190
+ delete result.isAccept
191
+ if (result) {
192
+ let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
193
+ customerBizplaceId,
194
+ refNo: result.refNo
195
+ })
196
+
197
+ if (releaseOrders) {
198
+ result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1)
199
+ }
200
+
201
+ result.requiredDraft = false
202
+
203
+ const releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
204
+ customerBizplaceId,
205
+ releaseOrder: result
206
+ })
207
+
208
+ if (releaseOrder) {
193
209
  let movePaths = {
194
210
  source: (dataPath += fileString),
195
- destination: (failedPath += fileString)
211
+ destination: (successPath += fileString)
196
212
  }
197
213
  await SFTPFILESTORAGE.moveFile(movePaths)
198
214
  }
199
215
  }
216
+ } else {
217
+ let movePaths = {
218
+ source: (dataPath += fileString),
219
+ destination: (failedPath += fileString)
220
+ }
221
+ await SFTPFILESTORAGE.moveFile(movePaths)
200
222
  }
201
- })
202
-
203
- return true
223
+ } catch (e) {
224
+ let movePaths = {
225
+ source: (dataPath += fileString),
226
+ destination: (failedPath += fileString)
227
+ }
228
+ await SFTPFILESTORAGE.moveFile(movePaths)
229
+ }
204
230
  }
205
231
  }
232
+
233
+ export async function getCustomerBizplace(customerDomainId, tx): Promise<Bizplace> {
234
+ const customerDomain: Domain = await tx.getRepository(Domain).findOneBy({ id: customerDomainId })
235
+
236
+ const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
237
+ where: { domain: customerDomain }
238
+ })
239
+
240
+ return customerBizplace
241
+ }
@@ -1,8 +1,7 @@
1
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
- import { getRepository } from 'typeorm'
3
2
 
4
3
  import { User } from '@things-factory/auth-base'
5
- import { convertListParams, Domain, ListParam } from '@things-factory/shell'
4
+ import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
6
5
 
7
6
  import { Sftp } from './sftp'
8
7
  import { SftpList } from './sftp-type'
@@ -10,16 +9,16 @@ import { SftpList } from './sftp-type'
10
9
  @Resolver(Sftp)
11
10
  export class SftpQuery {
12
11
  @Query(returns => Sftp, { description: 'To fetch a Sftp' })
13
- async sftp(@Arg('id') id: string, @Ctx() context: any): Promise<Sftp> {
12
+ async sftp(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Sftp> {
14
13
  const { domain } = context.state
15
14
 
16
15
  return await getRepository(Sftp).findOne({
17
- where: { domain, id }
16
+ where: { domain: { id: domain.id }, id }
18
17
  })
19
18
  }
20
19
 
21
20
  @Query(returns => SftpList, { description: 'To fetch multiple Sftps' })
22
- async sftps(@Args() params: ListParam, @Ctx() context: any): Promise<SftpList> {
21
+ async sftps(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<SftpList> {
23
22
  const { domain } = context.state
24
23
 
25
24
  const convertedParams = convertListParams(params, { domain })
@@ -30,16 +29,16 @@ export class SftpQuery {
30
29
 
31
30
  @FieldResolver(type => Domain)
32
31
  async domain(@Root() sftp: Sftp): Promise<Domain> {
33
- return await getRepository(Domain).findOne(sftp.domainId)
32
+ return await getRepository(Domain).findOneBy({ id: sftp.domainId })
34
33
  }
35
34
 
36
35
  @FieldResolver(type => User)
37
36
  async updater(@Root() sftp: Sftp): Promise<User> {
38
- return await getRepository(User).findOne(sftp.updaterId)
37
+ return await getRepository(User).findOneBy({ id: sftp.updaterId })
39
38
  }
40
39
 
41
40
  @FieldResolver(type => User)
42
41
  async creator(@Root() sftp: Sftp): Promise<User> {
43
- return await getRepository(User).findOne(sftp.creatorId)
42
+ return await getRepository(User).findOneBy({ id: sftp.creatorId })
44
43
  }
45
44
  }
@@ -111,6 +111,10 @@ export class Sftp {
111
111
  @Field({ nullable: true })
112
112
  responseFileTypes: string
113
113
 
114
+ @Column({ nullable: true })
115
+ @Field({ nullable: true })
116
+ lastTimeSync?: Date
117
+
114
118
  @CreateDateColumn()
115
119
  @Field({ nullable: true })
116
120
  createdAt?: Date
@@ -2,7 +2,7 @@ import '../sftp-s3'
2
2
 
3
3
  import { SFTPFILESTORAGE } from '../sftp-const'
4
4
 
5
- export async function getPermittedDirectories(params: any, context: any) {
5
+ export async function getPermittedDirectories(params: any, context: ResolverContext) {
6
6
  const sftpDirectories: any[] = await SFTPFILESTORAGE.readFolders(params)
7
7
 
8
8
  return sftpDirectories