dcos-core-monalisav2-latam 1.1.6 → 1.1.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcos-core-monalisav2-latam",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1"
6
6
  },
@@ -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: productsRegularFinal,
48
- productsIncremental: productsIncrementalFinal,
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
@@ -123,13 +123,12 @@ function validateClientsData(clients, minProductsCount, indexClientRegister, an,
123
123
  }
124
124
 
125
125
  client.clientId = clientId;
126
- client.productsRegularFinal = [];
127
- client.productsIncrementalFinal = [];
128
- setItemInformation(client.productsRegular, 'REGULAR', skusList, client.productsRegularFinal);
129
- setItemInformation(client.productsIncremental, 'INCREMENTAL', skusList, client.productsIncrementalFinal);
126
+ const productsCounter = { 'REGULAR': 0, 'INCREMENTAL': 0 };
127
+ setItemInformation(client.productsRegular, 'REGULAR', skusList, productsCounter);
128
+ setItemInformation(client.productsIncremental, 'INCREMENTAL', skusList, productsCounter);
130
129
 
131
- // Se valida si la longitud de alguno de los ítems del cliente es menos al número mínimo de productos
132
- if (client.productsRegularFinal.length < minProductsCount || client.productsIncrementalFinal.length < minProductsCount) {
130
+ // 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
131
+ if (productsCounter.REGULAR.length < minProductsCount || productsCounter.INCREMENTAL.length < minProductsCount) {
133
132
  client.error = `Validate the following properties productsRegular and productsIncremental minimum ${minProductsCount} elements`;
134
133
  notProcessedItems.push(client);
135
134
  }
@@ -260,32 +259,29 @@ function removeDuplicatesSku(items, skusList) {
260
259
  * @param {Object[]} list Lista de ítems enviados en la petición.
261
260
  * @param {String} productType Tipo de producto ('REGULAR' o 'INCREMENTAL').
262
261
  * @param {Object} skusList Objeto donde se consolida la información de los SKU que no fueron encontrados.
262
+ * @param {Object} productsCounter Objeto donde se consolida el conteo de productos válidos por el tipo de producto `productType`.
263
263
  */
264
- function setItemInformation(list, productType, skusList, finalList) {
264
+ function setItemInformation(list, productType, skusList, productsCounter) {
265
265
  for (let item of list) {
266
- const { sku, quantity, priority } = item;
267
- const finalItem = {
268
- refId: sku,
269
- quantity,
270
- type: productType,
271
- priority
272
- };
266
+ const { sku } = item;
267
+ item.type = productType;
268
+
269
+ // Se elimina la propiedad "sku" del ítem de la lista, ya que su valor se estableció en la propiedad "refId"
270
+ item.refId = sku;
271
+ delete item.sku;
273
272
 
274
273
  if (skusList?.[sku]?.hasOwnProperty('SkuId')) {
275
274
  const { SkuId, IsActive, ProductIsVisible } = skusList[sku];
276
- finalItem.skuId = SkuId;
275
+ item.skuId = SkuId;
277
276
  if (IsActive) {
278
- if (ProductIsVisible) {
279
- finalItem.status = 'active';
280
- finalList.push(finalItem);
281
- } else {
282
- finalItem.status = 'not_visible';
283
- }
277
+ item.status = ProductIsVisible ? 'active' : 'not_visible';
278
+ // Se incrementa el contador de productos válidos asociados al tipo "productType"
279
+ productsCounter[productType] += 1;
284
280
  } else {
285
- finalItem.status = 'inactive';
281
+ item.status = 'inactive';
286
282
  }
287
283
  } else {
288
- finalItem.status = 'invalid';
284
+ item.status = 'invalid';
289
285
  }
290
286
  }
291
287
  }