@zauru-sdk/services 1.0.18 → 1.0.23

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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.23](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.22...v1.0.23) (2024-03-22)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/services
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.0.20](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.19...v1.0.20) (2024-03-22)
15
+
16
+ **Note:** Version bump only for package @zauru-sdk/services
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.0.18](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.17...v1.0.18) (2024-03-22)
7
23
 
8
24
  **Note:** Version bump only for package @zauru-sdk/services
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export * from "./zauru/httpZauru.server.js";
7
7
  export * from "./zauru/zauru-agencies.server.js";
8
8
  export * from "./zauru/zauru-automatic-numbers.server.js";
9
9
  export * from "./zauru/zauru-bookings.server.js";
10
- export * from "./zauru/zauru-bundles.service.js";
10
+ export * from "./zauru/zauru-bundles.server.js";
11
11
  export * from "./zauru/zauru-cases.server.js";
12
12
  export * from "./zauru/zauru-currencies.server.js";
13
13
  export * from "./zauru/zauru-consolidated.server.js";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ export * from "./zauru/httpZauru.server.js";
7
7
  export * from "./zauru/zauru-agencies.server.js";
8
8
  export * from "./zauru/zauru-automatic-numbers.server.js";
9
9
  export * from "./zauru/zauru-bookings.server.js";
10
- export * from "./zauru/zauru-bundles.service.js";
10
+ export * from "./zauru/zauru-bundles.server.js";
11
11
  export * from "./zauru/zauru-cases.server.js";
12
12
  export * from "./zauru/zauru-currencies.server.js";
13
13
  export * from "./zauru/zauru-consolidated.server.js";
@@ -1,5 +1,11 @@
1
1
  import type { Session } from "@remix-run/node";
2
- import { AxiosUtilsResponse, ItemCategoryGraphQL, ItemGraphQL, ItemSuperCategoryGraphQL } from "@zauru-sdk/types";
2
+ import { AxiosUtilsResponse, ItemCategoryGraphQL, ItemDataTable, ItemGraphQL, ItemSuperCategoryGraphQL, SearchItemParams } from "@zauru-sdk/types";
3
+ /**
4
+ *
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare const getItemsDataTable: (headers: any, search: SearchItemParams) => Promise<AxiosUtilsResponse<ItemDataTable[]>>;
3
9
  /**
4
10
  * getItems
5
11
  */
@@ -1,8 +1,42 @@
1
- import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
1
+ import { extractValueBetweenTags, handlePossibleAxiosErrors, } from "@zauru-sdk/common";
2
2
  import { getGraphQLAPIHeaders } from "~/common.server.js";
3
3
  import httpGraphQLAPI from "./httpGraphQL.server.js";
4
4
  import { getItemByNameStringQuery, getItemCategoryByIdStringQuery, getItemsByCategoryStringQuery, getItemsBySuperCategoryStringQuery, getItemsStringQuery, getSuperCategoryByIdStringQuery, } from "@zauru-sdk/graphql";
5
5
  import httpZauru from "./httpZauru.server.js";
6
+ //============================ FORMATEADO DE ITEMS
7
+ function extractIdFromURL(input) {
8
+ const regex = /\/items\/(\d+)/;
9
+ const match = input.match(regex);
10
+ return match ? parseInt(match[1], 10) : -1;
11
+ }
12
+ function formatHTMLItemList(item) {
13
+ return {
14
+ zid: parseInt(extractValueBetweenTags(item.zid, "a"), 10),
15
+ itemId: extractIdFromURL(item.cod),
16
+ name: extractValueBetweenTags(item.name, "a"),
17
+ stck: extractValueBetweenTags(item.stck, "i") || null,
18
+ act: extractValueBetweenTags(item.act, "i") || null,
19
+ sell: extractValueBetweenTags(item.sell, "i") || null,
20
+ purch: extractValueBetweenTags(item.purch, "i") || null,
21
+ vat: extractValueBetweenTags(item.vat, "i") || null,
22
+ cat: item.cat,
23
+ warr: item.warr,
24
+ cat_note: item.cat_note,
25
+ DT_RowId: parseInt(item.DT_RowId.replace("settings-item-", ""), 10),
26
+ };
27
+ }
28
+ /**
29
+ *
30
+ * @param headers
31
+ * @returns
32
+ */
33
+ export const getItemsDataTable = async (headers, search) => {
34
+ return handlePossibleAxiosErrors(async () => {
35
+ const response = await httpZauru.post(`/settings/items/datatables.json`, search, { headers });
36
+ const items = response.data?.data?.map((x) => formatHTMLItemList(x)) ?? [];
37
+ return items;
38
+ });
39
+ };
6
40
  /**
7
41
  * getItems
8
42
  */
@@ -1,5 +1,5 @@
1
1
  import type { Session } from "@remix-run/node";
2
- import { AxiosUtilsResponse, WebAppRowGraphQL, WebAppTableCreateBody, WebAppTableGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
2
+ import { AxiosUtilsResponse, RejectionWebAppTableObject, WebAppRowGraphQL, WebAppTableCreateBody, WebAppTableGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
3
3
  /**
4
4
  * getWebAppRow
5
5
  * @param headers
@@ -46,3 +46,10 @@ export declare function updateWebAppTableRegister<T>(headers: any, id_web_app_ta
46
46
  * @returns
47
47
  */
48
48
  export declare function createWebAppTable(headers: any, body: WebAppTableCreateBody): Promise<AxiosUtilsResponse<WebAppTableGraphQL>>;
49
+ /**
50
+ * getWebappTable
51
+ * @param headers
52
+ * @param session
53
+ * @returns
54
+ */
55
+ export declare const getRejectionWebAppTable: (headers: any, session: Session) => Promise<AxiosUtilsResponse<RejectionWebAppTableObject>>;
@@ -1,5 +1,5 @@
1
1
  import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
- import { getGraphQLAPIHeaders } from "~/common.server.js";
2
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
3
3
  import httpGraphQLAPI from "./httpGraphQL.server.js";
4
4
  import { getWebAppRowStringQuery, getWebAppRowsByWebAppTableIdStringQuery, } from "@zauru-sdk/graphql";
5
5
  import httpZauru from "./httpZauru.server.js";
@@ -118,3 +118,37 @@ export async function createWebAppTable(headers, body) {
118
118
  };
119
119
  }
120
120
  }
121
+ /**
122
+ * getWebappTable
123
+ * @param headers
124
+ * @param session
125
+ * @returns
126
+ */
127
+ export const getRejectionWebAppTable = async (headers, session) => {
128
+ return handlePossibleAxiosErrors(async () => {
129
+ const { recepciones_rejections_webapp_table_id, recepciones_rejection_types_webapp_table_id, } = await getVariablesByName(headers, session, [
130
+ "recepciones_rejections_webapp_table_id",
131
+ "recepciones_rejection_types_webapp_table_id",
132
+ ]);
133
+ const webappTableResponse = await httpZauru.get(`/apps/webapp_tables/${recepciones_rejections_webapp_table_id}.json`, { headers });
134
+ const webappTableRejectionsResponse = await httpZauru.get(`/apps/webapp_tables/${recepciones_rejection_types_webapp_table_id}/webapp_rows.json`, { headers });
135
+ const rejections_select = [];
136
+ const rejections_complete = webappTableRejectionsResponse.data;
137
+ const keyName = Object.keys(rejections_complete[0].data)[0]; //get the first value
138
+ const rejections_list = [];
139
+ rejections_complete.forEach((val) => {
140
+ rejections_list.push(val.data[keyName]);
141
+ });
142
+ rejections_complete.forEach((rc) => {
143
+ rejections_select.push({
144
+ value: rc.data[keyName],
145
+ label: rc.data[keyName],
146
+ });
147
+ });
148
+ return {
149
+ webapp_table: webappTableResponse.data.structure,
150
+ rejection_list: rejections_list,
151
+ rejection_select: rejections_select,
152
+ };
153
+ });
154
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "1.0.18",
3
+ "version": "1.0.23",
4
4
  "description": "Servicios de consulta a Zauru",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,5 +29,5 @@
29
29
  "engines": {
30
30
  "node": ">=18.0.0"
31
31
  },
32
- "gitHead": "bcd403ed2996283a6eed13ce56cc24b2ee824369"
32
+ "gitHead": "5ce5e3740053cdb3ccb85ba4a600207c544998b1"
33
33
  }
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ export * from "./zauru/httpZauru.server.js";
10
10
  export * from "./zauru/zauru-agencies.server.js";
11
11
  export * from "./zauru/zauru-automatic-numbers.server.js";
12
12
  export * from "./zauru/zauru-bookings.server.js";
13
- export * from "./zauru/zauru-bundles.service.js";
13
+ export * from "./zauru/zauru-bundles.server.js";
14
14
  export * from "./zauru/zauru-cases.server.js";
15
15
  export * from "./zauru/zauru-currencies.server.js";
16
16
  export * from "./zauru/zauru-consolidated.server.js";
@@ -1,10 +1,17 @@
1
1
  import type { Session } from "@remix-run/node";
2
- import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import {
3
+ extractValueBetweenTags,
4
+ handlePossibleAxiosErrors,
5
+ } from "@zauru-sdk/common";
3
6
  import {
4
7
  AxiosUtilsResponse,
8
+ HTMLItemListSchema,
5
9
  ItemCategoryGraphQL,
10
+ ItemDataTable,
6
11
  ItemGraphQL,
7
12
  ItemSuperCategoryGraphQL,
13
+ ResponseItemList,
14
+ SearchItemParams,
8
15
  } from "@zauru-sdk/types";
9
16
  import { getGraphQLAPIHeaders } from "~/common.server.js";
10
17
  import httpGraphQLAPI from "./httpGraphQL.server.js";
@@ -18,6 +25,53 @@ import {
18
25
  } from "@zauru-sdk/graphql";
19
26
  import httpZauru from "./httpZauru.server.js";
20
27
 
28
+ //============================ FORMATEADO DE ITEMS
29
+ function extractIdFromURL(input: string): number {
30
+ const regex = /\/items\/(\d+)/;
31
+ const match = input.match(regex);
32
+ return match ? parseInt(match[1], 10) : -1;
33
+ }
34
+
35
+ function formatHTMLItemList(item: HTMLItemListSchema): ItemDataTable {
36
+ return {
37
+ zid: parseInt(extractValueBetweenTags(item.zid, "a"), 10),
38
+ itemId: extractIdFromURL(item.cod),
39
+ name: extractValueBetweenTags(item.name, "a"),
40
+ stck: extractValueBetweenTags(item.stck, "i") || null,
41
+ act: extractValueBetweenTags(item.act, "i") || null,
42
+ sell: extractValueBetweenTags(item.sell, "i") || null,
43
+ purch: extractValueBetweenTags(item.purch, "i") || null,
44
+ vat: extractValueBetweenTags(item.vat, "i") || null,
45
+ cat: item.cat,
46
+ warr: item.warr,
47
+ cat_note: item.cat_note,
48
+ DT_RowId: parseInt(item.DT_RowId.replace("settings-item-", ""), 10),
49
+ };
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param headers
55
+ * @returns
56
+ */
57
+ export const getItemsDataTable = async (
58
+ headers: any,
59
+ search: SearchItemParams
60
+ ): Promise<AxiosUtilsResponse<ItemDataTable[]>> => {
61
+ return handlePossibleAxiosErrors(async () => {
62
+ const response = await httpZauru.post<ResponseItemList>(
63
+ `/settings/items/datatables.json`,
64
+ search,
65
+ { headers }
66
+ );
67
+
68
+ const items: ItemDataTable[] =
69
+ response.data?.data?.map((x) => formatHTMLItemList(x)) ?? [];
70
+
71
+ return items;
72
+ });
73
+ };
74
+
21
75
  /**
22
76
  * getItems
23
77
  */
@@ -2,13 +2,15 @@ import type { Session } from "@remix-run/node";
2
2
  import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
3
  import {
4
4
  AxiosUtilsResponse,
5
+ MotivoRechazo,
6
+ RejectionWebAppTableObject,
5
7
  WebAppRowGraphQL,
6
8
  WebAppTableBody,
7
9
  WebAppTableCreateBody,
8
10
  WebAppTableGraphQL,
9
11
  WebAppTableUpdateResponse,
10
12
  } from "@zauru-sdk/types";
11
- import { getGraphQLAPIHeaders } from "~/common.server.js";
13
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
12
14
  import httpGraphQLAPI from "./httpGraphQL.server.js";
13
15
  import {
14
16
  getWebAppRowStringQuery,
@@ -198,3 +200,57 @@ export async function createWebAppTable(
198
200
  } as AxiosUtilsResponse<WebAppTableGraphQL>;
199
201
  }
200
202
  }
203
+
204
+ /**
205
+ * getWebappTable
206
+ * @param headers
207
+ * @param session
208
+ * @returns
209
+ */
210
+ export const getRejectionWebAppTable = async (
211
+ headers: any,
212
+ session: Session
213
+ ): Promise<AxiosUtilsResponse<RejectionWebAppTableObject>> => {
214
+ return handlePossibleAxiosErrors(async () => {
215
+ const {
216
+ recepciones_rejections_webapp_table_id,
217
+ recepciones_rejection_types_webapp_table_id,
218
+ } = await getVariablesByName(headers, session, [
219
+ "recepciones_rejections_webapp_table_id",
220
+ "recepciones_rejection_types_webapp_table_id",
221
+ ]);
222
+
223
+ const webappTableResponse = await httpZauru.get<WebAppTableGraphQL>(
224
+ `/apps/webapp_tables/${recepciones_rejections_webapp_table_id}.json`,
225
+ { headers }
226
+ );
227
+
228
+ const webappTableRejectionsResponse = await httpZauru.get<
229
+ WebAppRowGraphQL<MotivoRechazo>[]
230
+ >(
231
+ `/apps/webapp_tables/${recepciones_rejection_types_webapp_table_id}/webapp_rows.json`,
232
+ { headers }
233
+ );
234
+
235
+ const rejections_select: { value: string; label: string }[] = [];
236
+ const rejections_complete = webappTableRejectionsResponse.data;
237
+ const keyName: string = Object.keys(rejections_complete[0].data)[0]; //get the first value
238
+ const rejections_list: string[] = [];
239
+ rejections_complete.forEach((val: any) => {
240
+ rejections_list.push(val.data[keyName]);
241
+ });
242
+
243
+ rejections_complete.forEach((rc: any) => {
244
+ rejections_select.push({
245
+ value: rc.data[keyName],
246
+ label: rc.data[keyName],
247
+ });
248
+ });
249
+
250
+ return {
251
+ webapp_table: webappTableResponse.data.structure,
252
+ rejection_list: rejections_list,
253
+ rejection_select: rejections_select,
254
+ } as RejectionWebAppTableObject;
255
+ });
256
+ };