@zauru-sdk/services 1.0.6 → 1.0.8

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.d.ts +23 -0
  3. package/dist/index.js +23 -0
  4. package/dist/zauru/zauru-bookings.server.d.ts +28 -0
  5. package/dist/zauru/zauru-bookings.server.js +80 -0
  6. package/dist/zauru/zauru-bundles.service.d.ts +28 -0
  7. package/dist/zauru/zauru-bundles.service.js +93 -0
  8. package/dist/zauru/zauru-cases.server.d.ts +6 -0
  9. package/dist/zauru/zauru-cases.server.js +23 -0
  10. package/dist/zauru/zauru-consolidated.server.d.ts +36 -0
  11. package/dist/zauru/zauru-consolidated.server.js +71 -0
  12. package/dist/zauru/zauru-currencies.server.d.ts +6 -0
  13. package/dist/zauru/zauru-currencies.server.js +20 -0
  14. package/dist/zauru/zauru-deliveries.server.d.ts +22 -0
  15. package/dist/zauru/zauru-deliveries.server.js +44 -0
  16. package/dist/zauru/zauru-discharges.server.d.ts +26 -0
  17. package/dist/zauru/zauru-discharges.server.js +46 -0
  18. package/dist/zauru/zauru-employees.server.d.ts +6 -0
  19. package/dist/zauru/zauru-employees.server.js +23 -0
  20. package/dist/zauru/zauru-forms.server.d.ts +96 -0
  21. package/dist/zauru/zauru-forms.server.js +343 -0
  22. package/dist/zauru/zauru-invoices.server.d.ts +26 -0
  23. package/dist/zauru/zauru-invoices.server.js +94 -0
  24. package/dist/zauru/zauru-items.server.d.ts +91 -0
  25. package/dist/zauru/zauru-items.server.js +238 -0
  26. package/dist/zauru/zauru-lote-record.server.d.ts +8 -0
  27. package/dist/zauru/zauru-lote-record.server.js +26 -0
  28. package/dist/zauru/zauru-lotes.server.d.ts +91 -0
  29. package/dist/zauru/zauru-lotes.server.js +294 -0
  30. package/dist/zauru/zauru-motivos-rechazo.server.d.ts +9 -0
  31. package/dist/zauru/zauru-motivos-rechazo.server.js +49 -0
  32. package/dist/zauru/zauru-payees.server.d.ts +97 -0
  33. package/dist/zauru/zauru-payees.server.js +227 -0
  34. package/dist/zauru/zauru-payment-terms.server.d.ts +20 -0
  35. package/dist/zauru/zauru-payment-terms.server.js +65 -0
  36. package/dist/zauru/zauru-price-lists.server.d.ts +22 -0
  37. package/dist/zauru/zauru-price-lists.server.js +40 -0
  38. package/dist/zauru/zauru-purchase-orders.server.d.ts +160 -0
  39. package/dist/zauru/zauru-purchase-orders.server.js +414 -0
  40. package/dist/zauru/zauru-receptions.server.d.ts +33 -0
  41. package/dist/zauru/zauru-receptions.server.js +94 -0
  42. package/dist/zauru/zauru-shipments.server.d.ts +20 -0
  43. package/dist/zauru/zauru-shipments.server.js +53 -0
  44. package/dist/zauru/zauru-suggested-prices.server.d.ts +30 -0
  45. package/dist/zauru/zauru-suggested-prices.server.js +83 -0
  46. package/dist/zauru/zauru-tags.server.d.ts +7 -0
  47. package/dist/zauru/zauru-tags.server.js +13 -0
  48. package/dist/zauru/zauru-templates.server.d.ts +7 -0
  49. package/dist/zauru/zauru-templates.server.js +15 -0
  50. package/dist/zauru/zauru-web-app-tables.server.d.ts +48 -0
  51. package/dist/zauru/zauru-web-app-tables.server.js +120 -0
  52. package/package.json +6 -6
  53. package/src/index.ts +23 -0
  54. package/src/zauru/zauru-bookings.server.ts +134 -0
  55. package/src/zauru/zauru-bundles.service.ts +157 -0
  56. package/src/zauru/zauru-cases.server.ts +44 -0
  57. package/src/zauru/zauru-consolidated.server.ts +129 -0
  58. package/src/zauru/zauru-currencies.server.ts +39 -0
  59. package/src/zauru/zauru-deliveries.server.ts +70 -0
  60. package/src/zauru/zauru-discharges.server.ts +90 -0
  61. package/src/zauru/zauru-employees.server.ts +43 -0
  62. package/src/zauru/zauru-forms.server.ts +618 -0
  63. package/src/zauru/zauru-invoices.server.ts +142 -0
  64. package/src/zauru/zauru-items.server.ts +427 -0
  65. package/src/zauru/zauru-lote-record.server.ts +77 -0
  66. package/src/zauru/zauru-lotes.server.ts +484 -0
  67. package/src/zauru/zauru-motivos-rechazo.server.ts +121 -0
  68. package/src/zauru/zauru-payees.server.ts +398 -0
  69. package/src/zauru/zauru-payment-terms.server.ts +126 -0
  70. package/src/zauru/zauru-price-lists.server.ts +68 -0
  71. package/src/zauru/zauru-purchase-orders.server.ts +701 -0
  72. package/src/zauru/zauru-receptions.server.ts +148 -0
  73. package/src/zauru/zauru-shipments.server.ts +88 -0
  74. package/src/zauru/zauru-suggested-prices.server.ts +134 -0
  75. package/src/zauru/zauru-tags.server.ts +22 -0
  76. package/src/zauru/zauru-templates.server.ts +24 -0
  77. package/src/zauru/zauru-web-app-tables.server.ts +200 -0
@@ -0,0 +1,83 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpZauru from "./httpZauru.server.js";
3
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
4
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
5
+ import { getSuggestedPricesStringQuery } from "@zauru-sdk/graphql";
6
+ /**
7
+ *
8
+ * @param headers
9
+ * @returns
10
+ */
11
+ export const getSuggestedPricesExportJSON = async (headers) => {
12
+ return handlePossibleAxiosErrors(async () => {
13
+ const response = await httpZauru.get(`/sales/suggested_prices/export.json`, {
14
+ headers,
15
+ });
16
+ return response.data;
17
+ });
18
+ };
19
+ /**
20
+ * getSuggestedPrices
21
+ * @param session
22
+ * @param id
23
+ */
24
+ export async function getSuggestedPrices(session, config) {
25
+ return handlePossibleAxiosErrors(async () => {
26
+ const { notNullPriceList = false, withItems = false, withItemCategories = false, } = config;
27
+ const headers = await getGraphQLAPIHeaders(session);
28
+ const response = await httpGraphQLAPI.post("", {
29
+ query: getSuggestedPricesStringQuery({
30
+ notNullPriceList,
31
+ withItems,
32
+ withItemCategories,
33
+ }),
34
+ }, { headers });
35
+ if (response.data.errors) {
36
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
37
+ }
38
+ return response?.data?.data?.suggested_prices ?? [];
39
+ });
40
+ }
41
+ /**
42
+ * createSuggestedPrice
43
+ * @param headers
44
+ * @param body
45
+ */
46
+ export async function createSuggestedPrice(headers, body) {
47
+ return handlePossibleAxiosErrors(async () => {
48
+ const response = await httpZauru.post(`/sales/suggested_prices.json`, { suggested_price: body }, { headers });
49
+ return response.data;
50
+ });
51
+ }
52
+ //No existe actualizar
53
+ // /**
54
+ // * updateSuggestedPrice
55
+ // * @param headers
56
+ // * @param body
57
+ // */
58
+ // export async function updateSuggestedPrice(
59
+ // headers: any,
60
+ // body: Partial<SuggestedPriceGraphQL>
61
+ // ): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL>> {
62
+ // return handlePossibleAxiosErrors(async () => {
63
+ // const response = await httpZauru.patch<SuggestedPriceGraphQL>(
64
+ // `/sales/suggested_prices.json`,
65
+ // { suggested_price: body },
66
+ // { headers }
67
+ // );
68
+ // return response.data;
69
+ // });
70
+ // }
71
+ /**
72
+ * deleteSuggestedPrice
73
+ * @param headers
74
+ * @param body
75
+ */
76
+ export async function deleteSuggestedPrice(headers, id) {
77
+ return handlePossibleAxiosErrors(async () => {
78
+ await httpZauru.delete(`/sales/suggested_prices/${id}?destroy=true`, {
79
+ headers,
80
+ });
81
+ return true;
82
+ });
83
+ }
@@ -0,0 +1,7 @@
1
+ import { AxiosUtilsResponse, TagGraphQL } from "@zauru-sdk/types";
2
+ /**
3
+ * createTag
4
+ * @param headers
5
+ * @param body
6
+ */
7
+ export declare function createTag(headers: any, body: Partial<TagGraphQL>): Promise<AxiosUtilsResponse<TagGraphQL>>;
@@ -0,0 +1,13 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpZauru from "./httpZauru.server.js";
3
+ /**
4
+ * createTag
5
+ * @param headers
6
+ * @param body
7
+ */
8
+ export async function createTag(headers, body) {
9
+ return handlePossibleAxiosErrors(async () => {
10
+ const response = await httpZauru.post(`/settings/tags.json`, { tag: body }, { headers });
11
+ return response.data;
12
+ });
13
+ }
@@ -0,0 +1,7 @@
1
+ import { AxiosUtilsResponse } from "@zauru-sdk/types";
2
+ /**
3
+ *
4
+ * @param headers
5
+ * @returns
6
+ */
7
+ export declare const getReceptionTemplate: (headers: any, id: string | number) => Promise<AxiosUtilsResponse<string>>;
@@ -0,0 +1,15 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpZauru from "./httpZauru.server.js";
3
+ /**
4
+ *
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export const getReceptionTemplate = async (headers, id) => {
9
+ return handlePossibleAxiosErrors(async () => {
10
+ const response = await httpZauru.get(`/settings/templates/print_templates/${id}/preview_with_vars`, {
11
+ headers,
12
+ });
13
+ return response.data;
14
+ });
15
+ };
@@ -0,0 +1,48 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, WebAppRowGraphQL, WebAppTableCreateBody, WebAppTableGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
3
+ /**
4
+ * getWebAppRow
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare function getWebAppRow<T>(session: Session, id: number): Promise<AxiosUtilsResponse<T>>;
9
+ /**
10
+ * getWebAppTableRegisters Function for get all web app table registers
11
+ * @param headers
12
+ * @param webapp_table_id web app table id
13
+ * @returns
14
+ */
15
+ export declare function getWebAppTableRegisters<T>(session: Session, webapp_table_id: string): Promise<AxiosUtilsResponse<WebAppRowGraphQL<T>[]>>;
16
+ /**
17
+ * deleteWebAppTableRegister Function for delete a web app table register
18
+ * @param headers
19
+ * @param id_web_app_table
20
+ * @param id_register
21
+ * @returns
22
+ */
23
+ export declare function deleteWebAppTableRegister(headers: any, id_web_app_table: string, id_register: number): Promise<WebAppTableUpdateResponse>;
24
+ /**
25
+ * createWebAppTableRegister function for create a new web app table register
26
+ * @param headers
27
+ * @param body
28
+ * @param id_web_app_table
29
+ * @returns
30
+ */
31
+ export declare function createWebAppTableRegister<T>(headers: any, id_web_app_table: string, body: T, extraBody?: {
32
+ temp_purchase_order_id: string;
33
+ }): Promise<WebAppTableUpdateResponse>;
34
+ /**
35
+ * updateWebAppTableRegister Function for update a web app table register
36
+ * @param headers
37
+ * @param id_web_app_table
38
+ * @param id_register
39
+ * @returns
40
+ */
41
+ export declare function updateWebAppTableRegister<T>(headers: any, id_web_app_table: string, id_register: number | string, body: Partial<T>): Promise<WebAppTableUpdateResponse>;
42
+ /**
43
+ *
44
+ * @param headers
45
+ * @param body
46
+ * @returns
47
+ */
48
+ export declare function createWebAppTable(headers: any, body: WebAppTableCreateBody): Promise<AxiosUtilsResponse<WebAppTableGraphQL>>;
@@ -0,0 +1,120 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
3
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
4
+ import { getWebAppRowStringQuery, getWebAppRowsByWebAppTableIdStringQuery, } from "@zauru-sdk/graphql";
5
+ import httpZauru from "./httpZauru.server.js";
6
+ /**
7
+ * getWebAppRow
8
+ * @param headers
9
+ * @returns
10
+ */
11
+ export async function getWebAppRow(session, id) {
12
+ return handlePossibleAxiosErrors(async () => {
13
+ const headers = await getGraphQLAPIHeaders(session);
14
+ const response = await httpGraphQLAPI.post("", {
15
+ query: getWebAppRowStringQuery,
16
+ variables: {
17
+ id,
18
+ },
19
+ }, { headers });
20
+ return response.data?.data?.webapp_rows[0]?.data;
21
+ });
22
+ }
23
+ /**
24
+ * getWebAppTableRegisters Function for get all web app table registers
25
+ * @param headers
26
+ * @param webapp_table_id web app table id
27
+ * @returns
28
+ */
29
+ export async function getWebAppTableRegisters(session, webapp_table_id) {
30
+ return handlePossibleAxiosErrors(async () => {
31
+ const headers = await getGraphQLAPIHeaders(session);
32
+ const response = await httpGraphQLAPI.post("", {
33
+ query: getWebAppRowsByWebAppTableIdStringQuery,
34
+ variables: {
35
+ webapp_table_id,
36
+ },
37
+ }, { headers });
38
+ if (response.data.errors) {
39
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
40
+ }
41
+ if (!response?.data?.data.webapp_rows) {
42
+ return [];
43
+ }
44
+ return response.data?.data?.webapp_rows;
45
+ });
46
+ }
47
+ /**
48
+ * deleteWebAppTableRegister Function for delete a web app table register
49
+ * @param headers
50
+ * @param id_web_app_table
51
+ * @param id_register
52
+ * @returns
53
+ */
54
+ export async function deleteWebAppTableRegister(headers, id_web_app_table, id_register) {
55
+ const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows/${id_register}.json`, {
56
+ method: "DELETE",
57
+ headers: headers,
58
+ });
59
+ return response.data;
60
+ }
61
+ /**
62
+ * createWebAppTableRegister function for create a new web app table register
63
+ * @param headers
64
+ * @param body
65
+ * @param id_web_app_table
66
+ * @returns
67
+ */
68
+ export async function createWebAppTableRegister(headers, id_web_app_table, body, extraBody) {
69
+ const requestBody = {
70
+ webapp_row: { data: body },
71
+ ...(extraBody ?? {}),
72
+ };
73
+ const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows.json`, {
74
+ method: "POST",
75
+ headers: headers,
76
+ data: requestBody,
77
+ });
78
+ return response.data;
79
+ }
80
+ /**
81
+ * updateWebAppTableRegister Function for update a web app table register
82
+ * @param headers
83
+ * @param id_web_app_table
84
+ * @param id_register
85
+ * @returns
86
+ */
87
+ export async function updateWebAppTableRegister(headers, id_web_app_table, id_register, body) {
88
+ const requestBody = { webapp_row: { data: body } };
89
+ const response = await httpZauru(`/apps/webapp_tables/${id_web_app_table}/webapp_rows/${id_register}.json`, {
90
+ method: "PATCH",
91
+ headers: headers,
92
+ data: requestBody,
93
+ });
94
+ return response.data;
95
+ }
96
+ //============================== WEB APP TABLE
97
+ /**
98
+ *
99
+ * @param headers
100
+ * @param body
101
+ * @returns
102
+ */
103
+ export async function createWebAppTable(headers, body) {
104
+ try {
105
+ const response = await httpZauru.post(`/apps/webapp_tables.json`, { webapp_table: body }, {
106
+ headers,
107
+ });
108
+ return {
109
+ data: response.data,
110
+ error: false,
111
+ };
112
+ }
113
+ catch (error) {
114
+ return {
115
+ msg: error,
116
+ error: true,
117
+ userMsg: `Ocurrió un error al intentar crear la web app table ${body.name}`,
118
+ };
119
+ }
120
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "1.0.6",
4
- "description": "Configuración centralizada para aplicaciones Zauru SDK",
3
+ "version": "1.0.8",
4
+ "description": "Servicios de consulta a Zauru",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
@@ -19,15 +19,15 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@remix-run/node": "^2.8.1",
22
- "@zauru-sdk/common": "^1.0.6",
22
+ "@zauru-sdk/common": "^1.0.8",
23
23
  "@zauru-sdk/config": "^1.0.4",
24
- "@zauru-sdk/graphql": "^1.0.5",
25
- "@zauru-sdk/types": "^1.0.6",
24
+ "@zauru-sdk/graphql": "^1.0.7",
25
+ "@zauru-sdk/types": "^1.0.8",
26
26
  "axios": "^1.6.7",
27
27
  "chalk": "5.3.0"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=18.0.0"
31
31
  },
32
- "gitHead": "d49d7b1cec4ab5685b34983c46d97db129115aaf"
32
+ "gitHead": "60fc0a94174a359d300c7479bcb8278316857ed9"
33
33
  }
package/src/index.ts CHANGED
@@ -9,5 +9,28 @@ export * from "./zauru/httpZauru.server.js";
9
9
 
10
10
  export * from "./zauru/zauru-agencies.server.js";
11
11
  export * from "./zauru/zauru-automatic-numbers.server.js";
12
+ export * from "./zauru/zauru-bookings.server.js";
13
+ export * from "./zauru/zauru-bundles.service.js";
14
+ export * from "./zauru/zauru-cases.server.js";
15
+ export * from "./zauru/zauru-consolidated.server.js";
16
+ export * from "./zauru/zauru-deliveries.server.js";
17
+ export * from "./zauru/zauru-discharges.server.js";
18
+ export * from "./zauru/zauru-employees.server.js";
19
+ export * from "./zauru/zauru-forms.server.js";
20
+ export * from "./zauru/zauru-invoices.server.js";
21
+ export * from "./zauru/zauru-items.server.js";
22
+ export * from "./zauru/zauru-lote-record.server.js";
23
+ export * from "./zauru/zauru-lotes.server.js";
24
+ export * from "./zauru/zauru-motivos-rechazo.server.js";
25
+ export * from "./zauru/zauru-payees.server.js";
26
+ export * from "./zauru/zauru-payment-terms.server.js";
27
+ export * from "./zauru/zauru-price-lists.server.js";
28
+ export * from "./zauru/zauru-purchase-orders.server.js";
12
29
  export * from "./zauru/zauru-profiles.server.js";
30
+ export * from "./zauru/zauru-receptions.server.js";
31
+ export * from "./zauru/zauru-shipments.server.js";
32
+ export * from "./zauru/zauru-suggested-prices.server.js";
33
+ export * from "./zauru/zauru-tags.server.js";
34
+ export * from "./zauru/zauru-templates.server.js";
35
+ export * from "./zauru/zauru-web-app-tables.server.js";
13
36
  export * from "./zauru/zauru-variables.server.js";
@@ -0,0 +1,134 @@
1
+ import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import {
3
+ AxiosUtilsResponse,
4
+ InsertBookingBody,
5
+ ShipmentGraphQL,
6
+ } from "@zauru-sdk/types";
7
+ import httpZauru from "./httpZauru.server.js";
8
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
9
+ import { Session } from "@remix-run/node";
10
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
11
+ import { getShipmentsStringQuery } from "@zauru-sdk/graphql";
12
+
13
+ /**
14
+ * insertBookings
15
+ * @param headers
16
+ * @param body
17
+ * @returns
18
+ */
19
+ export const insertBookings = async (
20
+ headers: any,
21
+ body: Partial<InsertBookingBody>,
22
+ temp_purchase_order_id?: string
23
+ ): Promise<AxiosUtilsResponse<ShipmentGraphQL>> => {
24
+ return handlePossibleAxiosErrors(async () => {
25
+ const sendBody: any = {
26
+ shipment: {
27
+ ...body,
28
+ movements_attributes: arrayToObject(body.movements),
29
+ },
30
+ };
31
+
32
+ delete sendBody.shipment.movements;
33
+
34
+ if (temp_purchase_order_id) {
35
+ sendBody[`temp_purchase_order_id`] = `${temp_purchase_order_id}`;
36
+ }
37
+
38
+ const response = await httpZauru.post<ShipmentGraphQL>(
39
+ `/inventories/bookings.json`,
40
+ sendBody,
41
+ {
42
+ headers,
43
+ }
44
+ );
45
+
46
+ return response.data;
47
+ });
48
+ };
49
+
50
+ /**
51
+ * getDeliveryByBooking
52
+ * @param headers
53
+ * @param shipment_id
54
+ * @returns
55
+ */
56
+ export const getDeliveryByBooking = async (
57
+ headers: any,
58
+ shipment_id: number
59
+ ) => {
60
+ return handlePossibleAxiosErrors(async () => {
61
+ if (!shipment_id) {
62
+ throw new Error("No hay un shipment_id, en getDeliveryByBooking");
63
+ }
64
+
65
+ const response = await httpZauru.get<any>(
66
+ `/inventories/bookings/${shipment_id}/deliver.json`,
67
+ {
68
+ headers,
69
+ data: {
70
+ id: shipment_id,
71
+ },
72
+ }
73
+ );
74
+
75
+ return response.data;
76
+ });
77
+ };
78
+
79
+ /**
80
+ * getBookings
81
+ * @param headers
82
+ * @returns
83
+ */
84
+ export const getBookings = async (
85
+ session: Session,
86
+ wheres: string[] = []
87
+ ): Promise<AxiosUtilsResponse<ShipmentGraphQL[]>> => {
88
+ return handlePossibleAxiosErrors(async () => {
89
+ const headers = await getGraphQLAPIHeaders(session);
90
+
91
+ const response = await httpGraphQLAPI.post<{
92
+ data: { shipments: ShipmentGraphQL[] };
93
+ errors?: {
94
+ message: string;
95
+ extensions: { path: string; code: string };
96
+ }[];
97
+ }>(
98
+ "",
99
+ {
100
+ query: getShipmentsStringQuery([...wheres, "delivered: {_eq: false}"]),
101
+ },
102
+ { headers }
103
+ );
104
+
105
+ if (response.data.errors) {
106
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
107
+ }
108
+
109
+ const registers = response?.data?.data?.shipments;
110
+
111
+ return registers;
112
+ });
113
+ };
114
+
115
+ /**
116
+ * getBookings
117
+ * @param headers
118
+ * @returns
119
+ */
120
+ export const getBooking = async (
121
+ headers: any,
122
+ booking_id: string
123
+ ): Promise<AxiosUtilsResponse<ShipmentGraphQL>> => {
124
+ return handlePossibleAxiosErrors(async () => {
125
+ const response = await httpZauru.get<any>(
126
+ `/inventories/bookings/${booking_id}.json`,
127
+ {
128
+ headers,
129
+ }
130
+ );
131
+
132
+ return response.data;
133
+ });
134
+ };
@@ -0,0 +1,157 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import { AxiosUtilsResponse, BundleGraphQL } from "@zauru-sdk/types";
4
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
5
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
6
+ import {
7
+ getBundleByNameStringQuery,
8
+ getBundlesByItemCategoryIdStringQuery,
9
+ } from "@zauru-sdk/graphql";
10
+ import httpZauru from "./httpZauru.server.js";
11
+
12
+ /**
13
+ * getBundlesByItemCategoryId
14
+ */
15
+ export async function getBundlesByItemCategoryId(
16
+ session: Session,
17
+ id: string
18
+ ): Promise<AxiosUtilsResponse<BundleGraphQL[]>> {
19
+ return handlePossibleAxiosErrors(async () => {
20
+ const headers = await getGraphQLAPIHeaders(session);
21
+
22
+ const response = await httpGraphQLAPI.post<{
23
+ data: { bundles: BundleGraphQL[] };
24
+ errors?: {
25
+ message: string;
26
+ extensions: { path: string; code: string };
27
+ }[];
28
+ }>(
29
+ "",
30
+ {
31
+ query: getBundlesByItemCategoryIdStringQuery,
32
+ variables: {
33
+ id,
34
+ },
35
+ },
36
+ { headers }
37
+ );
38
+
39
+ if (response.data.errors) {
40
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
41
+ }
42
+
43
+ const registers = response?.data?.data?.bundles;
44
+
45
+ return registers;
46
+ });
47
+ }
48
+
49
+ /**
50
+ * getBundleByName
51
+ */
52
+ export async function getBundleByName(
53
+ session: Session,
54
+ name: string
55
+ ): Promise<AxiosUtilsResponse<BundleGraphQL>> {
56
+ return handlePossibleAxiosErrors(async () => {
57
+ const headers = await getGraphQLAPIHeaders(session);
58
+
59
+ const response = await httpGraphQLAPI.post<{
60
+ data: { bundles: BundleGraphQL[] };
61
+ errors?: {
62
+ message: string;
63
+ extensions: { path: string; code: string };
64
+ }[];
65
+ }>(
66
+ "",
67
+ {
68
+ query: getBundleByNameStringQuery,
69
+ variables: {
70
+ name,
71
+ },
72
+ },
73
+ { headers }
74
+ );
75
+
76
+ if (response.data.errors) {
77
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
78
+ }
79
+
80
+ if (!response?.data?.data?.bundles[0]) {
81
+ throw new Error(
82
+ `No se encontró ningún bundle con el nombre: ${name} asociado`
83
+ );
84
+ }
85
+
86
+ const register = response?.data?.data?.bundles[0];
87
+
88
+ return register;
89
+ });
90
+ }
91
+
92
+ /**
93
+ * createBundle
94
+ * @param headers
95
+ * @param body
96
+ */
97
+ export async function createBundle(
98
+ headers: any,
99
+ body: Partial<BundleGraphQL>
100
+ ): Promise<AxiosUtilsResponse<BundleGraphQL>> {
101
+ return handlePossibleAxiosErrors(async () => {
102
+ const sendBody = {
103
+ ...body,
104
+ bundle_details_attributes: arrayToObject(body.bundle_details, {
105
+ withOutId: true,
106
+ }),
107
+ };
108
+ delete sendBody.bundle_details;
109
+ const response = await httpZauru.post<BundleGraphQL>(
110
+ `/inventories/bundles.json`,
111
+ sendBody,
112
+ { headers }
113
+ );
114
+ return response.data;
115
+ });
116
+ }
117
+
118
+ /**
119
+ * updateBundle
120
+ * @param headers
121
+ * @param body
122
+ */
123
+ export async function updateBundle(
124
+ headers: any,
125
+ body: Partial<BundleGraphQL>
126
+ ): Promise<AxiosUtilsResponse<BundleGraphQL>> {
127
+ return handlePossibleAxiosErrors(async () => {
128
+ const sendBody = {
129
+ ...body,
130
+ bundle_details_attributes: arrayToObject(body.bundle_details),
131
+ };
132
+ delete sendBody.bundle_details;
133
+ const response = await httpZauru.patch<BundleGraphQL>(
134
+ `/inventories/bundles/${body.id}.json`,
135
+ sendBody,
136
+ { headers }
137
+ );
138
+ return response.data;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * deleteBundle
144
+ * @param headers
145
+ * @param body
146
+ */
147
+ export async function deleteBundle(
148
+ headers: any,
149
+ id: string | number
150
+ ): Promise<AxiosUtilsResponse<boolean>> {
151
+ return handlePossibleAxiosErrors(async () => {
152
+ await httpZauru.delete<any>(`/inventories/bundles/${id}?destroy=true`, {
153
+ headers,
154
+ });
155
+ return true;
156
+ });
157
+ }
@@ -0,0 +1,44 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import { AxiosUtilsResponse, CaseGraphQL } from "@zauru-sdk/types";
4
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
5
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
6
+ import { getCasesByResponsibleIdStringQuery } from "@zauru-sdk/graphql";
7
+
8
+ /**
9
+ * getCasesByResponsibleId
10
+ */
11
+ export async function getCasesByResponsibleId(
12
+ session: Session,
13
+ responsible_id: string,
14
+ wheres: string[] = []
15
+ ): Promise<AxiosUtilsResponse<CaseGraphQL[]>> {
16
+ return handlePossibleAxiosErrors(async () => {
17
+ const headers = await getGraphQLAPIHeaders(session);
18
+
19
+ const response = await httpGraphQLAPI.post<{
20
+ data: { cases: CaseGraphQL[] };
21
+ errors?: {
22
+ message: string;
23
+ extensions: { path: string; code: string };
24
+ }[];
25
+ }>(
26
+ "",
27
+ {
28
+ query: getCasesByResponsibleIdStringQuery(wheres),
29
+ variables: {
30
+ responsible_id,
31
+ },
32
+ },
33
+ { headers }
34
+ );
35
+
36
+ if (response.data.errors) {
37
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
38
+ }
39
+
40
+ const registers = response?.data?.data?.cases;
41
+
42
+ return registers;
43
+ });
44
+ }