@zauru-sdk/utils 2.0.12 → 2.0.14

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,6 +1,75 @@
1
- import { getHeaders, getSession } from "@zauru-sdk/services";
1
+ import { getHeaders, getSession, updateReceivedPurchaseOrder, } from "@zauru-sdk/services";
2
+ import { deleteQueueShipmentsFormHistory, updateQueueShipmentsFormHistory, } from "./4pinos-shipments-form-history.utils.js";
3
+ import { ESTADOS_COLA_RECEPCIONES } from "./4pinos-receptions-form-history.utils.js";
2
4
  export const register4pinosShipment = async ({ cookie, idWebAppTable, agency_id, values, }) => {
3
5
  const session = await getSession(cookie);
4
6
  const headers = await getHeaders(cookie, session);
5
- console.log(values);
7
+ try {
8
+ //PASO 1: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA
9
+ for (const purchaseOrder of values.purchase_orders) {
10
+ const response = await updateReceivedPurchaseOrder(headers, {
11
+ purchase_order: {
12
+ shipment_number: values.shipment_number,
13
+ },
14
+ }, purchaseOrder.id);
15
+ if (response.error) {
16
+ throw new Error(`Error al actualizar la orden de compra ${purchaseOrder.id}: ${response.userMsg}`);
17
+ }
18
+ }
19
+ console.log("========================================>");
20
+ console.log("paso 4: ELIMINAR EL REGISTRO DE LA COLA");
21
+ //ELIMINAR EL REGISTRO DE LA COLA
22
+ await deleteQueueShipmentsFormHistory(headers, session, idWebAppTable.toString());
23
+ }
24
+ catch (e) {
25
+ console.log("========================================>");
26
+ console.log("paso -1: ACTUALIZAR EL REGISTRO DE LA COLA A ERROR");
27
+ console.error(`Error: ${e?.toString()}, idWebAppTable: ${idWebAppTable}`);
28
+ await updateQueueShipmentsFormHistory(headers, session, {
29
+ estado: ESTADOS_COLA_RECEPCIONES.ERROR,
30
+ description: e?.toString(),
31
+ }, idWebAppTable);
32
+ }
33
+ };
34
+ export const retryShipmennt = async (register, session, headers, hostname, cookie) => {
35
+ console.log("REINTENTO DE REGISTRO DE ENVÍO =======================>");
36
+ const queueResponse = await updateQueueShipmentsFormHistory(headers, session, {
37
+ estado: ESTADOS_COLA_RECEPCIONES.REINTENTANDO,
38
+ }, register.id);
39
+ if (queueResponse.error || !queueResponse.data?.id) {
40
+ return {
41
+ error: true,
42
+ title: "No se logró comunicar con la red.",
43
+ type: "error",
44
+ description: `No hay comunicación con la red para el reintento: ${queueResponse?.userMsg}`,
45
+ };
46
+ }
47
+ if (hostname.includes("localhost")) {
48
+ console.log("------- EJECUTANDO LOCALMENTE", ` para ${register.data?.formSubmited?.shipment_number}`);
49
+ register4pinosShipment({
50
+ values: register.data?.formSubmited,
51
+ cookie: cookie || "",
52
+ idWebAppTable: register.id,
53
+ agency_id: register.data?.agency_id,
54
+ });
55
+ }
56
+ else {
57
+ console.log("------- ENVIANDO A EJECUTAR NETLIFY FUNCTION: 4pinosNewShipment-background", ` para ${register.data?.formSubmited?.shipment_number}`);
58
+ fetch(`https://${hostname}/.netlify/functions/4pinosNewShipment-background`, {
59
+ method: "post",
60
+ headers: { "Content-type": "application/json" },
61
+ body: JSON.stringify({
62
+ values: register.data?.formSubmited,
63
+ cookie: cookie || "",
64
+ idWebAppTable: register.id,
65
+ agency_id: register.data?.agency_id,
66
+ }),
67
+ });
68
+ }
69
+ return {
70
+ error: false,
71
+ title: "Reintento iniciado con éxito.",
72
+ type: "success",
73
+ description: `Se está procesando el reintento de ingreso de recepción!.`,
74
+ };
6
75
  };
@@ -1,3 +1,6 @@
1
+ import { Session } from "@remix-run/node";
2
+ import { QueueShipmentsForm } from "@zauru-sdk/types";
3
+ import { WebAppRowGraphQL } from "@zauru-sdk/types";
1
4
  export declare const register4pinosShipment: ({ cookie, idWebAppTable, agency_id, values, }: {
2
5
  cookie: string;
3
6
  idWebAppTable: number;
@@ -14,3 +17,9 @@ export declare const register4pinosShipment: ({ cookie, idWebAppTable, agency_id
14
17
  }[];
15
18
  };
16
19
  }) => Promise<void>;
20
+ export declare const retryShipmennt: (register: WebAppRowGraphQL<QueueShipmentsForm>, session: Session, headers: any, hostname: string, cookie: string | null) => Promise<{
21
+ error: boolean;
22
+ title: string;
23
+ type: string;
24
+ description: string;
25
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/utils",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
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.11",
27
+ "@zauru-sdk/common": "^2.0.13",
28
28
  "@zauru-sdk/config": "^2.0.0",
29
29
  "@zauru-sdk/graphql": "^2.0.7",
30
- "@zauru-sdk/services": "^2.0.11",
31
- "@zauru-sdk/types": "^2.0.10"
30
+ "@zauru-sdk/services": "^2.0.13",
31
+ "@zauru-sdk/types": "^2.0.13"
32
32
  },
33
- "gitHead": "a4ea888baa4cb398db3986bb3ddf55b38e56c97b"
33
+ "gitHead": "d2ff8b2319a6bbac7a864ff258bf5b3e1315e56c"
34
34
  }