repzo-sap-absjo 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +207 -365
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +107 -195
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +146 -285
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +158 -312
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +126 -223
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +48 -67
- package/lib/commands/brand.d.ts +1 -3
- package/lib/commands/brand.js +100 -174
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +62 -62
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +326 -612
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +263 -485
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -160
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/brand.js +90 -90
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +334 -337
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +53 -77
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
package/lib/commands/brand.js
CHANGED
|
@@ -1,181 +1,107 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create, update_bench_time, set_error } from "../util.js";
|
|
2
|
+
import { _create, update_bench_time, set_error, } from "../util.js";
|
|
3
3
|
export const sync_brand = async (commandEvent) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!repzo_brand) {
|
|
84
|
-
// Create
|
|
85
|
-
try {
|
|
86
|
-
const created_brand = await repzo.brand.create(body);
|
|
87
|
-
result.created++;
|
|
88
|
-
} catch (e) {
|
|
89
|
-
// console.log("Create Brand 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
|
-
} else {
|
|
98
|
-
if (
|
|
99
|
-
((_d =
|
|
100
|
-
repzo_brand === null || repzo_brand === void 0
|
|
101
|
-
? void 0
|
|
102
|
-
: repzo_brand.integration_meta) === null || _d === void 0
|
|
103
|
-
? void 0
|
|
104
|
-
: _d.id) ==
|
|
105
|
-
((_e =
|
|
106
|
-
body === null || body === void 0
|
|
107
|
-
? void 0
|
|
108
|
-
: body.integration_meta) === null || _e === void 0
|
|
109
|
-
? void 0
|
|
110
|
-
: _e.id) &&
|
|
111
|
-
(repzo_brand === null || repzo_brand === void 0
|
|
112
|
-
? void 0
|
|
113
|
-
: repzo_brand.name) ==
|
|
114
|
-
(body === null || body === void 0 ? void 0 : body.name) &&
|
|
115
|
-
(repzo_brand === null || repzo_brand === void 0
|
|
116
|
-
? void 0
|
|
117
|
-
: repzo_brand.disabled) == false
|
|
118
|
-
) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
// Update
|
|
122
|
-
try {
|
|
123
|
-
const updated_brand = await repzo.brand.update(repzo_brand._id, body);
|
|
124
|
-
result.updated++;
|
|
125
|
-
} catch (e) {
|
|
126
|
-
// console.log(
|
|
127
|
-
// "Update Brand Failed >> ",
|
|
128
|
-
// e?.response?.data,
|
|
129
|
-
// body
|
|
130
|
-
// );
|
|
131
|
-
failed_docs_report.push({
|
|
132
|
-
method: "update",
|
|
133
|
-
doc_id:
|
|
134
|
-
repzo_brand === null || repzo_brand === void 0
|
|
135
|
-
? void 0
|
|
136
|
-
: repzo_brand._id,
|
|
137
|
-
doc: body,
|
|
138
|
-
error_message: set_error(e),
|
|
139
|
-
});
|
|
140
|
-
result.failed++;
|
|
4
|
+
var _a, _b, _c, _d, _e, _f;
|
|
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_brand");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_brand";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Brands").commit();
|
|
15
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
16
|
+
const result = {
|
|
17
|
+
sap_total: 0,
|
|
18
|
+
repzo_total: 0,
|
|
19
|
+
created: 0,
|
|
20
|
+
updated: 0,
|
|
21
|
+
failed: 0,
|
|
22
|
+
};
|
|
23
|
+
const failed_docs_report = [];
|
|
24
|
+
const sap_brands = await get_sap_brands(commandEvent.app.formData.sapHostUrl, {});
|
|
25
|
+
result.sap_total = sap_brands === null || sap_brands === void 0 ? void 0 : sap_brands.length;
|
|
26
|
+
await commandLog.addDetail(`${result.sap_total} Brands in SAP`).commit();
|
|
27
|
+
const repzo_brands = await repzo.brand.find({ per_page: 50000 });
|
|
28
|
+
result.repzo_total = (_b = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
29
|
+
await commandLog
|
|
30
|
+
.addDetail(`${(_c = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _c === void 0 ? void 0 : _c.length} Brand in Repzo`)
|
|
31
|
+
.commit();
|
|
32
|
+
for (let i = 0; i < (sap_brands === null || sap_brands === void 0 ? void 0 : sap_brands.length); i++) {
|
|
33
|
+
const sap_brand = sap_brands[i];
|
|
34
|
+
const repzo_brand = repzo_brands.data.find((r_cat) => { var _a; return ((_a = r_cat.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_brand.U_Code}`; });
|
|
35
|
+
const body = {
|
|
36
|
+
name: sap_brand.Name,
|
|
37
|
+
disabled: false,
|
|
38
|
+
integration_meta: { id: `${nameSpace}_${sap_brand.U_Code}` },
|
|
39
|
+
company_namespace: [nameSpace],
|
|
40
|
+
};
|
|
41
|
+
if (!repzo_brand) {
|
|
42
|
+
// Create
|
|
43
|
+
try {
|
|
44
|
+
const created_brand = await repzo.brand.create(body);
|
|
45
|
+
result.created++;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
// console.log("Create Brand Failed >> ", e?.response, body);
|
|
49
|
+
failed_docs_report.push({
|
|
50
|
+
method: "create",
|
|
51
|
+
doc: body,
|
|
52
|
+
error_message: set_error(e),
|
|
53
|
+
});
|
|
54
|
+
result.failed++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (((_d = repzo_brand === null || repzo_brand === void 0 ? void 0 : repzo_brand.integration_meta) === null || _d === void 0 ? void 0 : _d.id) == ((_e = body === null || body === void 0 ? void 0 : body.integration_meta) === null || _e === void 0 ? void 0 : _e.id) &&
|
|
59
|
+
(repzo_brand === null || repzo_brand === void 0 ? void 0 : repzo_brand.name) == (body === null || body === void 0 ? void 0 : body.name) &&
|
|
60
|
+
(repzo_brand === null || repzo_brand === void 0 ? void 0 : repzo_brand.disabled) == false) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// Update
|
|
64
|
+
try {
|
|
65
|
+
const updated_brand = await repzo.brand.update(repzo_brand._id, body);
|
|
66
|
+
result.updated++;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// console.log(
|
|
70
|
+
// "Update Brand Failed >> ",
|
|
71
|
+
// e?.response?.data,
|
|
72
|
+
// body
|
|
73
|
+
// );
|
|
74
|
+
failed_docs_report.push({
|
|
75
|
+
method: "update",
|
|
76
|
+
doc_id: repzo_brand === null || repzo_brand === void 0 ? void 0 : repzo_brand._id,
|
|
77
|
+
doc: body,
|
|
78
|
+
error_message: set_error(e),
|
|
79
|
+
});
|
|
80
|
+
result.failed++;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
141
83
|
}
|
|
142
|
-
|
|
84
|
+
// console.log(result);
|
|
85
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
86
|
+
await commandLog
|
|
87
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
88
|
+
.setBody(result)
|
|
89
|
+
.commit();
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
console.error(((_f = e === null || e === void 0 ? void 0 : e.response) === null || _f === void 0 ? void 0 : _f.data) || e);
|
|
95
|
+
await commandLog.setStatus("fail", e).commit();
|
|
96
|
+
throw e;
|
|
143
97
|
}
|
|
144
|
-
// console.log(result);
|
|
145
|
-
await update_bench_time(
|
|
146
|
-
repzo,
|
|
147
|
-
commandEvent.app._id,
|
|
148
|
-
bench_time_key,
|
|
149
|
-
new_bench_time
|
|
150
|
-
);
|
|
151
|
-
await commandLog
|
|
152
|
-
.setStatus(
|
|
153
|
-
"success",
|
|
154
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
155
|
-
)
|
|
156
|
-
.setBody(result)
|
|
157
|
-
.commit();
|
|
158
|
-
return result;
|
|
159
|
-
} catch (e) {
|
|
160
|
-
//@ts-ignore
|
|
161
|
-
console.error(
|
|
162
|
-
((_f = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
163
|
-
_f === void 0
|
|
164
|
-
? void 0
|
|
165
|
-
: _f.data) || e
|
|
166
|
-
);
|
|
167
|
-
await commandLog.setStatus("fail", e).commit();
|
|
168
|
-
throw e;
|
|
169
|
-
}
|
|
170
98
|
};
|
|
171
99
|
const get_sap_brands = async (serviceEndPoint, query) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
throw e;
|
|
180
|
-
}
|
|
100
|
+
try {
|
|
101
|
+
const sap_brands = await _create(serviceEndPoint, "/ParentCategory", { UpdateAt: "20201230:000000", Active: "Y" });
|
|
102
|
+
return sap_brands.ItemSubGroup;
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
throw e;
|
|
106
|
+
}
|
|
181
107
|
};
|
package/lib/commands/category.js
CHANGED
|
@@ -1,186 +1,112 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create, update_bench_time, set_error } from "../util.js";
|
|
2
|
+
import { _create, update_bench_time, set_error, } from "../util.js";
|
|
3
3
|
export const sync_category = async (commandEvent) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
? void 0
|
|
8
|
-
: _a.repzoApiKey,
|
|
9
|
-
{
|
|
10
|
-
env: commandEvent.env,
|
|
11
|
-
}
|
|
12
|
-
);
|
|
13
|
-
const commandLog = new Repzo.CommandLog(
|
|
14
|
-
repzo,
|
|
15
|
-
commandEvent.app,
|
|
16
|
-
commandEvent.command
|
|
17
|
-
);
|
|
18
|
-
try {
|
|
19
|
-
// console.log("sync_category");
|
|
20
|
-
const new_bench_time = new Date().toISOString();
|
|
21
|
-
const bench_time_key = "bench_time_category";
|
|
22
|
-
await commandLog.load(commandEvent.sync_id);
|
|
23
|
-
await commandLog
|
|
24
|
-
.addDetail("Repzo SAP: Started Syncing Product Categories")
|
|
25
|
-
.commit();
|
|
26
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
27
|
-
const result = {
|
|
28
|
-
sap_total: 0,
|
|
29
|
-
repzo_total: 0,
|
|
30
|
-
created: 0,
|
|
31
|
-
updated: 0,
|
|
32
|
-
failed: 0,
|
|
33
|
-
};
|
|
34
|
-
const failed_docs_report = [];
|
|
35
|
-
const sap_categories = await get_sap_categories(
|
|
36
|
-
commandEvent.app.formData.sapHostUrl,
|
|
37
|
-
{}
|
|
38
|
-
);
|
|
39
|
-
result.sap_total =
|
|
40
|
-
sap_categories === null || sap_categories === void 0
|
|
41
|
-
? void 0
|
|
42
|
-
: sap_categories.length;
|
|
43
|
-
await commandLog
|
|
44
|
-
.addDetail(`${result.sap_total} Item Groups in SAP`)
|
|
45
|
-
.commit();
|
|
46
|
-
const repzo_categories = await repzo.category.find({
|
|
47
|
-
per_page: 50000,
|
|
4
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
6
|
+
env: commandEvent.env,
|
|
48
7
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
:
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
? void 0
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
repzo_category._id,
|
|
130
|
-
body
|
|
131
|
-
);
|
|
132
|
-
result.updated++;
|
|
133
|
-
} catch (e) {
|
|
134
|
-
// console.log(
|
|
135
|
-
// "Update Product Category Failed >> ",
|
|
136
|
-
// e?.response?.data,
|
|
137
|
-
// body
|
|
138
|
-
// );
|
|
139
|
-
failed_docs_report.push({
|
|
140
|
-
method: "update",
|
|
141
|
-
doc_id:
|
|
142
|
-
repzo_category === null || repzo_category === void 0
|
|
143
|
-
? void 0
|
|
144
|
-
: repzo_category._id,
|
|
145
|
-
doc: body,
|
|
146
|
-
error_message: set_error(e),
|
|
147
|
-
});
|
|
148
|
-
result.failed++;
|
|
8
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
9
|
+
try {
|
|
10
|
+
// console.log("sync_category");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_category";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog
|
|
15
|
+
.addDetail("Repzo SAP: Started Syncing Product Categories")
|
|
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_categories = await get_sap_categories(commandEvent.app.formData.sapHostUrl, {});
|
|
27
|
+
result.sap_total = sap_categories === null || sap_categories === void 0 ? void 0 : sap_categories.length;
|
|
28
|
+
await commandLog
|
|
29
|
+
.addDetail(`${result.sap_total} Item Groups in SAP`)
|
|
30
|
+
.commit();
|
|
31
|
+
const repzo_categories = await repzo.category.find({
|
|
32
|
+
per_page: 50000,
|
|
33
|
+
});
|
|
34
|
+
result.repzo_total = (_b = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
35
|
+
await commandLog
|
|
36
|
+
.addDetail(`${(_c = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _c === void 0 ? void 0 : _c.length} Product Category in Repzo`)
|
|
37
|
+
.commit();
|
|
38
|
+
for (let i = 0; i < (sap_categories === null || sap_categories === void 0 ? void 0 : sap_categories.length); i++) {
|
|
39
|
+
const sap_category = sap_categories[i];
|
|
40
|
+
const repzo_category = repzo_categories.data.find((r_cat) => { var _a; return ((_a = r_cat.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_category.GROUPCODE}`; });
|
|
41
|
+
const body = {
|
|
42
|
+
name: sap_category.GROUPDESC,
|
|
43
|
+
disabled: false,
|
|
44
|
+
integration_meta: { id: `${nameSpace}_${sap_category.GROUPCODE}` },
|
|
45
|
+
company_namespace: [nameSpace],
|
|
46
|
+
};
|
|
47
|
+
if (!repzo_category) {
|
|
48
|
+
// Create
|
|
49
|
+
try {
|
|
50
|
+
const created_category = await repzo.category.create(body);
|
|
51
|
+
result.created++;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// console.log("Create Product Category Failed >> ", e?.response, body);
|
|
55
|
+
failed_docs_report.push({
|
|
56
|
+
method: "create",
|
|
57
|
+
doc: body,
|
|
58
|
+
error_message: set_error(e),
|
|
59
|
+
});
|
|
60
|
+
result.failed++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (((_d = repzo_category === null || repzo_category === void 0 ? void 0 : repzo_category.integration_meta) === null || _d === void 0 ? void 0 : _d.id) == ((_e = body === null || body === void 0 ? void 0 : body.integration_meta) === null || _e === void 0 ? void 0 : _e.id) &&
|
|
65
|
+
(repzo_category === null || repzo_category === void 0 ? void 0 : repzo_category.name) == (body === null || body === void 0 ? void 0 : body.name)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// Update
|
|
69
|
+
try {
|
|
70
|
+
const updated_category = await repzo.category.update(repzo_category._id, body);
|
|
71
|
+
result.updated++;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// console.log(
|
|
75
|
+
// "Update Product Category Failed >> ",
|
|
76
|
+
// e?.response?.data,
|
|
77
|
+
// body
|
|
78
|
+
// );
|
|
79
|
+
failed_docs_report.push({
|
|
80
|
+
method: "update",
|
|
81
|
+
doc_id: repzo_category === null || repzo_category === void 0 ? void 0 : repzo_category._id,
|
|
82
|
+
doc: body,
|
|
83
|
+
error_message: set_error(e),
|
|
84
|
+
});
|
|
85
|
+
result.failed++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
149
88
|
}
|
|
150
|
-
|
|
89
|
+
// console.log(result);
|
|
90
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
91
|
+
await commandLog
|
|
92
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
93
|
+
.setBody(result)
|
|
94
|
+
.commit();
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
//@ts-ignore
|
|
99
|
+
console.error(((_f = e === null || e === void 0 ? void 0 : e.response) === null || _f === void 0 ? void 0 : _f.data) || e);
|
|
100
|
+
await commandLog.setStatus("fail", e).commit();
|
|
101
|
+
throw e;
|
|
151
102
|
}
|
|
152
|
-
// console.log(result);
|
|
153
|
-
await update_bench_time(
|
|
154
|
-
repzo,
|
|
155
|
-
commandEvent.app._id,
|
|
156
|
-
bench_time_key,
|
|
157
|
-
new_bench_time
|
|
158
|
-
);
|
|
159
|
-
await commandLog
|
|
160
|
-
.setStatus(
|
|
161
|
-
"success",
|
|
162
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
163
|
-
)
|
|
164
|
-
.setBody(result)
|
|
165
|
-
.commit();
|
|
166
|
-
return result;
|
|
167
|
-
} catch (e) {
|
|
168
|
-
//@ts-ignore
|
|
169
|
-
console.error(
|
|
170
|
-
((_f = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
171
|
-
_f === void 0
|
|
172
|
-
? void 0
|
|
173
|
-
: _f.data) || e
|
|
174
|
-
);
|
|
175
|
-
await commandLog.setStatus("fail", e).commit();
|
|
176
|
-
throw e;
|
|
177
|
-
}
|
|
178
103
|
};
|
|
179
104
|
const get_sap_categories = async (serviceEndPoint, query) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
105
|
+
try {
|
|
106
|
+
const sap_categories = await _create(serviceEndPoint, "/ItemGroup", {});
|
|
107
|
+
return sap_categories.ItemGroup;
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
186
112
|
};
|