dcos-core-monalisav2-latam 1.0.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.
- package/README.md +130 -0
- package/index.js +350 -0
- package/package.json +52 -0
- package/src/auth/handler.js +3 -0
- package/src/common/MondelezCastOrder.js +449 -0
- package/src/common/utils/AuthSecurity.js +46 -0
- package/src/common/utils/account-error-handler.js +279 -0
- package/src/common/utils/account-error-helper.js +231 -0
- package/src/common/utils/account-properties-handler.js +355 -0
- package/src/common/utils/api-response.js +62 -0
- package/src/common/utils/aws-services.js +186 -0
- package/src/common/utils/constants/account-error-codes.json +801 -0
- package/src/common/utils/constants.js +37 -0
- package/src/common/utils/convert/MondelezClientsItemsCast.js +52 -0
- package/src/common/utils/convert/MondelezInventoryItemsCast.js +15 -0
- package/src/common/utils/convert/MondelezOrderStatusCast.js +34 -0
- package/src/common/utils/convert/MondelezPricesItemsCast.js +37 -0
- package/src/common/utils/cron-ftp-get.js +143 -0
- package/src/common/utils/data-tables-helper.js +213 -0
- package/src/common/utils/date-range-calculator.js +113 -0
- package/src/common/utils/delay.js +17 -0
- package/src/common/utils/ftp-sftp.js +320 -0
- package/src/common/utils/logger.js +126 -0
- package/src/common/utils/nodemailerLib.js +61 -0
- package/src/common/utils/product-unit-converter.js +168 -0
- package/src/common/utils/schemas-utils.js +101 -0
- package/src/common/utils/seller-email-sharing-service.js +441 -0
- package/src/common/utils/sftp-utils.js +202 -0
- package/src/common/utils/status.js +15 -0
- package/src/common/utils/util.js +236 -0
- package/src/common/utils/validate-state-order.js +35 -0
- package/src/common/utils/validateProviders.js +67 -0
- package/src/common/utils/validation-data.js +45 -0
- package/src/common/utils/vtex/save-hooks.js +65 -0
- package/src/common/utils/vtex/save-schemas.js +65 -0
- package/src/common/utils/vtex-hook-handler.js +71 -0
- package/src/common/validation/AccountCoordinatesValidation.js +350 -0
- package/src/common/validation/GeneralErrorValidation.js +11 -0
- package/src/common/validation/MainErrorValidation.js +8 -0
- package/src/entities/account.js +639 -0
- package/src/entities/clients.js +104 -0
- package/src/entities/controlprice.js +196 -0
- package/src/entities/controlstock.js +206 -0
- package/src/entities/cron.js +77 -0
- package/src/entities/cronjob.js +71 -0
- package/src/entities/orders.js +195 -0
- package/src/entities/sftp-inbound.js +88 -0
- package/src/entities/sku.js +220 -0
- package/src/entities/taxpromotion.js +249 -0
- package/src/functions/account/account-get.js +262 -0
- package/src/functions/account/account-handler.js +299 -0
- package/src/functions/account/clients.js +10 -0
- package/src/functions/account/index.js +208 -0
- package/src/functions/actions/save-promotions-order-history.js +324 -0
- package/src/functions/affiliates/affiliates-hook-consumer.js +87 -0
- package/src/functions/affiliates/affiliates-hook-producer.js +45 -0
- package/src/functions/clients/clients-audience.js +62 -0
- package/src/functions/clients/clients-consumer.js +648 -0
- package/src/functions/clients/clients-producer.js +362 -0
- package/src/functions/clients/clients-suggested-product-consumer.js +166 -0
- package/src/functions/clients/helpers/suggested-product-mdlz.js +233 -0
- package/src/functions/clients_peru/email.html +129 -0
- package/src/functions/clients_peru/splitfile.js +357 -0
- package/src/functions/clients_peru/updateClients.js +1334 -0
- package/src/functions/clients_peru/utils.js +243 -0
- package/src/functions/cronjobs/cron-jobs-manager.js +40 -0
- package/src/functions/cronjobs/cron-jobs.js +171 -0
- package/src/functions/crons/cron.js +39 -0
- package/src/functions/distributors/distributor-handler.js +81 -0
- package/src/functions/distributors/distributor.js +535 -0
- package/src/functions/distributors/index.js +60 -0
- package/src/functions/financialpolicy/assign-financialpolicy.js +111 -0
- package/src/functions/financialpolicy/get-financialpolicy.js +91 -0
- package/src/functions/financialpolicy/index.js +28 -0
- package/src/functions/inventory/catalog-sync-consumer.js +17 -0
- package/src/functions/inventory/catalog-sync-handler.js +311 -0
- package/src/functions/inventory/inventory-consumer.js +119 -0
- package/src/functions/inventory/inventory-producer.js +197 -0
- package/src/functions/multiPresentation/multipre-queue.js +155 -0
- package/src/functions/multiPresentation/multipres.js +459 -0
- package/src/functions/nodeflow/index.js +83 -0
- package/src/functions/nodeflow/nodeflow-cron.js +200 -0
- package/src/functions/nodeflow/nodeflow-pub.js +203 -0
- package/src/functions/nodeflow/nodeflow-pvt.js +266 -0
- package/src/functions/notifications/download-leads-handler.js +67 -0
- package/src/functions/notifications/new-leads-notification-consumer.js +17 -0
- package/src/functions/notifications/new-leads-notification-handler.js +359 -0
- package/src/functions/notifications/order-status-notification-handler.js +482 -0
- package/src/functions/notifications/promotion-notification-handler.js +193 -0
- package/src/functions/orders/index.js +32 -0
- package/src/functions/orders/orders-cancel-handler.js +74 -0
- package/src/functions/orders/orders-handler.js +280 -0
- package/src/functions/orders/orders-hook-consumer.js +137 -0
- package/src/functions/orders/orders-hook-producer.js +170 -0
- package/src/functions/orders/orders-notifications-handler.js +137 -0
- package/src/functions/orders/orders-status-consumer.js +461 -0
- package/src/functions/orders/orders-status-producer.js +443 -0
- package/src/functions/prices/index.js +75 -0
- package/src/functions/prices/prices-consumer.js +236 -0
- package/src/functions/prices/prices-producer.js +323 -0
- package/src/functions/prices/promotion-and-tax.js +1284 -0
- package/src/functions/routesflow/assign-routeflow-queue.js +77 -0
- package/src/functions/schemas/vtex/handle-schemas.js +102 -0
- package/src/functions/security/process_gas.js +221 -0
- package/src/functions/security/security-handler.js +950 -0
- package/src/functions/sftp/sftp-consumer.js +453 -0
- package/src/functions/sftpIntegrations/processes/redirectServices.js +184 -0
- package/src/functions/sftpIntegrations/processes/validateFileSchema.js +226 -0
- package/src/functions/sftpIntegrations/schemas/credential-schema.js +123 -0
- package/src/functions/sftpIntegrations/schemas/record-schema.js +131 -0
- package/src/functions/sftpIntegrations/schemas/sftp_required_fields.json +3 -0
- package/src/functions/sftpIntegrations/sftp-config-producer.js +112 -0
- package/src/functions/sftpIntegrations/sftp-consumer.js +700 -0
- package/src/functions/sftpIntegrations/test/validateFile.test.js +122 -0
- package/src/functions/sftpIntegrations/utils/connect-dynamo.js +29 -0
- package/src/functions/sftpIntegrations/utils/split-data.js +25 -0
- package/src/functions/utils/index.js +130 -0
- package/src/functions/vtex/vtex-helpers.js +694 -0
- package/src/integrations/accountErrors/AccountErrorManager.js +437 -0
- package/src/integrations/audience/Audience.js +70 -0
- package/src/integrations/financialPolicy/FinancialPolicyApi.js +377 -0
- package/src/integrations/index.js +0 -0
- package/src/integrations/mobilvendor/MobilvendorApi.js +405 -0
- package/src/integrations/productmultipresentation/ProductMultiPresentation.js +200 -0
- package/src/mdlz/auth/SecretManagerApi.js +77 -0
- package/src/mdlz/client/MdlzApi.js +70 -0
- package/src/vtex/clients/ProvidersApi.js +51 -0
- package/src/vtex/clients/VtexApi.js +511 -0
- package/src/vtex/models/VtexOrder.js +87 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
const ApiResponse = require("../../common/utils/api-response");
|
|
2
|
+
const AWSServices = require("../../common/utils/aws-services");
|
|
3
|
+
const ClientData = require("../../entities/clients");
|
|
4
|
+
const AccountData = require("../../entities/account");
|
|
5
|
+
const SkuData = require("../../entities/sku");
|
|
6
|
+
const Constants = require("../../common/utils/constants");
|
|
7
|
+
const DistributorData = require("../distributors/distributor");
|
|
8
|
+
const LIMIT_ITEMS_TO_PROCESS = process?.env?.LIMIT_ITEMS_TO_PROCESS || 150;
|
|
9
|
+
const SQS_INVENTORY_QUEUE_URL = process?.env?.SQS_INVENTORY_QUEUE_URL;
|
|
10
|
+
const Logger = require("../../common/utils/logger");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {import("aws-lambda").APIGatewayProxyEvent} event
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
const producer = async (event) => {
|
|
18
|
+
let statusCode = 200;
|
|
19
|
+
let message;
|
|
20
|
+
|
|
21
|
+
if (!event.body) {
|
|
22
|
+
return ApiResponse.response(400, "No body was found");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const clientId = event?.requestContext?.authorizer?.claims?.client_id;
|
|
26
|
+
Logger.log(JSON.stringify(JSON.parse(event.body)), clientId);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const request = validateRequestBody(JSON.parse(event.body));
|
|
30
|
+
const scope = event?.requestContext?.authorizer?.claims?.scope;
|
|
31
|
+
const accountName = request?.an;
|
|
32
|
+
const inventory = request?.inventory;
|
|
33
|
+
|
|
34
|
+
if (!inventory || inventory?.length > LIMIT_ITEMS_TO_PROCESS) {
|
|
35
|
+
Logger.error("Inventory QTY INVALID: ", inventory?.length);
|
|
36
|
+
return ApiResponse.response(404, "Inventory limit of items exceeded");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!event?.internalService) {
|
|
40
|
+
if (!scope?.includes("admin")) {
|
|
41
|
+
const isValid = await ClientData.validateAccount(clientId, accountName);
|
|
42
|
+
if (!isValid) {
|
|
43
|
+
Logger.error("Account not found: ", accountName, ". ClientId: ", clientId);
|
|
44
|
+
return ApiResponse.response(404, "Account not found");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const account = event?.accountData && event?.internalService === true ? event?.accountData : await AccountData.getAccountDataByAccountName(accountName);
|
|
49
|
+
Logger.setAccount(account);
|
|
50
|
+
if (!account) {
|
|
51
|
+
Logger.error("Account not found: ", accountName, ". ClientId: ", clientId);
|
|
52
|
+
return ApiResponse.response(404, "Account not found");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Logger.debug("JSON account: ", JSON.stringify(account));
|
|
56
|
+
const allWarehouses = Object.values(account?.ChannelWarehouse);
|
|
57
|
+
const warehouse = request?.warehouse;
|
|
58
|
+
Logger.debug("Warehouse: ", warehouse);
|
|
59
|
+
Logger.debug("count: ", allWarehouses.length);
|
|
60
|
+
Logger.debug("if: ", allWarehouses.length < 1);
|
|
61
|
+
|
|
62
|
+
if (allWarehouses.length < 1) {
|
|
63
|
+
Logger.error("Warehouse INVALID: ", warehouse);
|
|
64
|
+
return ApiResponse.response(404, "Warehouse not found");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var warehouseExists = allWarehouses[0];
|
|
68
|
+
if (warehouse && warehouse !== "") {
|
|
69
|
+
warehouseExists = account?.ChannelWarehouse?.[warehouse];
|
|
70
|
+
if (!warehouseExists) {
|
|
71
|
+
Logger.error("Warehouse INVALID: ", warehouse);
|
|
72
|
+
return ApiResponse.response(404, "Warehouse not found");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let skuRefUsed = account?.SkuRefUsed;
|
|
77
|
+
if (typeof skuRefUsed !== "boolean") {
|
|
78
|
+
Logger.warn("Sku or ReferenceCode filter not defined, use default: ", skuRefUsed);
|
|
79
|
+
skuRefUsed = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const safetyStockType = account?.SafetyStockType || Constants.SAFETY_STOCK_TYPE_NOMINAL;
|
|
83
|
+
const safetyStock = account?.SafetyStock || 0;
|
|
84
|
+
|
|
85
|
+
var notProcessed = [];
|
|
86
|
+
|
|
87
|
+
for (let item of inventory) {
|
|
88
|
+
try {
|
|
89
|
+
let notFoundByEan = false;
|
|
90
|
+
let skuData = null;
|
|
91
|
+
//Si esta activado el manejo de sku por código de distribuidor
|
|
92
|
+
try {
|
|
93
|
+
const skuDistributorManagement = account?.SkuDistributorManagement || false;
|
|
94
|
+
item.sku = await DistributorData.getDistributorByErpCode(accountName, item?.sku, skuDistributorManagement);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error("Error al obtener distribuidor por sku:", error);
|
|
97
|
+
}
|
|
98
|
+
if (skuRefUsed) {
|
|
99
|
+
skuData = account?.ValidateSkuPriceInventoryInProcess === true ? { SkuId: item?.sku } : await SkuData.getSkuByParentAccountNameAndSku(account?.ParentAccountName, item?.sku);
|
|
100
|
+
} else {
|
|
101
|
+
skuData = account?.ValidateSkuPriceInventoryInProcess === true ? [{ SkuId: item?.sku }] : await SkuData.getSkuByParentAccountNameAndEan(account?.ParentAccountName, item?.sku);
|
|
102
|
+
if (!skuData || skuData.length < 1) {
|
|
103
|
+
Logger.debug("Not found by Ean: ", skuData);
|
|
104
|
+
notFoundByEan = true;
|
|
105
|
+
} else {
|
|
106
|
+
skuData = skuData?.[0];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
Logger.debug("SKU Data: ", skuData, ". SKU Ref Used: ", skuRefUsed);
|
|
110
|
+
if ((!skuData || !skuData?.SkuId) && !notFoundByEan) {
|
|
111
|
+
Logger.debug("SKU Data INVALID: ", skuData);
|
|
112
|
+
item.message = "SKU not found";
|
|
113
|
+
notProcessed.push(item);
|
|
114
|
+
} else if (notFoundByEan && !skuRefUsed) {
|
|
115
|
+
Logger.debug("SKU Data INVALID: ", skuData);
|
|
116
|
+
item.message = "SKU not found by Ean";
|
|
117
|
+
notProcessed.push(item);
|
|
118
|
+
} else {
|
|
119
|
+
let quantityCustom = 0;
|
|
120
|
+
if (item?.quantity >= 0) {
|
|
121
|
+
if (safetyStockType === Constants.SAFETY_STOCK_TYPE_NOMINAL) {
|
|
122
|
+
quantityCustom = item?.quantity - safetyStock;
|
|
123
|
+
} else if (safetyStockType === Constants.SAFETY_STOCK_TYPE_PERCENTAGE) {
|
|
124
|
+
quantityCustom = Math.floor((item?.quantity * (100 - safetyStock)) / 100);
|
|
125
|
+
}
|
|
126
|
+
if (quantityCustom < 0) {
|
|
127
|
+
quantityCustom = 0;
|
|
128
|
+
}
|
|
129
|
+
const dataSend = {
|
|
130
|
+
an: accountName,
|
|
131
|
+
skuRefId: item.sku,
|
|
132
|
+
hoursValidStockPrice: account?.HoursValidStockPrice ?? 24,
|
|
133
|
+
ValidateSkuPriceInventoryInProcess: account?.ValidateSkuPriceInventoryInProcess ?? false,
|
|
134
|
+
ParentAccountName: account?.ParentAccountName,
|
|
135
|
+
SkuRefUsed: skuRefUsed,
|
|
136
|
+
key: account?.Credentials?.key,
|
|
137
|
+
token: account?.Credentials?.token,
|
|
138
|
+
warehouse: warehouseExists,
|
|
139
|
+
sku: skuData?.SkuId,
|
|
140
|
+
quantity: quantityCustom,
|
|
141
|
+
accountConfig: account,
|
|
142
|
+
individualUnits: typeof item?.individualUnits === "number" ? item.individualUnits : 1
|
|
143
|
+
};
|
|
144
|
+
await AWSServices.sendSQSMessage(SQS_INVENTORY_QUEUE_URL, dataSend);
|
|
145
|
+
} else {
|
|
146
|
+
Logger.debug("Quantity INVALID: ", item?.quantity);
|
|
147
|
+
item.message = "Quantity invalid";
|
|
148
|
+
notProcessed.push(item);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
Logger.debug(error);
|
|
153
|
+
item.message = error.message;
|
|
154
|
+
notProcessed.push(item);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (notProcessed.length > 0) {
|
|
158
|
+
Logger.debug("Not Processed: ", notProcessed);
|
|
159
|
+
const message = {
|
|
160
|
+
message: "Not all items were processed.",
|
|
161
|
+
notProcessedItems: notProcessed,
|
|
162
|
+
};
|
|
163
|
+
return ApiResponse.response(207, message);
|
|
164
|
+
}
|
|
165
|
+
message = "Message accepted!";
|
|
166
|
+
} catch (error) {
|
|
167
|
+
Logger.error(error);
|
|
168
|
+
message = error;
|
|
169
|
+
statusCode = 500;
|
|
170
|
+
}
|
|
171
|
+
return ApiResponse.response(statusCode, message);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
function validateRequestBody(body) {
|
|
175
|
+
if (!body) {
|
|
176
|
+
throw new Error("El cuerpo de la solicitud es nulo o no está definido.");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const { an, warehouse, inventory } = body;
|
|
180
|
+
|
|
181
|
+
if (typeof an !== "string" || typeof warehouse !== "string" || !Array.isArray(inventory)) {
|
|
182
|
+
throw new Error("El cuerpo de la solicitud no tiene el formato esperado.");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const invalidInventoryItem = inventory.find((item) => {
|
|
186
|
+
return typeof item.sku !== "string" || typeof item.quantity !== "number";
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (invalidInventoryItem) {
|
|
190
|
+
throw new Error("El cuerpo de la solicitud no tiene el formato esperado.");
|
|
191
|
+
}
|
|
192
|
+
return body;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
module.exports = {
|
|
196
|
+
producer,
|
|
197
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const ProductMultiPresentation = require("../../integrations/productmultipresentation/ProductMultiPresentation");
|
|
2
|
+
const SkuData = require("../../entities/sku");
|
|
3
|
+
const AWSServices = require("../../common/utils/aws-services");
|
|
4
|
+
const AccountData = require("../../entities/account");
|
|
5
|
+
const InventoryData = require("./multipres");
|
|
6
|
+
const Logger = require("../../common/utils/logger");
|
|
7
|
+
|
|
8
|
+
const SQS_MULTIPRE_PRODUCT_QUEUE_URL = process?.env?.SQS_MULTIPRE_PRODUCT_QUEUE_URL;
|
|
9
|
+
const SQS_MULTIPRECOM_PRODUCT_QUEUE_URL = process?.env?.SQS_MULTIPRECOM_PRODUCT_QUEUE_URL;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Handles the event triggered by the Lambda function.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} event - The event object containing the request details.
|
|
15
|
+
* @param {Array<Object>} event.Records - List of records from the event.
|
|
16
|
+
* @param {Object} event.Records[].body - The body of the record containing the message.
|
|
17
|
+
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating success or failure.
|
|
18
|
+
* @throws {Error} - If an error occurs during the execution.
|
|
19
|
+
*/
|
|
20
|
+
module.exports.handler= async (event)=>{
|
|
21
|
+
for (const record of event.Records) {
|
|
22
|
+
Logger.debug("Message Body: ", record.body);
|
|
23
|
+
const body = JSON.parse(record.body);
|
|
24
|
+
if (body) {
|
|
25
|
+
const accountName = body?.accountName;
|
|
26
|
+
const account = await AccountData.getAccountDataByAccountName(accountName);
|
|
27
|
+
const accountParent = await AccountData.getAccountDataByAccountName(account?.ParentAccountName);
|
|
28
|
+
Logger.setAccount(account);
|
|
29
|
+
if (!account || !accountParent) {
|
|
30
|
+
Logger.error("Account not found: ", accountName);
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
Logger.debug("JSON account: ", account);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
if (account?.ProductMultiPresentation && account?.ProductMultiPresentation?.isActive) {
|
|
37
|
+
const geoSalesApi = new ProductMultiPresentation(
|
|
38
|
+
accountParent.ParentAccountName,
|
|
39
|
+
accountParent.Credentials.key,
|
|
40
|
+
accountParent.Credentials.token,
|
|
41
|
+
accountParent.AcronymDistributorVtex,
|
|
42
|
+
account.ProductMultiPresentation
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Obtener la lista de productos de GeoSales
|
|
46
|
+
const geoSalesProductList = await geoSalesApi.getProductList();
|
|
47
|
+
const vtexProductList = await geoSalesApi.getAllProductsVTEX();
|
|
48
|
+
const listProductProccess = getListProductProcess(geoSalesProductList, vtexProductList);
|
|
49
|
+
const skuRefUsed = account?.SkuRefUsed ?? true;
|
|
50
|
+
|
|
51
|
+
// Procesar la lista de productos de GeoSales
|
|
52
|
+
for (const geoSalesProduct of listProductProccess) {
|
|
53
|
+
try {
|
|
54
|
+
// Verifica si el producto existe en DynamoDB
|
|
55
|
+
if(account?.ProductMultiPresentation?.WhiteListProductId?.length === 0 || account?.ProductMultiPresentation?.WhiteListProductId?.includes(geoSalesProduct.productId)){
|
|
56
|
+
if (geoSalesProduct && geoSalesProduct.itemId) {
|
|
57
|
+
// Envía el producto válido a la cola SQS
|
|
58
|
+
await AWSServices.sendSQSMessage(SQS_MULTIPRECOM_PRODUCT_QUEUE_URL, {
|
|
59
|
+
account: account,
|
|
60
|
+
SkuId: geoSalesProduct.itemId,
|
|
61
|
+
geoSalesProduct: geoSalesProduct,
|
|
62
|
+
TradePolicyId: geoSalesProduct?.TradePolicyId
|
|
63
|
+
});
|
|
64
|
+
Logger.debug("Producto encontrado en DynamoDB y en procesamiento.", geoSalesProduct);
|
|
65
|
+
} else {
|
|
66
|
+
Logger.debug("Producto no encontrado en DynamoDB: ", geoSalesProduct, 'skuData', skuData);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
Logger.error("Error al procesar el producto de GeoSales: ", error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
Logger.error(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get the list of products to process by comparing external and VTEX lists.
|
|
83
|
+
*
|
|
84
|
+
* @param {Array<Object>} listExternal - List of products from the external system.
|
|
85
|
+
* @param {Array<Object>} listVtex - List of products from VTEX.
|
|
86
|
+
* @returns {Array<Object>} - A list of products to process.
|
|
87
|
+
*/
|
|
88
|
+
const getListProductProcess = (listExternal, listVtex)=>{
|
|
89
|
+
let listProcess= [];
|
|
90
|
+
let idsSku= [];
|
|
91
|
+
|
|
92
|
+
try{
|
|
93
|
+
for (var i = 0; i < listVtex.length; i++) {
|
|
94
|
+
let registerExternal= listExternal.find(it=>(it?.sku == listVtex[i]?.referenceId[0]?.Value || it?.sku == listVtex[i]?.ean));
|
|
95
|
+
if (registerExternal) {
|
|
96
|
+
if (!idsSku.includes(listVtex[i]?.itemId)) {
|
|
97
|
+
idsSku.push(listVtex[i]?.itemId);
|
|
98
|
+
listProcess.push({
|
|
99
|
+
boxUnit: registerExternal?.boxUnit,
|
|
100
|
+
infoUnit: registerExternal?.infoUnit,
|
|
101
|
+
is_active: registerExternal?.is_active,
|
|
102
|
+
sku: registerExternal?.sku,
|
|
103
|
+
quantity_pmp: registerExternal?.quantity_pmp,
|
|
104
|
+
itemId: listVtex[i]?.itemId,
|
|
105
|
+
productId: listVtex[i]?.productId,
|
|
106
|
+
TradePolicyId:listVtex[i]?.TradePolicyId
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} catch (error){
|
|
112
|
+
Logger.error("getListProductProcess", error);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return listProcess;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Complete the product presentation process.
|
|
121
|
+
*
|
|
122
|
+
* @param {Object} event - The event object containing the request details.
|
|
123
|
+
* @param {Array<Object>} event.Records - List of records from the event.
|
|
124
|
+
* @param {Object} event.Records[].body - The body of the record containing the message.
|
|
125
|
+
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating success or failure.
|
|
126
|
+
* @throws {Error} - If an error occurs during the execution.
|
|
127
|
+
*/
|
|
128
|
+
module.exports.completeProductPresentation= async (event)=>{
|
|
129
|
+
for (const record of event.Records) {
|
|
130
|
+
const body = JSON.parse(record.body);
|
|
131
|
+
if (body) {
|
|
132
|
+
const account = body?.account;
|
|
133
|
+
Logger.setAccount(account);
|
|
134
|
+
const SkuId = body?.SkuId;
|
|
135
|
+
const geoSalesProduct = body?.geoSalesProduct;
|
|
136
|
+
const TradePolicyId = body?.TradePolicyId;
|
|
137
|
+
|
|
138
|
+
if (!account || !SkuId || !geoSalesProduct) {
|
|
139
|
+
Logger.error("account or SkuId or geoSalesProduct not found: ", body);
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
Logger.debug("JSON account: ", account);
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
await InventoryData.setPresentationsSellers(account, SkuId, geoSalesProduct, TradePolicyId)
|
|
146
|
+
Logger.debug("process multi presentation complete");
|
|
147
|
+
return true;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
Logger.error("process multi presentation error", error);
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
}
|