@zauru-sdk/utils 2.0.23 → 2.0.25
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.
|
@@ -1,45 +1,50 @@
|
|
|
1
1
|
import { getHeaders, getSession, insertBookings, updateReceivedPurchaseOrder, } from "@zauru-sdk/services";
|
|
2
2
|
import { deleteQueueShipmentsFormHistory, updateQueueShipmentsFormHistory, } from "./4pinos-shipments-form-history.utils.js";
|
|
3
3
|
import { ESTADOS_COLA_RECEPCIONES } from "./4pinos-receptions-form-history.utils.js";
|
|
4
|
-
export const register4pinosShipment = async ({ cookie, idWebAppTable, values, }) => {
|
|
4
|
+
export const register4pinosShipment = async ({ cookie, idWebAppTable, apiStep, values, }) => {
|
|
5
5
|
const session = await getSession(cookie);
|
|
6
6
|
const headers = await getHeaders(cookie, session);
|
|
7
|
+
let proccess_step = apiStep ?? 1;
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (proccess_step === 1) {
|
|
10
|
+
//PASO 1: CREAR EL ENVIO
|
|
11
|
+
const shipmentBody = {
|
|
12
|
+
reference: `Envío: ${values.shipment_reference} realizado desde la aplicación web.`,
|
|
13
|
+
agency_from_id: values.agency_from_id,
|
|
14
|
+
agency_to_id: values.agency_to_id,
|
|
15
|
+
booker_id: values.booker_id,
|
|
16
|
+
id_number: values.shipment_reference,
|
|
17
|
+
transporter_id: values.transporter_id,
|
|
18
|
+
planned_delivery: values.planned_delivery,
|
|
19
|
+
planned_shipping: values.planned_shipping,
|
|
20
|
+
movements: values.purchase_orders.map((purchaseOrder) => ({
|
|
21
|
+
lot_id: purchaseOrder.lot_id,
|
|
22
|
+
booked_quantity: purchaseOrder.booked_quantity,
|
|
23
|
+
item_id: purchaseOrder.item_id,
|
|
24
|
+
})),
|
|
25
|
+
};
|
|
26
|
+
console.log("========================================>");
|
|
27
|
+
console.log("paso 1: CREAR EL ENVIO");
|
|
28
|
+
console.log("Enviando: ", JSON.stringify(shipmentBody));
|
|
29
|
+
const createBookingResponse = await insertBookings(headers, shipmentBody);
|
|
30
|
+
if (createBookingResponse.error) {
|
|
31
|
+
throw new Error(`Error al crear el envío: ${createBookingResponse.userMsg} con el body: ${JSON.stringify(shipmentBody)}`);
|
|
19
32
|
}
|
|
20
33
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})),
|
|
36
|
-
};
|
|
37
|
-
console.log("========================================>");
|
|
38
|
-
console.log("paso 2: CREAR EL ENVIO");
|
|
39
|
-
console.log("Enviando: ", JSON.stringify(shipmentBody));
|
|
40
|
-
const createBookingResponse = await insertBookings(headers, shipmentBody);
|
|
41
|
-
if (createBookingResponse.error) {
|
|
42
|
-
throw new Error(`Error al crear el envío: ${createBookingResponse.userMsg} con el body: ${JSON.stringify(shipmentBody)}`);
|
|
34
|
+
if (proccess_step === 2) {
|
|
35
|
+
//PASO 2: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA
|
|
36
|
+
console.log("========================================>");
|
|
37
|
+
console.log("paso 2: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA");
|
|
38
|
+
for (const purchaseOrder of values.purchase_orders) {
|
|
39
|
+
const response = await updateReceivedPurchaseOrder(headers, {
|
|
40
|
+
purchase_order: {
|
|
41
|
+
shipment_reference: values.shipment_reference,
|
|
42
|
+
},
|
|
43
|
+
}, purchaseOrder.id);
|
|
44
|
+
if (response.error) {
|
|
45
|
+
throw new Error(`Error al actualizar la orden de compra ${purchaseOrder.id}: ${response.userMsg}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
console.log("========================================>");
|
|
45
50
|
console.log("paso 3: ELIMINAR EL REGISTRO DE LA COLA");
|
|
@@ -53,6 +58,7 @@ export const register4pinosShipment = async ({ cookie, idWebAppTable, values, })
|
|
|
53
58
|
await updateQueueShipmentsFormHistory(headers, session, {
|
|
54
59
|
estado: ESTADOS_COLA_RECEPCIONES.ERROR,
|
|
55
60
|
description: e?.toString(),
|
|
61
|
+
apiStep: proccess_step,
|
|
56
62
|
}, idWebAppTable);
|
|
57
63
|
}
|
|
58
64
|
};
|
|
@@ -70,15 +76,16 @@ export const retryShipmennt = async (register, session, headers, hostname, cooki
|
|
|
70
76
|
};
|
|
71
77
|
}
|
|
72
78
|
if (hostname.includes("localhost")) {
|
|
73
|
-
console.log("------- EJECUTANDO LOCALMENTE", ` para ${register.data?.formSubmited?.
|
|
79
|
+
console.log("------- EJECUTANDO LOCALMENTE", ` para ${register.data?.formSubmited?.shipment_reference}`);
|
|
74
80
|
register4pinosShipment({
|
|
75
81
|
values: register.data?.formSubmited,
|
|
76
82
|
cookie: cookie || "",
|
|
77
83
|
idWebAppTable: register.id,
|
|
84
|
+
apiStep: register.data?.apiStep,
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
87
|
else {
|
|
81
|
-
console.log("------- ENVIANDO A EJECUTAR NETLIFY FUNCTION: 4pinosNewShipment-background", ` para ${register.data?.formSubmited?.
|
|
88
|
+
console.log("------- ENVIANDO A EJECUTAR NETLIFY FUNCTION: 4pinosNewShipment-background", ` para ${register.data?.formSubmited?.shipment_reference}`);
|
|
82
89
|
fetch(`https://${hostname}/.netlify/functions/4pinosNewShipment-background`, {
|
|
83
90
|
method: "post",
|
|
84
91
|
headers: { "Content-type": "application/json" },
|
|
@@ -86,6 +93,7 @@ export const retryShipmennt = async (register, session, headers, hostname, cooki
|
|
|
86
93
|
values: register.data?.formSubmited,
|
|
87
94
|
cookie: cookie || "",
|
|
88
95
|
idWebAppTable: register.id,
|
|
96
|
+
apiStep: register.data?.apiStep,
|
|
89
97
|
}),
|
|
90
98
|
});
|
|
91
99
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Session } from "@remix-run/node";
|
|
2
2
|
import { QueueShipmentsForm } from "@zauru-sdk/types";
|
|
3
3
|
import { WebAppRowGraphQL } from "@zauru-sdk/types";
|
|
4
|
-
export declare const register4pinosShipment: ({ cookie, idWebAppTable, values, }: {
|
|
4
|
+
export declare const register4pinosShipment: ({ cookie, idWebAppTable, apiStep, values, }: {
|
|
5
5
|
cookie: string;
|
|
6
6
|
idWebAppTable: number;
|
|
7
|
+
apiStep?: number;
|
|
7
8
|
values: {
|
|
8
9
|
booker_id: number;
|
|
9
10
|
agency_from_id: number;
|
|
10
11
|
transporter_id: number;
|
|
11
12
|
planned_shipping: string;
|
|
12
13
|
planned_delivery: string;
|
|
13
|
-
|
|
14
|
+
shipment_reference: string;
|
|
14
15
|
agency_to_id: number;
|
|
15
16
|
purchase_orders: {
|
|
16
17
|
id: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.25",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
|
-
"@zauru-sdk/common": "^2.0.
|
|
27
|
+
"@zauru-sdk/common": "^2.0.24",
|
|
28
28
|
"@zauru-sdk/config": "^2.0.0",
|
|
29
29
|
"@zauru-sdk/graphql": "^2.0.23",
|
|
30
|
-
"@zauru-sdk/services": "^2.0.
|
|
31
|
-
"@zauru-sdk/types": "^2.0.
|
|
30
|
+
"@zauru-sdk/services": "^2.0.24",
|
|
31
|
+
"@zauru-sdk/types": "^2.0.24"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "a0bcb4eb932b6a75401b9f25e24d74e6a1ed16ec"
|
|
34
34
|
}
|