@zauru-sdk/utils 2.0.24 → 2.0.26

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,46 +1,54 @@
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
- //PASO 1: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA
9
- console.log("========================================>");
10
- console.log("paso 1: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA");
11
- for (const purchaseOrder of values.purchase_orders) {
12
- const response = await updateReceivedPurchaseOrder(headers, {
13
- purchase_order: {
14
- shipment_reference: values.shipment_reference,
15
- },
16
- }, purchaseOrder.id);
17
- if (response.error) {
18
- throw new Error(`Error al actualizar la orden de compra ${purchaseOrder.id}: ${response.userMsg}`);
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
+ needs_transport: true,
21
+ movements: values.purchase_orders.map((purchaseOrder) => ({
22
+ lot_id: purchaseOrder.lot_id,
23
+ booked_quantity: purchaseOrder.booked_quantity,
24
+ item_id: purchaseOrder.item_id,
25
+ })),
26
+ };
27
+ console.log("========================================>");
28
+ console.log("paso 1: CREAR EL ENVIO");
29
+ console.log("Enviando: ", JSON.stringify(shipmentBody));
30
+ const createBookingResponse = await insertBookings(headers, shipmentBody);
31
+ if (createBookingResponse.error) {
32
+ throw new Error(`Error al crear el envío: ${createBookingResponse.userMsg} con el body: ${JSON.stringify(shipmentBody)}`);
19
33
  }
20
34
  }
21
- //PASO 2: CREAR EL ENVIO
22
- const shipmentBody = {
23
- reference: `Envío: ${values.shipment_reference} realizado desde la aplicación web.`,
24
- agency_from_id: values.agency_from_id,
25
- agency_to_id: values.agency_to_id,
26
- booker_id: values.booker_id,
27
- id_number: values.shipment_reference,
28
- transporter_id: values.transporter_id,
29
- planned_delivery: values.planned_delivery,
30
- planned_shipping: values.planned_shipping,
31
- movements: values.purchase_orders.map((purchaseOrder) => ({
32
- lot_id: purchaseOrder.lot_id,
33
- booked_quantity: purchaseOrder.booked_quantity,
34
- item_id: purchaseOrder.item_id,
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)}`);
35
+ proccess_step++;
36
+ if (proccess_step === 2) {
37
+ //PASO 2: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA
38
+ console.log("========================================>");
39
+ console.log("paso 2: COLOCO EL NUMERO DE ENVIO EN TODAS LAS ORDENES DE COMPRA");
40
+ for (const purchaseOrder of values.purchase_orders) {
41
+ const response = await updateReceivedPurchaseOrder(headers, {
42
+ purchase_order: {
43
+ shipment_reference: values.shipment_reference,
44
+ },
45
+ }, purchaseOrder.id);
46
+ if (response.error) {
47
+ throw new Error(`Error al actualizar la orden de compra ${purchaseOrder.id}: ${response.userMsg}`);
48
+ }
49
+ }
43
50
  }
51
+ proccess_step++;
44
52
  console.log("========================================>");
45
53
  console.log("paso 3: ELIMINAR EL REGISTRO DE LA COLA");
46
54
  //ELIMINAR EL REGISTRO DE LA COLA
@@ -53,6 +61,7 @@ export const register4pinosShipment = async ({ cookie, idWebAppTable, values, })
53
61
  await updateQueueShipmentsFormHistory(headers, session, {
54
62
  estado: ESTADOS_COLA_RECEPCIONES.ERROR,
55
63
  description: e?.toString(),
64
+ apiStep: proccess_step,
56
65
  }, idWebAppTable);
57
66
  }
58
67
  };
@@ -75,6 +84,7 @@ export const retryShipmennt = async (register, session, headers, hostname, cooki
75
84
  values: register.data?.formSubmited,
76
85
  cookie: cookie || "",
77
86
  idWebAppTable: register.id,
87
+ apiStep: register.data?.apiStep,
78
88
  });
79
89
  }
80
90
  else {
@@ -86,6 +96,7 @@ export const retryShipmennt = async (register, session, headers, hostname, cooki
86
96
  values: register.data?.formSubmited,
87
97
  cookie: cookie || "",
88
98
  idWebAppTable: register.id,
99
+ apiStep: register.data?.apiStep,
89
100
  }),
90
101
  });
91
102
  }
@@ -1,5 +1,5 @@
1
1
  import { getDatePickerCurrentDate, handlePossibleAxiosErrors, reduceAdd, } from "@zauru-sdk/common";
2
- import { getDeliveryByBooking, getMyAgencyLotStocks, getShipmentsByToAgencyLast100Id_booking, getVariablesByName, insertBookings, } from "@zauru-sdk/services";
2
+ import { getDeliveryByBooking, getMyAgencyLotStocks, getShipments, getVariablesByName, insertBookings, } from "@zauru-sdk/services";
3
3
  /**
4
4
  *
5
5
  * @param headers
@@ -8,7 +8,7 @@ import { getDeliveryByBooking, getMyAgencyLotStocks, getShipmentsByToAgencyLast1
8
8
  */
9
9
  export const getShipmentsToMyAgency = async (session) => {
10
10
  return handlePossibleAxiosErrors(async () => {
11
- const response = await getShipmentsByToAgencyLast100Id_booking(session, session.get("agency_id"));
11
+ const response = await getShipments(session, session.get("agency_id"));
12
12
  if (response.error) {
13
13
  throw new Error(`Ocurrió un error al consultar los envíos a mi agencia actual: ${response.userMsg}`);
14
14
  }
@@ -1,9 +1,10 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/utils",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
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",
@@ -26,9 +26,9 @@
26
26
  "@remix-run/node": "^2.8.1",
27
27
  "@zauru-sdk/common": "^2.0.24",
28
28
  "@zauru-sdk/config": "^2.0.0",
29
- "@zauru-sdk/graphql": "^2.0.23",
30
- "@zauru-sdk/services": "^2.0.24",
29
+ "@zauru-sdk/graphql": "^2.0.26",
30
+ "@zauru-sdk/services": "^2.0.26",
31
31
  "@zauru-sdk/types": "^2.0.24"
32
32
  },
33
- "gitHead": "4246f96df338c55f7c90d565f466691de6729ec2"
33
+ "gitHead": "41440682edbc853c6e9ce4f7c982dbf4ac9a185b"
34
34
  }