repzo-sap-absjo 1.0.8 → 1.0.9

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 (77) hide show
  1. package/lib/actions/create_invoice.d.ts +19 -13
  2. package/lib/actions/create_invoice.js +363 -214
  3. package/lib/actions/create_payment.d.ts +4 -1
  4. package/lib/actions/create_payment.js +200 -125
  5. package/lib/actions/create_proforma.d.ts +4 -1
  6. package/lib/actions/create_proforma.js +290 -165
  7. package/lib/actions/create_return_invoice.d.ts +4 -1
  8. package/lib/actions/create_return_invoice.js +321 -177
  9. package/lib/actions/create_transfer.d.ts +4 -1
  10. package/lib/actions/create_transfer.js +220 -143
  11. package/lib/actions/index.js +23 -15
  12. package/lib/commands/adjust_inventory.d.ts +4 -2
  13. package/lib/commands/adjust_inventory.js +290 -160
  14. package/lib/commands/bank.d.ts +4 -2
  15. package/lib/commands/bank.js +279 -157
  16. package/lib/commands/basic.js +66 -47
  17. package/lib/commands/category.d.ts +3 -1
  18. package/lib/commands/category.js +178 -104
  19. package/lib/commands/channel.d.ts +3 -1
  20. package/lib/commands/channel.js +198 -117
  21. package/lib/commands/client.d.ts +34 -32
  22. package/lib/commands/client.js +404 -244
  23. package/lib/commands/client_disabled.d.ts +3 -1
  24. package/lib/commands/client_disabled.js +163 -94
  25. package/lib/commands/index.d.ts +15 -11
  26. package/lib/commands/index.js +60 -60
  27. package/lib/commands/join.js +192 -66
  28. package/lib/commands/measureunit.d.ts +19 -14
  29. package/lib/commands/measureunit.js +289 -191
  30. package/lib/commands/measureunit_family.d.ts +10 -8
  31. package/lib/commands/measureunit_family.js +250 -138
  32. package/lib/commands/payment_term.d.ts +3 -1
  33. package/lib/commands/payment_term.js +202 -123
  34. package/lib/commands/price_list.d.ts +15 -15
  35. package/lib/commands/price_list.js +612 -326
  36. package/lib/commands/product.d.ts +32 -30
  37. package/lib/commands/product.js +425 -243
  38. package/lib/commands/product_disabled.d.ts +3 -1
  39. package/lib/commands/product_disabled.js +164 -94
  40. package/lib/commands/rep.js +221 -141
  41. package/lib/commands/tag.js +174 -109
  42. package/lib/commands/tax.js +177 -112
  43. package/lib/commands/warehouse.d.ts +3 -1
  44. package/lib/commands/warehouse.js +207 -119
  45. package/lib/index.d.ts +21 -12
  46. package/lib/test/actions/create_invoice.js +193 -188
  47. package/lib/test/actions/create_payment.js +112 -107
  48. package/lib/test/actions/create_proforma.js +220 -216
  49. package/lib/test/actions/create_return_invoice.js +205 -200
  50. package/lib/test/actions/create_transfer.js +120 -115
  51. package/lib/test/commands/adjust_inventory.js +90 -90
  52. package/lib/test/commands/bank.js +90 -90
  53. package/lib/test/commands/basic.js +328 -327
  54. package/lib/test/commands/category.js +90 -90
  55. package/lib/test/commands/channel.js +90 -90
  56. package/lib/test/commands/client.js +355 -353
  57. package/lib/test/commands/client_disabled.js +90 -90
  58. package/lib/test/commands/join.js +328 -327
  59. package/lib/test/commands/measureunit.js +90 -90
  60. package/lib/test/commands/measureunit_family.js +90 -90
  61. package/lib/test/commands/payment_term.js +90 -90
  62. package/lib/test/commands/price_list.js +337 -334
  63. package/lib/test/commands/product.js +90 -90
  64. package/lib/test/commands/product_disabled.js +90 -90
  65. package/lib/test/commands/rep.js +346 -344
  66. package/lib/test/commands/tag.js +90 -90
  67. package/lib/test/commands/tax.js +90 -90
  68. package/lib/test/commands/warehouse.js +90 -90
  69. package/lib/types.d.ts +83 -60
  70. package/lib/util.d.ts +70 -19
  71. package/lib/util.js +170 -144
  72. package/package.json +1 -1
  73. package/src/actions/create_invoice.ts +4 -13
  74. package/src/actions/create_payment.ts +4 -13
  75. package/src/actions/create_proforma.ts +28 -40
  76. package/src/actions/create_return_invoice.ts +4 -16
  77. package/src/actions/create_transfer.ts +24 -36
@@ -1,2 +1,4 @@
1
1
  import { CommandEvent, Result } from "../types";
2
- export declare const sync_disabled_product: (commandEvent: CommandEvent) => Promise<Result>;
2
+ export declare const sync_disabled_product: (
3
+ commandEvent: CommandEvent
4
+ ) => Promise<Result>;
@@ -1,101 +1,171 @@
1
1
  import Repzo from "repzo";
2
- import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
2
+ import {
3
+ _create,
4
+ update_bench_time,
5
+ date_formatting,
6
+ set_error,
7
+ } from "../util.js";
3
8
  export const sync_disabled_product = async (commandEvent) => {
4
- var _a, _b, _c;
5
- const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
6
- env: commandEvent.env,
7
- });
8
- const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
9
- try {
10
- // console.log("sync_disabled_product");
11
- const new_bench_time = new Date().toISOString();
12
- const bench_time_key = "bench_time_product_disabled";
13
- await commandLog.load(commandEvent.sync_id);
14
- await commandLog
15
- .addDetail("Repzo SAP: Started Syncing Disabled Products")
16
- .commit();
17
- const nameSpace = commandEvent.nameSpace.join("_");
18
- const result = {
19
- sap_total: 0,
20
- repzo_total: 0,
21
- created: 0,
22
- updated: 0,
23
- failed: 0,
24
- };
25
- const failed_docs_report = [];
26
- const sap_products = await get_sap_disabled_products(commandEvent.app.formData.sapHostUrl, { updateAt: commandEvent.app.options_formData[bench_time_key] });
27
- result.sap_total = sap_products === null || sap_products === void 0 ? void 0 : sap_products.length;
28
- await commandLog
29
- .addDetail(`${result.sap_total} Disabled Products in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
30
- .commit();
31
- const sap_product_query = sap_products === null || sap_products === void 0 ? void 0 : sap_products.map((product) => `${nameSpace}_${product.ITEMCODE}`);
32
- const repzo_products = [];
33
- const per_page = 200;
34
- const pages = Math.ceil(sap_product_query.length / per_page);
35
- for (let i = 0; i < pages; i += per_page) {
36
- const repzo_product_per_page = await repzo.product.find({
37
- active: true,
38
- per_page: 50000,
39
- "integration_meta.id": sap_product_query.slice(i, i + per_page),
40
- });
41
- if ((_b = repzo_product_per_page === null || repzo_product_per_page === void 0 ? void 0 : repzo_product_per_page.data) === null || _b === void 0 ? void 0 : _b.length)
42
- repzo_products.push(...repzo_product_per_page.data);
43
- }
44
- result.repzo_total = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.length;
45
- await commandLog
46
- .addDetail(`${result.repzo_total} Active Products in Repzo should be disabled`)
47
- .commit();
48
- for (let i = 0; i < (sap_products === null || sap_products === void 0 ? void 0 : sap_products.length); i++) {
49
- const sap_product = sap_products[i];
50
- const repzo_product = repzo_products.find((r_product) => {
51
- var _a;
52
- return ((_a = r_product === null || r_product === void 0 ? void 0 : r_product.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
53
- `${nameSpace}_${sap_product.ITEMCODE}`;
54
- });
55
- if (repzo_product) {
56
- // Update
57
- try {
58
- const disabled_product = await repzo.product.remove(repzo_product._id);
59
- result.updated++;
60
- }
61
- catch (e) {
62
- // console.log("Disabled Product Failed >> ", e?.response?.data, {
63
- // ITEMCODE: sap_product.ITEMCODE,
64
- // });
65
- failed_docs_report.push({
66
- method: "delete",
67
- doc_id: repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product._id,
68
- doc: { ITEMCODE: sap_product.ITEMCODE },
69
- error_message: set_error(e),
70
- });
71
- result.failed++;
72
- }
73
- }
74
- }
75
- // console.log(result);
76
- await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
77
- await commandLog
78
- .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
79
- .setBody(result)
80
- .commit();
81
- return result;
9
+ var _a, _b, _c;
10
+ const repzo = new Repzo(
11
+ (_a = commandEvent.app.formData) === null || _a === void 0
12
+ ? void 0
13
+ : _a.repzoApiKey,
14
+ {
15
+ env: commandEvent.env,
16
+ }
17
+ );
18
+ const commandLog = new Repzo.CommandLog(
19
+ repzo,
20
+ commandEvent.app,
21
+ commandEvent.command
22
+ );
23
+ try {
24
+ // console.log("sync_disabled_product");
25
+ const new_bench_time = new Date().toISOString();
26
+ const bench_time_key = "bench_time_product_disabled";
27
+ await commandLog.load(commandEvent.sync_id);
28
+ await commandLog
29
+ .addDetail("Repzo SAP: Started Syncing Disabled Products")
30
+ .commit();
31
+ const nameSpace = commandEvent.nameSpace.join("_");
32
+ const result = {
33
+ sap_total: 0,
34
+ repzo_total: 0,
35
+ created: 0,
36
+ updated: 0,
37
+ failed: 0,
38
+ };
39
+ const failed_docs_report = [];
40
+ const sap_products = await get_sap_disabled_products(
41
+ commandEvent.app.formData.sapHostUrl,
42
+ { updateAt: commandEvent.app.options_formData[bench_time_key] }
43
+ );
44
+ result.sap_total =
45
+ sap_products === null || sap_products === void 0
46
+ ? void 0
47
+ : sap_products.length;
48
+ await commandLog
49
+ .addDetail(
50
+ `${result.sap_total} Disabled Products in SAP changed since ${
51
+ commandEvent.app.options_formData[bench_time_key] || "ever"
52
+ }`
53
+ )
54
+ .commit();
55
+ const sap_product_query =
56
+ sap_products === null || sap_products === void 0
57
+ ? void 0
58
+ : sap_products.map((product) => `${nameSpace}_${product.ITEMCODE}`);
59
+ const repzo_products = [];
60
+ const per_page = 200;
61
+ const pages = Math.ceil(sap_product_query.length / per_page);
62
+ for (let i = 0; i < pages; i += per_page) {
63
+ const repzo_product_per_page = await repzo.product.find({
64
+ active: true,
65
+ per_page: 50000,
66
+ "integration_meta.id": sap_product_query.slice(i, i + per_page),
67
+ });
68
+ if (
69
+ (_b =
70
+ repzo_product_per_page === null || repzo_product_per_page === void 0
71
+ ? void 0
72
+ : repzo_product_per_page.data) === null || _b === void 0
73
+ ? void 0
74
+ : _b.length
75
+ )
76
+ repzo_products.push(...repzo_product_per_page.data);
82
77
  }
83
- catch (e) {
84
- //@ts-ignore
85
- console.error(((_c = e === null || e === void 0 ? void 0 : e.response) === null || _c === void 0 ? void 0 : _c.data) || e);
86
- await commandLog.setStatus("fail", e).commit();
87
- throw e;
78
+ result.repzo_total =
79
+ repzo_products === null || repzo_products === void 0
80
+ ? void 0
81
+ : repzo_products.length;
82
+ await commandLog
83
+ .addDetail(
84
+ `${result.repzo_total} Active Products in Repzo should be disabled`
85
+ )
86
+ .commit();
87
+ for (
88
+ let i = 0;
89
+ i <
90
+ (sap_products === null || sap_products === void 0
91
+ ? void 0
92
+ : sap_products.length);
93
+ i++
94
+ ) {
95
+ const sap_product = sap_products[i];
96
+ const repzo_product = repzo_products.find((r_product) => {
97
+ var _a;
98
+ return (
99
+ ((_a =
100
+ r_product === null || r_product === void 0
101
+ ? void 0
102
+ : r_product.integration_meta) === null || _a === void 0
103
+ ? void 0
104
+ : _a.id) == `${nameSpace}_${sap_product.ITEMCODE}`
105
+ );
106
+ });
107
+ if (repzo_product) {
108
+ // Update
109
+ try {
110
+ const disabled_product = await repzo.product.remove(
111
+ repzo_product._id
112
+ );
113
+ result.updated++;
114
+ } catch (e) {
115
+ // console.log("Disabled Product Failed >> ", e?.response?.data, {
116
+ // ITEMCODE: sap_product.ITEMCODE,
117
+ // });
118
+ failed_docs_report.push({
119
+ method: "delete",
120
+ doc_id:
121
+ repzo_product === null || repzo_product === void 0
122
+ ? void 0
123
+ : repzo_product._id,
124
+ doc: { ITEMCODE: sap_product.ITEMCODE },
125
+ error_message: set_error(e),
126
+ });
127
+ result.failed++;
128
+ }
129
+ }
88
130
  }
131
+ // console.log(result);
132
+ await update_bench_time(
133
+ repzo,
134
+ commandEvent.app._id,
135
+ bench_time_key,
136
+ new_bench_time
137
+ );
138
+ await commandLog
139
+ .setStatus(
140
+ "success",
141
+ failed_docs_report.length ? failed_docs_report : null
142
+ )
143
+ .setBody(result)
144
+ .commit();
145
+ return result;
146
+ } catch (e) {
147
+ //@ts-ignore
148
+ console.error(
149
+ ((_c = e === null || e === void 0 ? void 0 : e.response) === null ||
150
+ _c === void 0
151
+ ? void 0
152
+ : _c.data) || e
153
+ );
154
+ await commandLog.setStatus("fail", e).commit();
155
+ throw e;
156
+ }
89
157
  };
90
158
  const get_sap_disabled_products = async (serviceEndPoint, query) => {
91
- try {
92
- const sap_products = await _create(serviceEndPoint, "/Items", {
93
- Active: "N",
94
- UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
95
- });
96
- return sap_products.Items;
97
- }
98
- catch (e) {
99
- throw e;
100
- }
159
+ try {
160
+ const sap_products = await _create(serviceEndPoint, "/Items", {
161
+ Active: "N",
162
+ UpdateAt: date_formatting(
163
+ query === null || query === void 0 ? void 0 : query.updateAt,
164
+ "YYYYMMDD:HHmmss"
165
+ ),
166
+ });
167
+ return sap_products.Items;
168
+ } catch (e) {
169
+ throw e;
170
+ }
101
171
  };
@@ -1,151 +1,231 @@
1
1
  import Repzo from "repzo";
2
2
  import DataSet from "data-set-query";
3
- import { _create, update_bench_time, set_error, } from "../util.js";
3
+ import { _create, update_bench_time, set_error } from "../util.js";
4
4
  export const sync_rep = async (commandEvent) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
- const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
7
- env: commandEvent.env,
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
+ const repzo = new Repzo(
7
+ (_a = commandEvent.app.formData) === null || _a === void 0
8
+ ? void 0
9
+ : _a.repzoApiKey,
10
+ {
11
+ env: commandEvent.env,
12
+ }
13
+ );
14
+ const commandLog = new Repzo.CommandLog(
15
+ repzo,
16
+ commandEvent.app,
17
+ commandEvent.command
18
+ );
19
+ try {
20
+ // console.log("sync_rep");
21
+ const new_bench_time = new Date().toISOString();
22
+ const bench_time_key = "bench_time_rep";
23
+ await commandLog.load(commandEvent.sync_id);
24
+ await commandLog.addDetail("Repzo SAP: Started Syncing Reps").commit();
25
+ const nameSpace = commandEvent.nameSpace.join("_");
26
+ const result = {
27
+ sap_total: 0,
28
+ repzo_total: 0,
29
+ created: 0,
30
+ updated: 0,
31
+ failed: 0,
32
+ };
33
+ const failed_docs_report = [];
34
+ const sap_reps = await get_sap_reps(
35
+ commandEvent.app.formData.sapHostUrl,
36
+ {}
37
+ );
38
+ result.sap_total =
39
+ (_b =
40
+ sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
41
+ null || _b === void 0
42
+ ? void 0
43
+ : _b.length;
44
+ await commandLog.addDetail(`${result.sap_total} reps in SAP`).commit();
45
+ // hard code ************************************
46
+ // sap_reps?.Users?.forEach((sap_rep) => {
47
+ // if (
48
+ // sap_rep.USERDESC.startsWith("WS ") ||
49
+ // sap_rep.USERDESC.startsWith("RET ")
50
+ // ) {
51
+ // sap_rep.USERWHSCODE = "1";
52
+ // }
53
+ // if (sap_rep.USERDESC.startsWith("MT ")) {
54
+ // sap_rep.USERWHSCODE = "K.A";
55
+ // }
56
+ // });
57
+ // **********************************************
58
+ const db = new DataSet([], { autoIndex: false });
59
+ db.createIndex({
60
+ USERID: true,
61
+ USERDESC: true,
62
+ DEPARTMENTCODE: true,
63
+ USERCASHACCOUNT: true,
64
+ USERCHECKACCTCODE: true,
65
+ USERWHSCODE: true,
8
66
  });
9
- const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
10
- try {
11
- // console.log("sync_rep");
12
- const new_bench_time = new Date().toISOString();
13
- const bench_time_key = "bench_time_rep";
14
- await commandLog.load(commandEvent.sync_id);
15
- await commandLog.addDetail("Repzo SAP: Started Syncing Reps").commit();
16
- const nameSpace = commandEvent.nameSpace.join("_");
17
- const result = {
18
- sap_total: 0,
19
- repzo_total: 0,
20
- created: 0,
21
- updated: 0,
22
- failed: 0,
23
- };
24
- const failed_docs_report = [];
25
- const sap_reps = await get_sap_reps(commandEvent.app.formData.sapHostUrl, {});
26
- result.sap_total = (_b = sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) === null || _b === void 0 ? void 0 : _b.length;
27
- await commandLog.addDetail(`${result.sap_total} reps in SAP`).commit();
28
- // hard code ************************************
29
- // sap_reps?.Users?.forEach((sap_rep) => {
30
- // if (
31
- // sap_rep.USERDESC.startsWith("WS ") ||
32
- // sap_rep.USERDESC.startsWith("RET ")
33
- // ) {
34
- // sap_rep.USERWHSCODE = "1";
35
- // }
36
- // if (sap_rep.USERDESC.startsWith("MT ")) {
37
- // sap_rep.USERWHSCODE = "K.A";
38
- // }
39
- // });
40
- // **********************************************
41
- const db = new DataSet([], { autoIndex: false });
42
- db.createIndex({
43
- USERID: true,
44
- USERDESC: true,
45
- DEPARTMENTCODE: true,
46
- USERCASHACCOUNT: true,
47
- USERCHECKACCTCODE: true,
48
- USERWHSCODE: true,
67
+ db.load(sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users);
68
+ const repzo_reps = await repzo.rep.find({ per_page: 50000 });
69
+ result.repzo_total =
70
+ (_c =
71
+ repzo_reps === null || repzo_reps === void 0
72
+ ? void 0
73
+ : repzo_reps.data) === null || _c === void 0
74
+ ? void 0
75
+ : _c.length;
76
+ await commandLog
77
+ .addDetail(
78
+ `${
79
+ (_d =
80
+ repzo_reps === null || repzo_reps === void 0
81
+ ? void 0
82
+ : repzo_reps.data) === null || _d === void 0
83
+ ? void 0
84
+ : _d.length
85
+ } reps in Repzo`
86
+ )
87
+ .commit();
88
+ for (
89
+ let i = 0;
90
+ i <
91
+ ((_e =
92
+ sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
93
+ null || _e === void 0
94
+ ? void 0
95
+ : _e.length);
96
+ i++
97
+ ) {
98
+ const sap_rep = sap_reps.Users[i];
99
+ const repzo_rep = repzo_reps.data.find((r_rep) => {
100
+ var _a;
101
+ return (
102
+ ((_a = r_rep.integration_meta) === null || _a === void 0
103
+ ? void 0
104
+ : _a.id) == `${nameSpace}_${sap_rep.USERID}`
105
+ );
106
+ });
107
+ let warehouse;
108
+ if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
109
+ const warehouse_res = await repzo.warehouse.find({
110
+ code: sap_rep.USERWHSCODE,
49
111
  });
50
- db.load(sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users);
51
- const repzo_reps = await repzo.rep.find({ per_page: 50000 });
52
- result.repzo_total = (_c = repzo_reps === null || repzo_reps === void 0 ? void 0 : repzo_reps.data) === null || _c === void 0 ? void 0 : _c.length;
53
- await commandLog
54
- .addDetail(`${(_d = repzo_reps === null || repzo_reps === void 0 ? void 0 : repzo_reps.data) === null || _d === void 0 ? void 0 : _d.length} reps in Repzo`)
55
- .commit();
56
- for (let i = 0; i < ((_e = sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) === null || _e === void 0 ? void 0 : _e.length); i++) {
57
- const sap_rep = sap_reps.Users[i];
58
- const repzo_rep = repzo_reps.data.find((r_rep) => { var _a; return ((_a = r_rep.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_rep.USERID}`; });
59
- let warehouse;
60
- if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
61
- const warehouse_res = await repzo.warehouse.find({
62
- code: sap_rep.USERWHSCODE,
63
- });
64
- if ((_f = warehouse_res === null || warehouse_res === void 0 ? void 0 : warehouse_res.data) === null || _f === void 0 ? void 0 : _f.length)
65
- warehouse = warehouse_res.data[0]._id;
66
- }
67
- const body = {
68
- name: sap_rep.USERDESC,
69
- password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
70
- username: nameSpace + sap_rep.USERID,
71
- integration_id: (_g = sap_rep.USERID) === null || _g === void 0 ? void 0 : _g.toString(),
72
- integration_meta: {
73
- DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
74
- USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
75
- USERCHECKACCTCODE: sap_rep.USERCHECKACCTCODE,
76
- USERWHSCODE: sap_rep.USERWHSCODE,
77
- id: `${nameSpace}_${sap_rep.USERID}`,
78
- },
79
- assigned_warehouse: warehouse,
80
- company_namespace: [nameSpace],
81
- };
82
- if (!repzo_rep) {
83
- // Create
84
- try {
85
- const created_rep = await repzo.rep.create(body);
86
- result.created++;
87
- }
88
- catch (e) {
89
- // console.log("Create Rep Failed >> ", e?.response, body);
90
- failed_docs_report.push({
91
- method: "create",
92
- doc: body,
93
- error_message: set_error(e),
94
- });
95
- result.failed++;
96
- }
97
- }
98
- else {
99
- const found_identical_docs = db.search({
100
- USERID: repzo_rep.integration_id,
101
- USERDESC: repzo_rep.name,
102
- DEPARTMENTCODE: (_h = repzo_rep.integration_meta) === null || _h === void 0 ? void 0 : _h.DEPARTMENTCODE,
103
- USERCASHACCOUNT: (_j = repzo_rep.integration_meta) === null || _j === void 0 ? void 0 : _j.USERCASHACCOUNT,
104
- USERCHECKACCTCODE: (_k = repzo_rep.integration_meta) === null || _k === void 0 ? void 0 : _k.USERCHECKACCTCODE,
105
- USERWHSCODE: (_l = repzo_rep.integration_meta) === null || _l === void 0 ? void 0 : _l.USERWHSCODE,
106
- });
107
- if (found_identical_docs.length)
108
- continue;
109
- // Update
110
- try {
111
- // Delete Rep.Password
112
- delete body.password;
113
- const updated_rep = await repzo.rep.update(repzo_rep._id, body);
114
- result.updated++;
115
- }
116
- catch (e) {
117
- // console.log("Update Rep Failed >> ", e?.response?.data, body);
118
- failed_docs_report.push({
119
- method: "update",
120
- doc_id: repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep._id,
121
- doc: body,
122
- error_message: set_error(e),
123
- });
124
- result.failed++;
125
- }
126
- }
112
+ if (
113
+ (_f =
114
+ warehouse_res === null || warehouse_res === void 0
115
+ ? void 0
116
+ : warehouse_res.data) === null || _f === void 0
117
+ ? void 0
118
+ : _f.length
119
+ )
120
+ warehouse = warehouse_res.data[0]._id;
121
+ }
122
+ const body = {
123
+ name: sap_rep.USERDESC,
124
+ password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
125
+ username: nameSpace + sap_rep.USERID,
126
+ integration_id:
127
+ (_g = sap_rep.USERID) === null || _g === void 0
128
+ ? void 0
129
+ : _g.toString(),
130
+ integration_meta: {
131
+ DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
132
+ USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
133
+ USERCHECKACCTCODE: sap_rep.USERCHECKACCTCODE,
134
+ USERWHSCODE: sap_rep.USERWHSCODE,
135
+ id: `${nameSpace}_${sap_rep.USERID}`,
136
+ },
137
+ assigned_warehouse: warehouse,
138
+ company_namespace: [nameSpace],
139
+ };
140
+ if (!repzo_rep) {
141
+ // Create
142
+ try {
143
+ const created_rep = await repzo.rep.create(body);
144
+ result.created++;
145
+ } catch (e) {
146
+ // console.log("Create Rep Failed >> ", e?.response, body);
147
+ failed_docs_report.push({
148
+ method: "create",
149
+ doc: body,
150
+ error_message: set_error(e),
151
+ });
152
+ result.failed++;
127
153
  }
128
- // console.log(result);
129
- await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
130
- await commandLog
131
- .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
132
- .setBody(result)
133
- .commit();
134
- return result;
135
- }
136
- catch (e) {
137
- //@ts-ignore
138
- console.error(((_m = e === null || e === void 0 ? void 0 : e.response) === null || _m === void 0 ? void 0 : _m.data) || e);
139
- await commandLog.setStatus("fail", e).commit();
140
- throw e;
154
+ } else {
155
+ const found_identical_docs = db.search({
156
+ USERID: repzo_rep.integration_id,
157
+ USERDESC: repzo_rep.name,
158
+ DEPARTMENTCODE:
159
+ (_h = repzo_rep.integration_meta) === null || _h === void 0
160
+ ? void 0
161
+ : _h.DEPARTMENTCODE,
162
+ USERCASHACCOUNT:
163
+ (_j = repzo_rep.integration_meta) === null || _j === void 0
164
+ ? void 0
165
+ : _j.USERCASHACCOUNT,
166
+ USERCHECKACCTCODE:
167
+ (_k = repzo_rep.integration_meta) === null || _k === void 0
168
+ ? void 0
169
+ : _k.USERCHECKACCTCODE,
170
+ USERWHSCODE:
171
+ (_l = repzo_rep.integration_meta) === null || _l === void 0
172
+ ? void 0
173
+ : _l.USERWHSCODE,
174
+ });
175
+ if (found_identical_docs.length) continue;
176
+ // Update
177
+ try {
178
+ // Delete Rep.Password
179
+ delete body.password;
180
+ const updated_rep = await repzo.rep.update(repzo_rep._id, body);
181
+ result.updated++;
182
+ } catch (e) {
183
+ // console.log("Update Rep Failed >> ", e?.response?.data, body);
184
+ failed_docs_report.push({
185
+ method: "update",
186
+ doc_id:
187
+ repzo_rep === null || repzo_rep === void 0
188
+ ? void 0
189
+ : repzo_rep._id,
190
+ doc: body,
191
+ error_message: set_error(e),
192
+ });
193
+ result.failed++;
194
+ }
195
+ }
141
196
  }
197
+ // console.log(result);
198
+ await update_bench_time(
199
+ repzo,
200
+ commandEvent.app._id,
201
+ bench_time_key,
202
+ new_bench_time
203
+ );
204
+ await commandLog
205
+ .setStatus(
206
+ "success",
207
+ failed_docs_report.length ? failed_docs_report : null
208
+ )
209
+ .setBody(result)
210
+ .commit();
211
+ return result;
212
+ } catch (e) {
213
+ //@ts-ignore
214
+ console.error(
215
+ ((_m = e === null || e === void 0 ? void 0 : e.response) === null ||
216
+ _m === void 0
217
+ ? void 0
218
+ : _m.data) || e
219
+ );
220
+ await commandLog.setStatus("fail", e).commit();
221
+ throw e;
222
+ }
142
223
  };
143
224
  const get_sap_reps = async (serviceEndPoint, query) => {
144
- try {
145
- const sap_reps = await _create(serviceEndPoint, "/Users", {});
146
- return sap_reps;
147
- }
148
- catch (e) {
149
- throw e;
150
- }
225
+ try {
226
+ const sap_reps = await _create(serviceEndPoint, "/Users", {});
227
+ return sap_reps;
228
+ } catch (e) {
229
+ throw e;
230
+ }
151
231
  };