@things-factory/integration-sftp 5.0.14 → 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.
@@ -7,7 +7,7 @@ function createShipment() {
7
7
  method: 'post',
8
8
  path: '{folderPath}/{folderType}{shipmentCompletePath}',
9
9
  denormalize(req) {
10
- let { releaseGood, orderInventories, sftp } = req;
10
+ let { releaseGoods, sftp } = req;
11
11
  let { folderPath, platform } = sftp;
12
12
  const folderType = sftp.isDevelopment ? `dev` : `prd`;
13
13
  const shipmentCompletePath = sftp_const_1.COMPLETEDATAPATH;
@@ -18,58 +18,62 @@ function createShipment() {
18
18
  let newSequence = newSeq.toString().padStart(runningNumberDigit, '0');
19
19
  let newResponseFilePattern = JSON.stringify(Object.assign(Object.assign({}, responseFilePattern), { sequence: newSeq.toString() }));
20
20
  sftp = Object.assign(Object.assign({}, sftp), { responseFilePattern: newResponseFilePattern });
21
- const warehouseNumber = releaseGood.refNo2;
21
+ const warehouseNumber = releaseGoods[0].refNo2;
22
22
  let title = suffix ? suffix : ``;
23
23
  title += newSequence;
24
24
  title += warehouseNumber ? `_` + warehouseNumber : ``;
25
25
  title += fileExtension ? `.` + fileExtension : ``;
26
- let backupTitle = releaseGood.refNo + '_' + title;
26
+ let backupTitle = releaseGoods[0].refNo + '_' + title;
27
27
  const orderNoColumn = 15;
28
28
  const shipmentColumn = 27;
29
29
  const trackingNoColumn = 20;
30
- const refNoLength = releaseGood.refNo.length;
31
- let content = `1710` + releaseGood.refNo;
32
- let spaceNeeded = orderNoColumn - refNoLength;
33
- for (let i = 0; i < spaceNeeded; i++) {
34
- content += ` `;
35
- }
36
- content += warehouseNumber;
37
- content += `001000001`;
38
- for (let i = 0; i < shipmentColumn; i++) {
39
- content += ` `;
40
- }
41
- content += `000000 `;
42
- for (let i = 0; i < trackingNoColumn; i++) {
43
- content += ` `;
44
- }
45
- content += `000000000000 `;
46
- const today = new Date();
47
- const year = today.getFullYear().toString();
48
- const month = (today.getMonth() + 1).toString().padStart(2, '0');
49
- const day = today.getDate().toString().padStart(2, '0');
50
- const newDate = year + month + day;
51
- content += newDate + '\n';
52
- for (let i = 0; i < orderInventories.length; i++) {
53
- const orderInventory = orderInventories[i];
54
- let sku = orderInventory.product.brandSku;
55
- content += `1810` + releaseGood.refNo;
30
+ let bulkContent = '';
31
+ for (let releaseGood of releaseGoods) {
32
+ const refNoLength = releaseGood.refNo.length;
33
+ let content = `1710` + releaseGood.refNo;
34
+ let spaceNeeded = orderNoColumn - refNoLength;
56
35
  for (let i = 0; i < spaceNeeded; i++) {
57
36
  content += ` `;
58
37
  }
59
- const idx = (i + 1).toString().padStart(2, '0');
60
- const productCode = sku.substring(0, 4);
61
- content += idx + `000000` + productCode;
62
- let productCodeSpaceNeeded = 7 - productCode.length;
63
- for (let i = 0; i < productCodeSpaceNeeded; i++) {
38
+ content += warehouseNumber;
39
+ content += `001000001`;
40
+ for (let i = 0; i < shipmentColumn; i++) {
64
41
  content += ` `;
65
42
  }
66
- const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0');
67
- const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0');
68
- content += orderedQty + pickedQty + '\n';
43
+ content += `000000 `;
44
+ for (let i = 0; i < trackingNoColumn; i++) {
45
+ content += ` `;
46
+ }
47
+ content += `000000000000 `;
48
+ const today = new Date();
49
+ const year = today.getFullYear().toString();
50
+ const month = (today.getMonth() + 1).toString().padStart(2, '0');
51
+ const day = today.getDate().toString().padStart(2, '0');
52
+ const newDate = year + month + day;
53
+ content += newDate + '\n';
54
+ for (let i = 0; i < releaseGood.orderInventories.length; i++) {
55
+ const orderInventory = releaseGood.orderInventories[i];
56
+ let sku = orderInventory.product.brandSku;
57
+ content += `1810` + releaseGood.refNo;
58
+ for (let i = 0; i < spaceNeeded; i++) {
59
+ content += ` `;
60
+ }
61
+ const idx = (i + 1).toString().padStart(2, '0');
62
+ const productCode = sku.substring(0, 4);
63
+ content += idx + `000000` + productCode;
64
+ let productCodeSpaceNeeded = 7 - productCode.length;
65
+ for (let i = 0; i < productCodeSpaceNeeded; i++) {
66
+ content += ` `;
67
+ }
68
+ const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0');
69
+ const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0');
70
+ content += orderedQty + pickedQty + '\n';
71
+ }
72
+ bulkContent += content;
69
73
  }
70
74
  return {
71
75
  resource: { folderPath, folderType, shipmentCompletePath },
72
- payload: { title, backupTitle, content, sftp, backupPath }
76
+ payload: { title, backupTitle, content: bulkContent, sftp, backupPath }
73
77
  };
74
78
  },
75
79
  normalize(res) {
@@ -1 +1 @@
1
- {"version":3,"file":"create-shipment.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/create-shipment.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAElE,SAAgB,cAAc;IAC5B,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,iDAAiD;QACvD,WAAW,CAAC,GAAG;YACb,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;YACjD,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,oBAAoB,GAAW,6BAAgB,CAAA;YACrD,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,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAA;YACnF,IAAI,MAAM,GAAW,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC7C,IAAI,WAAW,G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MAAM,WAAW,GAAW,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;gBAC/C,OAAO,IAAI,GAAG,GAAG,QAAQ,GAAG,WAAW,CAAA;gBACvC,IAAI,sBAAsB,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,CAAA;gBACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,sBAAsB,EAAE,CAAC,EAAE,EAAE;oBAC/C,OAAO,IAAI,GAAG,CAAA;iBACf;gBACD,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,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,oBAAoB,EAAE;gBAC1D,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE;aAC3D,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AApFD,wCAoFC","sourcesContent":["import { BACKUPPATH, COMPLETEDATAPATH } from '../../../sftp-const'\n\nexport function createShipment() {\n return {\n method: 'post',\n path: '{folderPath}/{folderType}{shipmentCompletePath}',\n denormalize(req) {\n let { releaseGood, orderInventories, sftp } = req\n let { folderPath, platform } = sftp\n const folderType: string = sftp.isDevelopment ? `dev` : `prd`\n const shipmentCompletePath: string = COMPLETEDATAPATH\n const backupPath: string = `${BACKUPPATH}${platform}/${folderType}`\n\n let responseFilePattern: any = JSON.parse(sftp.responseFilePattern)\n const { suffix, fileExtension, runningNumberDigit, sequence } = responseFilePattern\n let newSeq: number = parseFloat(sequence) + 1\n let newSequence = newSeq.toString().padStart(runningNumberDigit, '0')\n let newResponseFilePattern: string = JSON.stringify({\n ...responseFilePattern,\n sequence: newSeq.toString()\n })\n sftp = { ...sftp, responseFilePattern: newResponseFilePattern }\n\n const warehouseNumber: string = releaseGood.refNo2\n let title: string = suffix ? suffix : ``\n title += newSequence\n title += warehouseNumber ? `_` + warehouseNumber : ``\n title += fileExtension ? `.` + fileExtension : ``\n\n let backupTitle: string = releaseGood.refNo + '_' + title\n\n const orderNoColumn: number = 15\n const shipmentColumn: number = 27\n const trackingNoColumn: number = 20\n\n const refNoLength: number = releaseGood.refNo.length\n let content: string = `1710` + releaseGood.refNo\n let spaceNeeded: number = orderNoColumn - refNoLength\n for (let i = 0; i < spaceNeeded; i++) {\n content += ` `\n }\n content += warehouseNumber\n content += `001000001`\n for (let i = 0; i < shipmentColumn; i++) {\n content += ` `\n }\n content += `000000 `\n for (let i = 0; i < trackingNoColumn; i++) {\n content += ` `\n }\n content += `000000000000 `\n const today = new Date()\n const year = today.getFullYear().toString()\n const month = (today.getMonth() + 1).toString().padStart(2, '0')\n const day = today.getDate().toString().padStart(2, '0')\n const newDate = year + month + day\n content += newDate + '\\n'\n\n for (let i = 0; i < orderInventories.length; i++) {\n const orderInventory: any = orderInventories[i]\n let sku: string = orderInventory.product.brandSku\n content += `1810` + releaseGood.refNo\n for (let i = 0; i < spaceNeeded; i++) {\n content += ` `\n }\n const idx = (i + 1).toString().padStart(2, '0')\n const productCode: string = sku.substring(0, 4)\n content += idx + `000000` + productCode\n let productCodeSpaceNeeded = 7 - productCode.length\n for (let i = 0; i < productCodeSpaceNeeded; i++) {\n content += ` `\n }\n const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0')\n const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0')\n content += orderedQty + pickedQty + '\\n'\n }\n\n return {\n resource: { folderPath, folderType, shipmentCompletePath },\n payload: { title, backupTitle, content, sftp, backupPath }\n }\n },\n normalize(res) {\n return res\n }\n }\n}\n"]}
1
+ {"version":3,"file":"create-shipment.js","sourceRoot":"","sources":["../../../../server/controllers/herbalife/apis/create-shipment.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAElE,SAAgB,cAAc;IAC5B,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,iDAAiD;QACvD,WAAW,CAAC,GAAG;YACb,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;YAChC,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,oBAAoB,GAAW,6BAAgB,CAAA;YACrD,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,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAA;YACnF,IAAI,MAAM,GAAW,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC7C,IAAI,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;YACrE,IAAI,sBAAsB,GAAW,IAAI,CAAC,SAAS,iCAC9C,mBAAmB,KACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,IAC3B,CAAA;YACF,IAAI,mCAAQ,IAAI,KAAE,mBAAmB,EAAE,sBAAsB,GAAE,CAAA;YAE/D,MAAM,eAAe,GAAW,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;YACtD,IAAI,KAAK,GAAW,MAAM,CAAC,CAAC,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AAC,GAAG,CAAC,EAAE,CAAC,GAAG,sBAAsB,EAAE,CAAC,EAAE,EAAE;wBAC/C,OAAO,IAAI,GAAG,CAAA;qBACf;oBACD,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;oBACxE,MAAM,SAAS,GAAG,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;oBACtE,OAAO,IAAI,UAAU,GAAG,SAAS,GAAG,IAAI,CAAA;iBACzC;gBACD,WAAW,IAAI,OAAO,CAAA;aACvB;YACD,OAAO;gBACL,QAAQ,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE;gBAC1D,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE;aACxE,CAAA;QACH,CAAC;QACD,SAAS,CAAC,GAAG;YACX,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AArFD,wCAqFC","sourcesContent":["import { BACKUPPATH, COMPLETEDATAPATH } from '../../../sftp-const'\n\nexport function createShipment() {\n return {\n method: 'post',\n path: '{folderPath}/{folderType}{shipmentCompletePath}',\n denormalize(req) {\n let { releaseGoods, sftp } = req\n let { folderPath, platform } = sftp\n const folderType: string = sftp.isDevelopment ? `dev` : `prd`\n const shipmentCompletePath: string = COMPLETEDATAPATH\n const backupPath: string = `${BACKUPPATH}${platform}/${folderType}`\n\n let responseFilePattern: any = JSON.parse(sftp.responseFilePattern)\n const { suffix, fileExtension, runningNumberDigit, sequence } = responseFilePattern\n let newSeq: number = parseFloat(sequence) + 1\n let newSequence = newSeq.toString().padStart(runningNumberDigit, '0')\n let newResponseFilePattern: string = JSON.stringify({\n ...responseFilePattern,\n sequence: newSeq.toString()\n })\n sftp = { ...sftp, responseFilePattern: newResponseFilePattern }\n\n const warehouseNumber: string = releaseGoods[0].refNo2\n let title: string = suffix ? suffix : ``\n title += newSequence\n title += warehouseNumber ? `_` + warehouseNumber : ``\n title += fileExtension ? `.` + fileExtension : ``\n\n let backupTitle: string = releaseGoods[0].refNo + '_' + title\n const orderNoColumn: number = 15\n const shipmentColumn: number = 27\n const trackingNoColumn: number = 20\n let bulkContent = ''\n for (let releaseGood of releaseGoods) {\n const refNoLength: number = releaseGood.refNo.length\n let content: string = `1710` + releaseGood.refNo\n let spaceNeeded: number = orderNoColumn - refNoLength\n for (let i = 0; i < spaceNeeded; i++) {\n content += ` `\n }\n content += warehouseNumber\n content += `001000001`\n for (let i = 0; i < shipmentColumn; i++) {\n content += ` `\n }\n content += `000000 `\n for (let i = 0; i < trackingNoColumn; i++) {\n content += ` `\n }\n content += `000000000000 `\n const today = new Date()\n const year = today.getFullYear().toString()\n const month = (today.getMonth() + 1).toString().padStart(2, '0')\n const day = today.getDate().toString().padStart(2, '0')\n const newDate = year + month + day\n content += newDate + '\\n'\n\n for (let i = 0; i < releaseGood.orderInventories.length; i++) {\n const orderInventory: any = releaseGood.orderInventories[i]\n let sku: string = orderInventory.product.brandSku\n content += `1810` + releaseGood.refNo\n for (let i = 0; i < spaceNeeded; i++) {\n content += ` `\n }\n const idx = (i + 1).toString().padStart(2, '0')\n const productCode: string = sku.substring(0, 4)\n content += idx + `000000` + productCode\n let productCodeSpaceNeeded = 7 - productCode.length\n for (let i = 0; i < productCodeSpaceNeeded; i++) {\n content += ` `\n }\n const orderedQty = orderInventory.releaseQty.toString().padStart(4, '0')\n const pickedQty = orderInventory.pickedQty.toString().padStart(4, '0')\n content += orderedQty + pickedQty + '\\n'\n }\n bulkContent += content\n }\n return {\n resource: { folderPath, folderType, shipmentCompletePath },\n payload: { title, backupTitle, content: bulkContent, sftp, backupPath }\n }\n },\n normalize(res) {\n return res\n }\n }\n}\n"]}
@@ -68,6 +68,7 @@ function getOutboundOrder() {
68
68
  let OrderLine = Order.PickList;
69
69
  let totalItems = parseFloat(Order.PickList.LinesInPickList._text);
70
70
  let itemsToPick = [];
71
+ let checkDuplicationValidation;
71
72
  if (totalItems == 1) {
72
73
  if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {
73
74
  itemsToPick.push({
@@ -90,11 +91,15 @@ function getOutboundOrder() {
90
91
  }
91
92
  });
92
93
  }
94
+ if (ntsStatus == 'BACKORDER' && OrderLine.Item.some(itm => itm.QuantityReleased._text == 0)) {
95
+ checkDuplicationValidation = false;
96
+ }
93
97
  if (itemsToPick.length == 0) {
94
98
  isAccept = false;
95
99
  }
96
100
  let orderItems = itemsToPick;
97
- let result = Object.assign(Object.assign({}, orderInfo), { orderInventories: orderItems, isAccept });
101
+ let result = Object.assign(Object.assign({}, orderInfo), { orderInventories: orderItems, isAccept,
102
+ checkDuplicationValidation });
98
103
  return result;
99
104
  }
100
105
  };
@@ -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,8CAA8C;QACpD,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,EAAE,EAAE,IAAI,EAAE;YACrB,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;YACrB,IAAI,QAAQ,GAAY,KAAK,CAAA;YAE7B,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;YAChE,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,gBAAgB,CAAA,CAAC,yBAAyB;YACvF,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;YAC9B,IAAI,UAAU,GAAW,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;YACzE,IAAI,WAAW,GAAU,EAAE,CAAA;YAC3B,IAAI,UAAU,IAAI,CAAC,EAAE;gBACnB,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACzD,WAAW,CAAC,IAAI,CAAC;wBACf,OAAO,EAAE;4BACP,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK;yBACtC;wBACD,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;qBAC9D,CAAC,CAAA;iBACH;aACF;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;oBACxB,IAAI,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;wBAC/C,WAAW,CAAC,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","sourcesContent":["export function getOutboundOrder() {\n return {\n method: 'get',\n path: '{folderPath}/{folderType}/sob/data/{fileKey}',\n denormalize(req) {\n const { folderPath, folderType, fileKey } = req\n return {\n resource: { folderPath, folderType, fileKey }\n }\n },\n normalize(res, { sftp }) {\n const { Order } = res\n let isAccept: boolean = false\n\n const responseFilePattern = JSON.parse(sftp.responseFilePattern)\n const acceptOrderTypes = responseFilePattern.acceptOrderTypes // ['RSO', 'MSO', 'MSBO']\n const acceptNTSStatuses = responseFilePattern.acceptNTSStatuses //['', 'BACKORDER']\n const acceptWarehouseNumber = responseFilePattern.acceptWarehouseNumber //['NK']\n const acceptCommand = responseFilePattern.acceptCommand //['NTS', '']\n const acceptFreightCode = responseFilePattern.acceptFreightCode // ['PU']\n\n let orderHeader: any = Order.OrderHeader\n let generalInfo: any = orderHeader.General\n let distributorDetails: any = orderHeader.DistributorDetails\n let shippingInstructions: any = Order.ShippingInstructions\n\n let orderType: string = generalInfo.OrderType._text\n let ntsStatus: string = generalInfo.NTSStatus._text || ''\n let command: string = generalInfo.Command._text || ''\n let warehouseNumber: string = generalInfo.WarehouseNumber._text\n let freightCode: string = shippingInstructions.FreightCode._text\n\n if (\n acceptWarehouseNumber.includes(warehouseNumber) &&\n acceptOrderTypes.includes(orderType) &&\n acceptNTSStatuses.includes(ntsStatus) &&\n acceptCommand.includes(command) &&\n acceptFreightCode.includes(freightCode)\n ) {\n isAccept = true\n }\n\n let shippingInstruction: string = shippingInstructions.ShippingInstructions._text\n let ntsDateParts = generalInfo.NTS_Date._text.split('/')\n let releaseDate: string = ntsDateParts[2] + '-' + ntsDateParts[1] + '-' + ntsDateParts[0]\n let orderInfo: any = {\n refNo: generalInfo.OrderNumber._text,\n refNo2: warehouseNumber,\n type: 'b2b',\n releaseDate,\n collectionOrderNo: generalInfo.OrderNumber._text,\n marketplaceOrderStatus: ntsStatus,\n ownTransport: true,\n exportOption: false,\n packingOption: false,\n remark: shippingInstruction,\n billTo: {\n billingAddress: distributorDetails.BillTo.BillToAddress._text\n },\n deliverTo: {\n deliveryAddress1: distributorDetails.ShipTo.Address1._text,\n deliveryAddress2: distributorDetails.ShipTo.Address2._text,\n deliveryAddress3: distributorDetails.ShipTo.Address3._text,\n attentionTo: distributorDetails.ShipTo.Name._text,\n city: distributorDetails.ShipTo.City._text,\n state: distributorDetails.ShipTo.ShipToState._text,\n postalCode: distributorDetails.ShipTo.Zipcode._text,\n country: distributorDetails.ShipTo.Country._text,\n phone1: distributorDetails.ShipTo.Phone._text\n }\n }\n\n let OrderLine = Order.PickList\n let totalItems: number = parseFloat(Order.PickList.LinesInPickList._text)\n let itemsToPick: any[] = []\n if (totalItems == 1) {\n if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {\n itemsToPick.push({\n product: {\n sku: OrderLine.Item.StockingSKU._text\n },\n releaseQty: parseFloat(OrderLine.Item.QuantityReleased._text)\n })\n }\n } else {\n OrderLine.Item.map(line => {\n if (parseFloat(line.QuantityReleased._text) > 0) {\n itemsToPick.push({\n product: {\n sku: line.StockingSKU._text\n },\n releaseQty: parseFloat(line.QuantityReleased._text)\n })\n }\n })\n }\n\n if (itemsToPick.length == 0) {\n isAccept = false\n }\n\n let orderItems: any[] = itemsToPick\n\n let result: any = {\n ...orderInfo,\n orderInventories: orderItems,\n isAccept\n }\n\n return result\n }\n }\n}\n"]}
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,8CAA8C;QACpD,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,EAAE,EAAE,IAAI,EAAE;YACrB,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;YACrB,IAAI,QAAQ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3F,0BAA0B,GAAG,KAAK,CAAA;aACnC;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;gBACR,0BAA0B,GAC3B,CAAA;YAED,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC;AAtHD,4CAsHC","sourcesContent":["export function getOutboundOrder() {\n return {\n method: 'get',\n path: '{folderPath}/{folderType}/sob/data/{fileKey}',\n denormalize(req) {\n const { folderPath, folderType, fileKey } = req\n return {\n resource: { folderPath, folderType, fileKey }\n }\n },\n normalize(res, { sftp }) {\n const { Order } = res\n let isAccept: boolean = false\n\n const responseFilePattern = JSON.parse(sftp.responseFilePattern)\n const acceptOrderTypes = responseFilePattern.acceptOrderTypes // ['RSO', 'MSO', 'MSBO']\n const acceptNTSStatuses = responseFilePattern.acceptNTSStatuses //['', 'BACKORDER']\n const acceptWarehouseNumber = responseFilePattern.acceptWarehouseNumber //['NK']\n const acceptCommand = responseFilePattern.acceptCommand //['NTS', '']\n const acceptFreightCode = responseFilePattern.acceptFreightCode // ['PU']\n\n let orderHeader: any = Order.OrderHeader\n let generalInfo: any = orderHeader.General\n let distributorDetails: any = orderHeader.DistributorDetails\n let shippingInstructions: any = Order.ShippingInstructions\n\n let orderType: string = generalInfo.OrderType._text\n let ntsStatus: string = generalInfo.NTSStatus._text || ''\n let command: string = generalInfo.Command._text || ''\n let warehouseNumber: string = generalInfo.WarehouseNumber._text\n let freightCode: string = shippingInstructions.FreightCode._text\n\n if (\n acceptWarehouseNumber.includes(warehouseNumber) &&\n acceptOrderTypes.includes(orderType) &&\n acceptNTSStatuses.includes(ntsStatus) &&\n acceptCommand.includes(command) &&\n acceptFreightCode.includes(freightCode)\n ) {\n isAccept = true\n }\n\n let shippingInstruction: string = shippingInstructions.ShippingInstructions._text\n let ntsDateParts = generalInfo.NTS_Date._text.split('/')\n let releaseDate: string = ntsDateParts[2] + '-' + ntsDateParts[1] + '-' + ntsDateParts[0]\n let orderInfo: any = {\n refNo: generalInfo.OrderNumber._text,\n refNo2: warehouseNumber,\n type: 'b2b',\n releaseDate,\n collectionOrderNo: generalInfo.OrderNumber._text,\n marketplaceOrderStatus: ntsStatus,\n ownTransport: true,\n exportOption: false,\n packingOption: false,\n remark: shippingInstruction,\n billTo: {\n billingAddress: distributorDetails.BillTo.BillToAddress._text\n },\n deliverTo: {\n deliveryAddress1: distributorDetails.ShipTo.Address1._text,\n deliveryAddress2: distributorDetails.ShipTo.Address2._text,\n deliveryAddress3: distributorDetails.ShipTo.Address3._text,\n attentionTo: distributorDetails.ShipTo.Name._text,\n city: distributorDetails.ShipTo.City._text,\n state: distributorDetails.ShipTo.ShipToState._text,\n postalCode: distributorDetails.ShipTo.Zipcode._text,\n country: distributorDetails.ShipTo.Country._text,\n phone1: distributorDetails.ShipTo.Phone._text\n }\n }\n\n let OrderLine = Order.PickList\n let totalItems: number = parseFloat(Order.PickList.LinesInPickList._text)\n let itemsToPick: any[] = []\n let checkDuplicationValidation\n if (totalItems == 1) {\n if (parseFloat(OrderLine.Item.QuantityReleased._text) > 0) {\n itemsToPick.push({\n product: {\n sku: OrderLine.Item.StockingSKU._text\n },\n releaseQty: parseFloat(OrderLine.Item.QuantityReleased._text)\n })\n }\n } else {\n OrderLine.Item.map(line => {\n if (parseFloat(line.QuantityReleased._text) > 0) {\n itemsToPick.push({\n product: {\n sku: line.StockingSKU._text\n },\n releaseQty: parseFloat(line.QuantityReleased._text)\n })\n }\n })\n }\n\n if (ntsStatus == 'BACKORDER' && OrderLine.Item.some(itm => itm.QuantityReleased._text == 0)) {\n checkDuplicationValidation = false\n }\n\n if (itemsToPick.length == 0) {\n isAccept = false\n }\n\n let orderItems: any[] = itemsToPick\n\n let result: any = {\n ...orderInfo,\n orderInventories: orderItems,\n isAccept,\n checkDuplicationValidation\n }\n\n return result\n }\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SftpAPI = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const typeorm_1 = require("typeorm");
5
+ const shell_1 = require("@things-factory/shell");
6
6
  const service_1 = require("../../service");
7
7
  const decorators_1 = require("./decorators");
8
8
  class SftpAPI {
@@ -16,7 +16,7 @@ class SftpAPI {
16
16
  return SftpAPI.platforms[name];
17
17
  }
18
18
  static async getSftp(id) {
19
- const repository = (0, typeorm_1.getRepository)(service_1.Sftp);
19
+ const repository = (0, shell_1.getRepository)(service_1.Sftp);
20
20
  return await repository.findOne({
21
21
  where: { id },
22
22
  relations: ['domain']
@@ -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;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","sourcesContent":["import { getRepository } from 'typeorm'\n\nimport { Sftp } from '../../service'\nimport { api } from './decorators'\n\nexport class SftpAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SftpAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SftpAPI.platforms[name]\n }\n\n static async getSftp(id) {\n const repository = getRepository(Sftp)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sftp, req): any {}\n\n @api\n static getOutboundOrder(sftp, req): any {}\n\n @api\n static createShipment(sftp, req): any {}\n\n @api\n static createSerialNumber(sftp, req): any {}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/controllers/sftp-api/index.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AAErD,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,qBAAa,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","sourcesContent":["import { getRepository } from '@things-factory/shell'\n\nimport { Sftp } from '../../service'\nimport { api } from './decorators'\n\nexport class SftpAPI {\n static platforms = {}\n\n static registerPlatform(name, action, apis) {\n SftpAPI.platforms[name] = {\n action,\n apis\n }\n }\n\n static getPlatform(name) {\n return SftpAPI.platforms[name]\n }\n\n static async getSftp(id) {\n const repository = getRepository(Sftp)\n return await repository.findOne({\n where: { id },\n relations: ['domain']\n })\n }\n\n @api\n static echo(sftp, req): any {}\n\n @api\n static getOutboundOrder(sftp, req): any {}\n\n @api\n static createShipment(sftp, req): any {}\n\n @api\n static createSerialNumber(sftp, req): any {}\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SftpMutation = void 0;
3
+ exports.getCustomerBizplace = exports.processSftp = exports.SftpMutation = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  require("../../sftp-s3");
6
6
  const type_graphql_1 = require("type-graphql");
@@ -22,7 +22,7 @@ let SftpMutation = class SftpMutation {
22
22
  const { domain, user, tx } = context.state;
23
23
  const repository = tx.getRepository(sftp_1.Sftp);
24
24
  const sftp = await repository.findOne({
25
- where: { domain, id }
25
+ where: { domain: { id: domain.id }, id }
26
26
  });
27
27
  return await repository.save(Object.assign(Object.assign(Object.assign({}, sftp), patch), { updater: user }));
28
28
  }
@@ -42,7 +42,7 @@ let SftpMutation = class SftpMutation {
42
42
  if (_updateRecords.length > 0) {
43
43
  for (let i = 0; i < _updateRecords.length; i++) {
44
44
  const newRecord = _updateRecords[i];
45
- const sftp = await sftpRepo.findOne(newRecord.id);
45
+ const sftp = await sftpRepo.findOneBy({ id: newRecord.id });
46
46
  const result = await sftpRepo.save(Object.assign(Object.assign(Object.assign({}, sftp), newRecord), { updater: user }));
47
47
  results.push(Object.assign(Object.assign({}, result), { cuFlag: 'M' }));
48
48
  }
@@ -51,103 +51,53 @@ let SftpMutation = class SftpMutation {
51
51
  }
52
52
  async deleteSftp(id, context) {
53
53
  const { domain, tx } = context.state;
54
- await tx.getRepository(sftp_1.Sftp).delete({ domain, id });
54
+ await tx.getRepository(sftp_1.Sftp).delete({ domain: { id: domain.id }, id });
55
55
  return true;
56
56
  }
57
57
  async deleteSftps(ids, context) {
58
58
  const { domain, tx } = context.state;
59
59
  await tx.getRepository(sftp_1.Sftp).delete({
60
- domain,
60
+ domain: { id: domain.id },
61
61
  id: (0, typeorm_1.In)(ids)
62
62
  });
63
63
  return true;
64
64
  }
65
65
  async syncSftpOrders(customerDomainId, context) {
66
66
  await (0, typeorm_1.getConnection)().transaction(async (tx) => {
67
- var e_1, _a;
68
- const customerDomain = await tx.getRepository(shell_1.Domain).findOne(customerDomainId);
69
- const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
70
- where: { domain: customerDomain }
71
- });
72
- const customerBizplaceId = customerBizplace.id;
67
+ const customerDomain = await tx.getRepository(shell_1.Domain).findOneBy({ id: customerDomainId });
68
+ const customerBizplace = await getCustomerBizplace(customerDomainId, tx);
73
69
  const sftpUsers = await tx.getRepository(sftp_1.Sftp).find({
74
- where: { domain: customerDomain, status: 'ACTIVE' },
70
+ where: { domain: { id: customerDomainId }, status: sftp_1.SftpStatus.ACTIVE },
75
71
  relations: ['fulfillmentCenter']
76
72
  });
77
73
  for (var i = 0; i < sftpUsers.length; i++) {
78
74
  const sftpUser = sftpUsers[i];
79
- const fulfilmentCenter = sftpUser.fulfillmentCenter;
80
- const isDevelopment = sftpUser.isDevelopment;
81
- const folderPath = sftpUser.folderPath;
82
- const folderType = isDevelopment ? 'dev' : 'prd';
83
- let initialDataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
84
- const results = await (0, util_1.getPermittedDirectories)({ path: initialDataPath }, context);
85
- const filesDirectories = results.filter(result => result.Size > 0);
86
- try {
87
- for (var filesDirectories_1 = (e_1 = void 0, tslib_1.__asyncValues(filesDirectories)), filesDirectories_1_1; filesDirectories_1_1 = await filesDirectories_1.next(), !filesDirectories_1_1.done;) {
88
- let fileDirectory = filesDirectories_1_1.value;
89
- let dataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
90
- let successPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUCCESSDATAPATH}/`;
91
- let failedPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.FAILEDDATAPATH}/`;
92
- const fileKey = fileDirectory.Key;
93
- const lastSlashIdx = fileKey.lastIndexOf('/');
94
- const fileString = fileKey.substring(lastSlashIdx + 1, fileKey.length);
95
- try {
96
- const sftp = sftpUser;
97
- let result = await controllers_1.SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString });
98
- let isAccept = result.isAccept;
99
- if (isAccept) {
100
- delete result.isAccept;
101
- if (result) {
102
- let { items: releaseOrders } = await integration_fulfillment_1.FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
103
- customerBizplaceId,
104
- refNo: result.refNo
105
- });
106
- if (releaseOrders) {
107
- result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1);
108
- }
109
- result.requiredDraft = false;
110
- const releaseOrder = await integration_fulfillment_1.FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
111
- customerBizplaceId,
112
- releaseOrder: result
113
- });
114
- if (releaseOrder) {
115
- let movePaths = {
116
- source: (dataPath += fileString),
117
- destination: (successPath += fileString)
118
- };
119
- await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
120
- }
121
- }
122
- }
123
- else {
124
- let movePaths = {
125
- source: (dataPath += fileString),
126
- destination: (failedPath += fileString)
127
- };
128
- await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
129
- }
130
- }
131
- catch (e) {
132
- let movePaths = {
133
- source: (dataPath += fileString),
134
- destination: (failedPath += fileString)
135
- };
136
- await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
137
- }
138
- }
139
- }
140
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
141
- finally {
142
- try {
143
- if (filesDirectories_1_1 && !filesDirectories_1_1.done && (_a = filesDirectories_1.return)) await _a.call(filesDirectories_1);
144
- }
145
- finally { if (e_1) throw e_1.error; }
146
- }
75
+ processSftp(sftpUser, context, customerBizplace.id);
147
76
  }
148
77
  });
149
78
  return true;
150
79
  }
80
+ async syncAllSftpOrders(context) {
81
+ try {
82
+ await (0, typeorm_1.getConnection)().transaction(async (tx) => {
83
+ const sftps = await tx
84
+ .getRepository(sftp_1.Sftp)
85
+ .createQueryBuilder('s')
86
+ .where('s.status = :status', { status: 'ACTIVE' })
87
+ .getMany();
88
+ if (sftps.length === 0)
89
+ return;
90
+ for (const sftp of sftps) {
91
+ const customerBizplace = await getCustomerBizplace(sftp.domainId, tx);
92
+ await processSftp(sftp, context, customerBizplace.id);
93
+ }
94
+ });
95
+ }
96
+ catch (e) {
97
+ console.log(e);
98
+ }
99
+ return true;
100
+ }
151
101
  };
152
102
  tslib_1.__decorate([
153
103
  (0, type_graphql_1.Directive)('@transaction'),
@@ -203,8 +153,96 @@ tslib_1.__decorate([
203
153
  tslib_1.__metadata("design:paramtypes", [String, Object]),
204
154
  tslib_1.__metadata("design:returntype", Promise)
205
155
  ], SftpMutation.prototype, "syncSftpOrders", null);
156
+ tslib_1.__decorate([
157
+ (0, type_graphql_1.Directive)('@transaction'),
158
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'Calls syncSftpOrders for all domain Ids' }),
159
+ tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
160
+ tslib_1.__metadata("design:type", Function),
161
+ tslib_1.__metadata("design:paramtypes", [Object]),
162
+ tslib_1.__metadata("design:returntype", Promise)
163
+ ], SftpMutation.prototype, "syncAllSftpOrders", null);
206
164
  SftpMutation = tslib_1.__decorate([
207
165
  (0, type_graphql_1.Resolver)(sftp_1.Sftp)
208
166
  ], SftpMutation);
209
167
  exports.SftpMutation = SftpMutation;
168
+ async function processSftp(sftpUser, context, customerBizplaceId) {
169
+ var e_1, _a;
170
+ const fulfilmentCenter = sftpUser.fulfillmentCenter;
171
+ const isDevelopment = sftpUser.isDevelopment;
172
+ const folderPath = sftpUser.folderPath;
173
+ const folderType = isDevelopment ? 'dev' : 'prd';
174
+ let initialDataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
175
+ const results = await (0, util_1.getPermittedDirectories)({ path: initialDataPath }, context);
176
+ const filesDirectories = results.filter(result => result.Size > 0);
177
+ try {
178
+ for (var filesDirectories_1 = tslib_1.__asyncValues(filesDirectories), filesDirectories_1_1; filesDirectories_1_1 = await filesDirectories_1.next(), !filesDirectories_1_1.done;) {
179
+ let fileDirectory = filesDirectories_1_1.value;
180
+ let dataPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUBMITDATAPATH}/`;
181
+ let successPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.SUCCESSDATAPATH}/`;
182
+ let failedPath = `${sftpUser.folderPath}/${folderType}${sftp_const_1.FAILEDDATAPATH}/`;
183
+ const fileKey = fileDirectory.Key;
184
+ const lastSlashIdx = fileKey.lastIndexOf('/');
185
+ const fileString = fileKey.substring(lastSlashIdx + 1, fileKey.length);
186
+ try {
187
+ const sftp = sftpUser;
188
+ let result = await controllers_1.SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString });
189
+ let isAccept = result.isAccept;
190
+ if (isAccept) {
191
+ delete result.isAccept;
192
+ if (result) {
193
+ let { items: releaseOrders } = await integration_fulfillment_1.FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {
194
+ customerBizplaceId,
195
+ refNo: result.refNo
196
+ });
197
+ if (releaseOrders) {
198
+ result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1);
199
+ }
200
+ result.requiredDraft = false;
201
+ const releaseOrder = await integration_fulfillment_1.FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {
202
+ customerBizplaceId,
203
+ releaseOrder: result
204
+ });
205
+ if (releaseOrder) {
206
+ let movePaths = {
207
+ source: (dataPath += fileString),
208
+ destination: (successPath += fileString)
209
+ };
210
+ await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
211
+ }
212
+ }
213
+ }
214
+ else {
215
+ let movePaths = {
216
+ source: (dataPath += fileString),
217
+ destination: (failedPath += fileString)
218
+ };
219
+ await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
220
+ }
221
+ }
222
+ catch (e) {
223
+ let movePaths = {
224
+ source: (dataPath += fileString),
225
+ destination: (failedPath += fileString)
226
+ };
227
+ await sftp_const_1.SFTPFILESTORAGE.moveFile(movePaths);
228
+ }
229
+ }
230
+ }
231
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
232
+ finally {
233
+ try {
234
+ if (filesDirectories_1_1 && !filesDirectories_1_1.done && (_a = filesDirectories_1.return)) await _a.call(filesDirectories_1);
235
+ }
236
+ finally { if (e_1) throw e_1.error; }
237
+ }
238
+ }
239
+ exports.processSftp = processSftp;
240
+ async function getCustomerBizplace(customerDomainId, tx) {
241
+ const customerDomain = await tx.getRepository(shell_1.Domain).findOneBy({ id: customerDomainId });
242
+ const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
243
+ where: { domain: customerDomain }
244
+ });
245
+ return customerBizplace;
246
+ }
247
+ exports.getCustomerBizplace = getCustomerBizplace;
210
248
  //# sourceMappingURL=sftp-mutation.js.map
@@ -1 +1 @@
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,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,OAAO,MAAM,EAAE,CAAC,aAAa,CAAC,WAAI,CAAC,CAAC,IAAI,iCACnC,IAAI,KACP,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;IACJ,CAAC;IAID,KAAK,CAAC,UAAU,CAAY,EAAU,EAAgB,KAAgB,EAAS,OAAY;QACzF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,WAAI,CAAC,CAAA;QACzC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YACpC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;SACtB,CAAC,CAAA;QAEF,OAAO,MAAM,UAAU,CAAC,IAAI,+CACvB,IAAI,GACJ,KAAK,KACR,OAAO,EAAE,IAAI,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n\nimport { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, getConnection, In } from 'typeorm'\n\nimport { Bizplace } from '@things-factory/biz-base'\nimport { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'\nimport { Domain } from '@things-factory/shell'\n\nimport { SftpAPI } from '../../controllers'\nimport { FAILEDDATAPATH, SFTPFILESTORAGE, SUBMITDATAPATH, SUCCESSDATAPATH } from '../../sftp-const'\nimport { getPermittedDirectories } from '../../util'\nimport { Sftp } from './sftp'\nimport { NewSftp, SftpPatch } from './sftp-type'\n\n@Resolver(Sftp)\nexport class SftpMutation {\n @Directive('@transaction')\n @Mutation(returns => Sftp, { description: 'To create new Sftp' })\n async createSftp(@Arg('sftp') sftp: NewSftp, @Ctx() context: any): Promise<Sftp> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Sftp).save({\n ...sftp,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Sftp, { description: 'To modify Sftp information' })\n async updateSftp(@Arg('id') id: string, @Arg('patch') patch: SftpPatch, @Ctx() context: any): Promise<Sftp> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Sftp)\n const sftp = await repository.findOne({\n where: { domain, id }\n })\n\n return await repository.save({\n ...sftp,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Sftp], { description: \"To modify multiple Sftps' information\" })\n async updateMultipleSftp(\n @Arg('patches', type => [SftpPatch]) patches: SftpPatch[],\n @Ctx() context: any\n ): Promise<Sftp[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const sftpRepo = tx.getRepository(Sftp)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await sftpRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const sftp = await sftpRepo.findOne(newRecord.id)\n\n const result = await sftpRepo.save({\n ...sftp,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Sftp' })\n async deleteSftp(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Sftp).delete({ domain, id })\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple sftps' })\n async deleteSftps(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Sftp).delete({\n domain,\n id: In(ids)\n })\n\n return true\n }\n\n @Mutation(returns => Boolean, { description: 'To sync all orders from sftp' })\n async syncSftpOrders(\n @Arg('customerDomainId', type => String) customerDomainId: string,\n @Ctx() context: any\n ): Promise<boolean> {\n await getConnection().transaction(async (tx: EntityManager) => {\n const customerDomain: Domain = await tx.getRepository(Domain).findOne(customerDomainId)\n\n const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({\n where: { domain: customerDomain }\n })\n\n const customerBizplaceId: string = customerBizplace.id\n\n const sftpUsers: Sftp[] = await tx.getRepository(Sftp).find({\n where: { domain: customerDomain, status: 'ACTIVE' },\n relations: ['fulfillmentCenter']\n })\n\n for (var i = 0; i < sftpUsers.length; i++) {\n const sftpUser: Sftp = sftpUsers[i]\n\n const fulfilmentCenter: FulfillmentCenter = sftpUser.fulfillmentCenter\n const isDevelopment: boolean = sftpUser.isDevelopment\n const folderPath: string = sftpUser.folderPath\n const folderType: string = isDevelopment ? 'dev' : 'prd'\n let initialDataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`\n const results: any[] = await getPermittedDirectories({ path: initialDataPath }, context)\n const filesDirectories: any[] = results.filter(result => result.Size > 0)\n\n for await (let fileDirectory of filesDirectories) {\n let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`\n let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`\n let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`\n const fileKey: string = fileDirectory.Key\n const lastSlashIdx = fileKey.lastIndexOf('/')\n const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)\n try {\n const sftp: any = sftpUser\n let result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })\n let isAccept: boolean = result.isAccept\n\n if (isAccept) {\n delete result.isAccept\n if (result) {\n let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {\n customerBizplaceId,\n refNo: result.refNo\n })\n\n if (releaseOrders) {\n result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1)\n }\n\n result.requiredDraft = false\n\n const releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {\n customerBizplaceId,\n releaseOrder: result\n })\n\n if (releaseOrder) {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (successPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n }\n } else {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (failedPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n } catch (e) {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (failedPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n }\n }\n })\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"sftp-mutation.js","sourceRoot":"","sources":["../../../server/service/sftp/sftp-mutation.ts"],"names":[],"mappings":";;;;AAAA,yBAAsB;AAEtB,+CAAsE;AACtE,qCAA0D;A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Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, getConnection, In } from 'typeorm'\n\nimport { Bizplace } from '@things-factory/biz-base'\nimport { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'\nimport { Domain } from '@things-factory/shell'\n\nimport { SftpAPI } from '../../controllers'\nimport { FAILEDDATAPATH, SFTPFILESTORAGE, SUBMITDATAPATH, SUCCESSDATAPATH } from '../../sftp-const'\nimport { getPermittedDirectories } from '../../util'\nimport { Sftp, SftpStatus } from './sftp'\nimport { NewSftp, SftpPatch } from './sftp-type'\n\n@Resolver(Sftp)\nexport class SftpMutation {\n @Directive('@transaction')\n @Mutation(returns => Sftp, { description: 'To create new Sftp' })\n async createSftp(@Arg('sftp') sftp: NewSftp, @Ctx() context: ResolverContext): Promise<Sftp> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Sftp).save({\n ...sftp,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Sftp, { description: 'To modify Sftp information' })\n async updateSftp(\n @Arg('id') id: string,\n @Arg('patch') patch: SftpPatch,\n @Ctx() context: ResolverContext\n ): Promise<Sftp> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Sftp)\n const sftp = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n return await repository.save({\n ...sftp,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Sftp], { description: \"To modify multiple Sftps' information\" })\n async updateMultipleSftp(\n @Arg('patches', type => [SftpPatch]) patches: SftpPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Sftp[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const sftpRepo = tx.getRepository(Sftp)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await sftpRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const sftp = await sftpRepo.findOneBy({ id: newRecord.id })\n\n const result = await sftpRepo.save({\n ...sftp,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Sftp' })\n async deleteSftp(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Sftp).delete({ domain: { id: domain.id }, id })\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple sftps' })\n async deleteSftps(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Sftp).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Mutation(returns => Boolean, { description: 'To sync all orders from sftp' })\n async syncSftpOrders(\n @Arg('customerDomainId', type => String) customerDomainId: string,\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n await getConnection().transaction(async (tx: EntityManager) => {\n const customerDomain: Domain = await tx.getRepository(Domain).findOneBy({ id: customerDomainId })\n\n const customerBizplace: Bizplace = await getCustomerBizplace(customerDomainId, tx)\n\n const sftpUsers: Sftp[] = await tx.getRepository(Sftp).find({\n where: { domain: { id: customerDomainId }, status: SftpStatus.ACTIVE },\n relations: ['fulfillmentCenter']\n })\n\n for (var i = 0; i < sftpUsers.length; i++) {\n const sftpUser: Sftp = sftpUsers[i]\n processSftp(sftpUser, context, customerBizplace.id)\n }\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'Calls syncSftpOrders for all domain Ids' })\n async syncAllSftpOrders(@Ctx() context: ResolverContext): Promise<Boolean> {\n try {\n await getConnection().transaction(async tx => {\n const sftps = await tx\n .getRepository(Sftp)\n .createQueryBuilder('s')\n .where('s.status = :status', { status: 'ACTIVE' })\n .getMany()\n\n if (sftps.length === 0) return\n for (const sftp of sftps) {\n const customerBizplace = await getCustomerBizplace(sftp.domainId, tx)\n await processSftp(sftp, context, customerBizplace.id)\n }\n })\n } catch (e) {\n console.log(e)\n }\n return true\n }\n}\n\nexport async function processSftp(sftpUser, context, customerBizplaceId) {\n const fulfilmentCenter: FulfillmentCenter = sftpUser.fulfillmentCenter\n const isDevelopment: boolean = sftpUser.isDevelopment\n const folderPath: string = sftpUser.folderPath\n const folderType: string = isDevelopment ? 'dev' : 'prd'\n let initialDataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`\n const results: any[] = await getPermittedDirectories({ path: initialDataPath }, context)\n const filesDirectories: any[] = results.filter(result => result.Size > 0)\n\n for await (let fileDirectory of filesDirectories) {\n let dataPath: string = `${sftpUser.folderPath}/${folderType}${SUBMITDATAPATH}/`\n let successPath: string = `${sftpUser.folderPath}/${folderType}${SUCCESSDATAPATH}/`\n let failedPath: string = `${sftpUser.folderPath}/${folderType}${FAILEDDATAPATH}/`\n const fileKey: string = fileDirectory.Key\n const lastSlashIdx = fileKey.lastIndexOf('/')\n const fileString: string = fileKey.substring(lastSlashIdx + 1, fileKey.length)\n try {\n const sftp: any = sftpUser\n let result: any = await SftpAPI.getOutboundOrder(sftp, { folderPath, folderType, fileKey: fileString })\n let isAccept: boolean = result.isAccept\n\n if (isAccept) {\n delete result.isAccept\n if (result) {\n let { items: releaseOrders }: any = await FulfillmentAPI.getOutboundOrders(fulfilmentCenter, {\n customerBizplaceId,\n refNo: result.refNo\n })\n\n if (releaseOrders) {\n result.collectionOrderNo = result.collectionOrderNo + ' - ' + (releaseOrders.length + 1)\n }\n\n result.requiredDraft = false\n\n const releaseOrder: any = await FulfillmentAPI.createOutboundOrder(fulfilmentCenter, {\n customerBizplaceId,\n releaseOrder: result\n })\n\n if (releaseOrder) {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (successPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n }\n } else {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (failedPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n } catch (e) {\n let movePaths = {\n source: (dataPath += fileString),\n destination: (failedPath += fileString)\n }\n await SFTPFILESTORAGE.moveFile(movePaths)\n }\n }\n}\n\nexport async function getCustomerBizplace(customerDomainId, tx): Promise<Bizplace> {\n const customerDomain: Domain = await tx.getRepository(Domain).findOneBy({ id: customerDomainId })\n\n const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({\n where: { domain: customerDomain }\n })\n\n return customerBizplace\n}\n"]}
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.SftpQuery = void 0;
5
4
  const tslib_1 = require("tslib");
6
5
  const type_graphql_1 = require("type-graphql");
7
- const typeorm_1 = require("typeorm");
8
6
  const auth_base_1 = require("@things-factory/auth-base");
9
7
  const shell_1 = require("@things-factory/shell");
10
8
  const sftp_1 = require("./sftp");
@@ -12,24 +10,24 @@ const sftp_type_1 = require("./sftp-type");
12
10
  let SftpQuery = class SftpQuery {
13
11
  async sftp(id, context) {
14
12
  const { domain } = context.state;
15
- return await (0, typeorm_1.getRepository)(sftp_1.Sftp).findOne({
16
- where: { domain, id }
13
+ return await (0, shell_1.getRepository)(sftp_1.Sftp).findOne({
14
+ where: { domain: { id: domain.id }, id }
17
15
  });
18
16
  }
19
17
  async sftps(params, context) {
20
18
  const { domain } = context.state;
21
19
  const convertedParams = (0, shell_1.convertListParams)(params, { domain });
22
- const [items, total] = await (0, typeorm_1.getRepository)(sftp_1.Sftp).findAndCount(convertedParams);
20
+ const [items, total] = await (0, shell_1.getRepository)(sftp_1.Sftp).findAndCount(convertedParams);
23
21
  return { items, total };
24
22
  }
25
23
  async domain(sftp) {
26
- return await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(sftp.domainId);
24
+ return await (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: sftp.domainId });
27
25
  }
28
26
  async updater(sftp) {
29
- return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(sftp.updaterId);
27
+ return await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: sftp.updaterId });
30
28
  }
31
29
  async creator(sftp) {
32
- return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(sftp.creatorId);
30
+ return await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: sftp.creatorId });
33
31
  }
34
32
  };
35
33
  tslib_1.__decorate([
@@ -45,7 +43,7 @@ tslib_1.__decorate([
45
43
  tslib_1.__param(0, (0, type_graphql_1.Args)()),
46
44
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
47
45
  tslib_1.__metadata("design:type", Function),
48
- tslib_1.__metadata("design:paramtypes", [typeof (_a = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _a : Object, Object]),
46
+ tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
49
47
  tslib_1.__metadata("design:returntype", Promise)
50
48
  ], SftpQuery.prototype, "sftps", null);
51
49
  tslib_1.__decorate([