dcos-core-monalisav2-latam 1.1.6 → 1.1.8
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/package.json
CHANGED
|
@@ -23,11 +23,7 @@ const consumer = async (event) => {
|
|
|
23
23
|
// Referencia a la API de VTEX sobre el marketplace asociado
|
|
24
24
|
const vtexApi = new VtexApi(parentAccount, key, token);
|
|
25
25
|
|
|
26
|
-
const {
|
|
27
|
-
clientId,
|
|
28
|
-
productsRegular, productsIncremental,
|
|
29
|
-
productsRegularFinal, productsIncrementalFinal
|
|
30
|
-
} = client;
|
|
26
|
+
const { clientId, productsRegular, productsIncremental } = client;
|
|
31
27
|
|
|
32
28
|
// Insertar datos en Clientes Totales
|
|
33
29
|
await vtexApi.fetch(`/dataentities/${DATA_ENTITY_CLIENT_ACRONYM}/documents`, {
|
|
@@ -44,11 +40,11 @@ const consumer = async (event) => {
|
|
|
44
40
|
orderDate: new Date().toISOString(),
|
|
45
41
|
clientId,
|
|
46
42
|
type: 'SUGGESTED_ORDER',
|
|
47
|
-
productsRegular
|
|
48
|
-
productsIncremental
|
|
43
|
+
productsRegular,
|
|
44
|
+
productsIncremental,
|
|
49
45
|
};
|
|
50
|
-
const email = `${Startemail}+${clientId}@${Domainemail}`;
|
|
51
46
|
// Consulta del userProfileId
|
|
47
|
+
const email = `${Startemail}+${clientId}@${Domainemail}`;
|
|
52
48
|
await findUserProfileId(vtexApi, email, suggestedProductData);
|
|
53
49
|
|
|
54
50
|
// Insertar datos en entidad de Productos Sugeridos
|
|
@@ -55,6 +55,8 @@ const suggestedProductMdlz = async (event) => {
|
|
|
55
55
|
return ApiResponse.response(207, validBody.data);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
return ApiResponse.response(200, clients);
|
|
59
|
+
|
|
58
60
|
do {
|
|
59
61
|
// Se extrae las primeras filas de la lista para ejecutar las Promises
|
|
60
62
|
let dataToProcess = clients.splice(0, 10);
|
|
@@ -123,13 +125,12 @@ function validateClientsData(clients, minProductsCount, indexClientRegister, an,
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
client.clientId = clientId;
|
|
126
|
-
|
|
127
|
-
client.
|
|
128
|
-
setItemInformation(client.
|
|
129
|
-
setItemInformation(client.productsIncremental, 'INCREMENTAL', skusList, client.productsIncrementalFinal);
|
|
128
|
+
const productsCounter = { 'REGULAR': 0, 'INCREMENTAL': 0 };
|
|
129
|
+
setItemInformation(client.productsRegular, 'REGULAR', skusList, productsCounter);
|
|
130
|
+
setItemInformation(client.productsIncremental, 'INCREMENTAL', skusList, productsCounter);
|
|
130
131
|
|
|
131
|
-
// Se valida si la longitud de alguno de
|
|
132
|
-
if (
|
|
132
|
+
// Se valida si la longitud de alguno de la lista de ítems válidos del cliente es menos al número mínimo de productos
|
|
133
|
+
if (productsCounter.REGULAR < minProductsCount || productsCounter.INCREMENTAL < minProductsCount) {
|
|
133
134
|
client.error = `Validate the following properties productsRegular and productsIncremental minimum ${minProductsCount} elements`;
|
|
134
135
|
notProcessedItems.push(client);
|
|
135
136
|
}
|
|
@@ -260,32 +261,29 @@ function removeDuplicatesSku(items, skusList) {
|
|
|
260
261
|
* @param {Object[]} list Lista de ítems enviados en la petición.
|
|
261
262
|
* @param {String} productType Tipo de producto ('REGULAR' o 'INCREMENTAL').
|
|
262
263
|
* @param {Object} skusList Objeto donde se consolida la información de los SKU que no fueron encontrados.
|
|
264
|
+
* @param {Object} productsCounter Objeto donde se consolida el conteo de productos válidos por el tipo de producto `productType`.
|
|
263
265
|
*/
|
|
264
|
-
function setItemInformation(list, productType, skusList,
|
|
266
|
+
function setItemInformation(list, productType, skusList, productsCounter) {
|
|
265
267
|
for (let item of list) {
|
|
266
|
-
const { sku
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
};
|
|
268
|
+
const { sku } = item;
|
|
269
|
+
item.type = productType;
|
|
270
|
+
|
|
271
|
+
// Se elimina la propiedad "sku" del ítem de la lista, ya que su valor se estableció en la propiedad "refId"
|
|
272
|
+
item.refId = sku;
|
|
273
|
+
delete item.sku;
|
|
273
274
|
|
|
274
275
|
if (skusList?.[sku]?.hasOwnProperty('SkuId')) {
|
|
275
276
|
const { SkuId, IsActive, ProductIsVisible } = skusList[sku];
|
|
276
|
-
|
|
277
|
+
item.skuId = SkuId;
|
|
277
278
|
if (IsActive) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} else {
|
|
282
|
-
finalItem.status = 'not_visible';
|
|
283
|
-
}
|
|
279
|
+
item.status = ProductIsVisible ? 'active' : 'not_visible';
|
|
280
|
+
// Se incrementa el contador de productos válidos asociados al tipo "productType"
|
|
281
|
+
productsCounter[productType] += 1;
|
|
284
282
|
} else {
|
|
285
|
-
|
|
283
|
+
item.status = 'inactive';
|
|
286
284
|
}
|
|
287
285
|
} else {
|
|
288
|
-
|
|
286
|
+
item.status = 'invalid';
|
|
289
287
|
}
|
|
290
288
|
}
|
|
291
289
|
}
|