@zauru-sdk/services 1.0.7 → 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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.8](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.7...v1.0.8) (2024-03-16)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/services
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.0.7](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.6...v1.0.7) (2024-03-16)
7
15
 
8
16
  **Note:** Version bump only for package @zauru-sdk/services
package/dist/index.d.ts CHANGED
@@ -6,7 +6,10 @@ export * from "./zauru/httpOauth.server.js";
6
6
  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
- export * from "./zauru/zauru-currencies.server.js";
9
+ export * from "./zauru/zauru-bookings.server.js";
10
+ export * from "./zauru/zauru-bundles.service.js";
11
+ export * from "./zauru/zauru-cases.server.js";
12
+ export * from "./zauru/zauru-consolidated.server.js";
10
13
  export * from "./zauru/zauru-deliveries.server.js";
11
14
  export * from "./zauru/zauru-discharges.server.js";
12
15
  export * from "./zauru/zauru-employees.server.js";
package/dist/index.js CHANGED
@@ -6,7 +6,10 @@ export * from "./zauru/httpOauth.server.js";
6
6
  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
- export * from "./zauru/zauru-currencies.server.js";
9
+ export * from "./zauru/zauru-bookings.server.js";
10
+ export * from "./zauru/zauru-bundles.service.js";
11
+ export * from "./zauru/zauru-cases.server.js";
12
+ export * from "./zauru/zauru-consolidated.server.js";
10
13
  export * from "./zauru/zauru-deliveries.server.js";
11
14
  export * from "./zauru/zauru-discharges.server.js";
12
15
  export * from "./zauru/zauru-employees.server.js";
@@ -0,0 +1,28 @@
1
+ import { AxiosUtilsResponse, InsertBookingBody, ShipmentGraphQL } from "@zauru-sdk/types";
2
+ import { Session } from "@remix-run/node";
3
+ /**
4
+ * insertBookings
5
+ * @param headers
6
+ * @param body
7
+ * @returns
8
+ */
9
+ export declare const insertBookings: (headers: any, body: Partial<InsertBookingBody>, temp_purchase_order_id?: string) => Promise<AxiosUtilsResponse<ShipmentGraphQL>>;
10
+ /**
11
+ * getDeliveryByBooking
12
+ * @param headers
13
+ * @param shipment_id
14
+ * @returns
15
+ */
16
+ export declare const getDeliveryByBooking: (headers: any, shipment_id: number) => Promise<AxiosUtilsResponse<any>>;
17
+ /**
18
+ * getBookings
19
+ * @param headers
20
+ * @returns
21
+ */
22
+ export declare const getBookings: (session: Session, wheres?: string[]) => Promise<AxiosUtilsResponse<ShipmentGraphQL[]>>;
23
+ /**
24
+ * getBookings
25
+ * @param headers
26
+ * @returns
27
+ */
28
+ export declare const getBooking: (headers: any, booking_id: string) => Promise<AxiosUtilsResponse<ShipmentGraphQL>>;
@@ -0,0 +1,80 @@
1
+ import { arrayToObject, 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 { getShipmentsStringQuery } from "@zauru-sdk/graphql";
6
+ /**
7
+ * insertBookings
8
+ * @param headers
9
+ * @param body
10
+ * @returns
11
+ */
12
+ export const insertBookings = async (headers, body, temp_purchase_order_id) => {
13
+ return handlePossibleAxiosErrors(async () => {
14
+ const sendBody = {
15
+ shipment: {
16
+ ...body,
17
+ movements_attributes: arrayToObject(body.movements),
18
+ },
19
+ };
20
+ delete sendBody.shipment.movements;
21
+ if (temp_purchase_order_id) {
22
+ sendBody[`temp_purchase_order_id`] = `${temp_purchase_order_id}`;
23
+ }
24
+ const response = await httpZauru.post(`/inventories/bookings.json`, sendBody, {
25
+ headers,
26
+ });
27
+ return response.data;
28
+ });
29
+ };
30
+ /**
31
+ * getDeliveryByBooking
32
+ * @param headers
33
+ * @param shipment_id
34
+ * @returns
35
+ */
36
+ export const getDeliveryByBooking = async (headers, shipment_id) => {
37
+ return handlePossibleAxiosErrors(async () => {
38
+ if (!shipment_id) {
39
+ throw new Error("No hay un shipment_id, en getDeliveryByBooking");
40
+ }
41
+ const response = await httpZauru.get(`/inventories/bookings/${shipment_id}/deliver.json`, {
42
+ headers,
43
+ data: {
44
+ id: shipment_id,
45
+ },
46
+ });
47
+ return response.data;
48
+ });
49
+ };
50
+ /**
51
+ * getBookings
52
+ * @param headers
53
+ * @returns
54
+ */
55
+ export const getBookings = async (session, wheres = []) => {
56
+ return handlePossibleAxiosErrors(async () => {
57
+ const headers = await getGraphQLAPIHeaders(session);
58
+ const response = await httpGraphQLAPI.post("", {
59
+ query: getShipmentsStringQuery([...wheres, "delivered: {_eq: false}"]),
60
+ }, { headers });
61
+ if (response.data.errors) {
62
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
63
+ }
64
+ const registers = response?.data?.data?.shipments;
65
+ return registers;
66
+ });
67
+ };
68
+ /**
69
+ * getBookings
70
+ * @param headers
71
+ * @returns
72
+ */
73
+ export const getBooking = async (headers, booking_id) => {
74
+ return handlePossibleAxiosErrors(async () => {
75
+ const response = await httpZauru.get(`/inventories/bookings/${booking_id}.json`, {
76
+ headers,
77
+ });
78
+ return response.data;
79
+ });
80
+ };
@@ -0,0 +1,28 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, BundleGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getBundlesByItemCategoryId
5
+ */
6
+ export declare function getBundlesByItemCategoryId(session: Session, id: string): Promise<AxiosUtilsResponse<BundleGraphQL[]>>;
7
+ /**
8
+ * getBundleByName
9
+ */
10
+ export declare function getBundleByName(session: Session, name: string): Promise<AxiosUtilsResponse<BundleGraphQL>>;
11
+ /**
12
+ * createBundle
13
+ * @param headers
14
+ * @param body
15
+ */
16
+ export declare function createBundle(headers: any, body: Partial<BundleGraphQL>): Promise<AxiosUtilsResponse<BundleGraphQL>>;
17
+ /**
18
+ * updateBundle
19
+ * @param headers
20
+ * @param body
21
+ */
22
+ export declare function updateBundle(headers: any, body: Partial<BundleGraphQL>): Promise<AxiosUtilsResponse<BundleGraphQL>>;
23
+ /**
24
+ * deleteBundle
25
+ * @param headers
26
+ * @param body
27
+ */
28
+ export declare function deleteBundle(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
@@ -0,0 +1,93 @@
1
+ import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
3
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
4
+ import { getBundleByNameStringQuery, getBundlesByItemCategoryIdStringQuery, } from "@zauru-sdk/graphql";
5
+ import httpZauru from "./httpZauru.server.js";
6
+ /**
7
+ * getBundlesByItemCategoryId
8
+ */
9
+ export async function getBundlesByItemCategoryId(session, id) {
10
+ return handlePossibleAxiosErrors(async () => {
11
+ const headers = await getGraphQLAPIHeaders(session);
12
+ const response = await httpGraphQLAPI.post("", {
13
+ query: getBundlesByItemCategoryIdStringQuery,
14
+ variables: {
15
+ id,
16
+ },
17
+ }, { headers });
18
+ if (response.data.errors) {
19
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
20
+ }
21
+ const registers = response?.data?.data?.bundles;
22
+ return registers;
23
+ });
24
+ }
25
+ /**
26
+ * getBundleByName
27
+ */
28
+ export async function getBundleByName(session, name) {
29
+ return handlePossibleAxiosErrors(async () => {
30
+ const headers = await getGraphQLAPIHeaders(session);
31
+ const response = await httpGraphQLAPI.post("", {
32
+ query: getBundleByNameStringQuery,
33
+ variables: {
34
+ name,
35
+ },
36
+ }, { headers });
37
+ if (response.data.errors) {
38
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
39
+ }
40
+ if (!response?.data?.data?.bundles[0]) {
41
+ throw new Error(`No se encontró ningún bundle con el nombre: ${name} asociado`);
42
+ }
43
+ const register = response?.data?.data?.bundles[0];
44
+ return register;
45
+ });
46
+ }
47
+ /**
48
+ * createBundle
49
+ * @param headers
50
+ * @param body
51
+ */
52
+ export async function createBundle(headers, body) {
53
+ return handlePossibleAxiosErrors(async () => {
54
+ const sendBody = {
55
+ ...body,
56
+ bundle_details_attributes: arrayToObject(body.bundle_details, {
57
+ withOutId: true,
58
+ }),
59
+ };
60
+ delete sendBody.bundle_details;
61
+ const response = await httpZauru.post(`/inventories/bundles.json`, sendBody, { headers });
62
+ return response.data;
63
+ });
64
+ }
65
+ /**
66
+ * updateBundle
67
+ * @param headers
68
+ * @param body
69
+ */
70
+ export async function updateBundle(headers, body) {
71
+ return handlePossibleAxiosErrors(async () => {
72
+ const sendBody = {
73
+ ...body,
74
+ bundle_details_attributes: arrayToObject(body.bundle_details),
75
+ };
76
+ delete sendBody.bundle_details;
77
+ const response = await httpZauru.patch(`/inventories/bundles/${body.id}.json`, sendBody, { headers });
78
+ return response.data;
79
+ });
80
+ }
81
+ /**
82
+ * deleteBundle
83
+ * @param headers
84
+ * @param body
85
+ */
86
+ export async function deleteBundle(headers, id) {
87
+ return handlePossibleAxiosErrors(async () => {
88
+ await httpZauru.delete(`/inventories/bundles/${id}?destroy=true`, {
89
+ headers,
90
+ });
91
+ return true;
92
+ });
93
+ }
@@ -0,0 +1,6 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, CaseGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getCasesByResponsibleId
5
+ */
6
+ export declare function getCasesByResponsibleId(session: Session, responsible_id: string, wheres?: string[]): Promise<AxiosUtilsResponse<CaseGraphQL[]>>;
@@ -0,0 +1,23 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
3
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
4
+ import { getCasesByResponsibleIdStringQuery } from "@zauru-sdk/graphql";
5
+ /**
6
+ * getCasesByResponsibleId
7
+ */
8
+ export async function getCasesByResponsibleId(session, responsible_id, wheres = []) {
9
+ return handlePossibleAxiosErrors(async () => {
10
+ const headers = await getGraphQLAPIHeaders(session);
11
+ const response = await httpGraphQLAPI.post("", {
12
+ query: getCasesByResponsibleIdStringQuery(wheres),
13
+ variables: {
14
+ responsible_id,
15
+ },
16
+ }, { headers });
17
+ if (response.data.errors) {
18
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
19
+ }
20
+ const registers = response?.data?.data?.cases;
21
+ return registers;
22
+ });
23
+ }
@@ -0,0 +1,36 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, ConsolidateGraphQL, GeneratePDFBody, NewConsolidatedBody, PDFResult } from "@zauru-sdk/types";
3
+ /**
4
+ *
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare const createConsolidated: (headers: any, body: NewConsolidatedBody) => Promise<AxiosUtilsResponse<{
9
+ id: number;
10
+ }>>;
11
+ /**
12
+ * generateConsolidatePDF
13
+ * @param headers
14
+ * @param body
15
+ */
16
+ export declare const generateConsolidatePDF: (headers: any, session: Session, body: GeneratePDFBody) => Promise<AxiosUtilsResponse<{
17
+ status: number;
18
+ zid: number;
19
+ }>>;
20
+ /**
21
+ * getConsolidatedPDFResult
22
+ * @param headers
23
+ * @param zid
24
+ * @returns
25
+ */
26
+ export declare const getConsolidatedPDFResult: (headers: any, zid: number | string) => Promise<AxiosUtilsResponse<PDFResult>>;
27
+ /**
28
+ *
29
+ * @param session
30
+ * @param dates
31
+ * @returns
32
+ */
33
+ export declare const getConsolidatesBetweenDates: (session: Session, dates: {
34
+ startDate: string;
35
+ endDate: string;
36
+ }) => Promise<AxiosUtilsResponse<ConsolidateGraphQL[]>>;
@@ -0,0 +1,71 @@
1
+ import { formatDateToUTC, handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpZauru from "./httpZauru.server.js";
3
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
4
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
5
+ import { getConsolidatesBetweenDatesStringQuery } from "@zauru-sdk/graphql";
6
+ /**
7
+ *
8
+ * @param headers
9
+ * @returns
10
+ */
11
+ export const createConsolidated = async (headers, body) => {
12
+ return handlePossibleAxiosErrors(async () => {
13
+ const response = await httpZauru.post(`/purchases/consolidates/create_for_special_invoice.json`, body, {
14
+ headers,
15
+ });
16
+ return response.data;
17
+ });
18
+ };
19
+ /**
20
+ * generateConsolidatePDF
21
+ * @param headers
22
+ * @param body
23
+ */
24
+ export const generateConsolidatePDF = async (headers, session, body) => {
25
+ return handlePossibleAxiosErrors(async () => {
26
+ const { consolidated_template_id } = await getVariablesByName(headers, session, ["consolidated_template_id"]);
27
+ body.print_template = consolidated_template_id;
28
+ const response = await httpZauru.post("/purchases/consolidates/gen_print_all.json", body, { headers });
29
+ return response.data;
30
+ });
31
+ };
32
+ /**
33
+ * getConsolidatedPDFResult
34
+ * @param headers
35
+ * @param zid
36
+ * @returns
37
+ */
38
+ export const getConsolidatedPDFResult = async (headers, zid) => {
39
+ return handlePossibleAxiosErrors(async () => {
40
+ const response = await httpZauru.get("purchases/consolidates/check_print_all", {
41
+ headers,
42
+ params: { zid },
43
+ });
44
+ return response.data;
45
+ });
46
+ };
47
+ /**
48
+ *
49
+ * @param session
50
+ * @param dates
51
+ * @returns
52
+ */
53
+ export const getConsolidatesBetweenDates = async (session, dates) => {
54
+ return handlePossibleAxiosErrors(async () => {
55
+ const headers = await getGraphQLAPIHeaders(session);
56
+ const response = await httpGraphQLAPI.post("", {
57
+ query: getConsolidatesBetweenDatesStringQuery,
58
+ variables: {
59
+ startDate: formatDateToUTC(dates.startDate),
60
+ endDate: formatDateToUTC(dates.endDate),
61
+ },
62
+ }, { headers });
63
+ if (response.data.errors) {
64
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
65
+ }
66
+ if (!response?.data?.data.consolidates) {
67
+ return [];
68
+ }
69
+ return response.data?.data.consolidates;
70
+ });
71
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Servicios de consulta a Zauru",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,15 +19,15 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@remix-run/node": "^2.8.1",
22
- "@zauru-sdk/common": "^1.0.7",
22
+ "@zauru-sdk/common": "^1.0.8",
23
23
  "@zauru-sdk/config": "^1.0.4",
24
24
  "@zauru-sdk/graphql": "^1.0.7",
25
- "@zauru-sdk/types": "^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": "8078893206a171382f3783914ceec8959cdda945"
32
+ "gitHead": "60fc0a94174a359d300c7479bcb8278316857ed9"
33
33
  }
package/src/index.ts CHANGED
@@ -9,7 +9,10 @@ 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-currencies.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";
13
16
  export * from "./zauru/zauru-deliveries.server.js";
14
17
  export * from "./zauru/zauru-discharges.server.js";
15
18
  export * from "./zauru/zauru-employees.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
+ }
@@ -0,0 +1,129 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { formatDateToUTC, handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ AxiosUtilsResponse,
5
+ ConsolidateGraphQL,
6
+ GeneratePDFBody,
7
+ NewConsolidatedBody,
8
+ PDFResult,
9
+ } from "@zauru-sdk/types";
10
+ import httpZauru from "./httpZauru.server.js";
11
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
12
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
13
+ import { getConsolidatesBetweenDatesStringQuery } from "@zauru-sdk/graphql";
14
+
15
+ /**
16
+ *
17
+ * @param headers
18
+ * @returns
19
+ */
20
+ export const createConsolidated = async (
21
+ headers: any,
22
+ body: NewConsolidatedBody
23
+ ): Promise<AxiosUtilsResponse<{ id: number }>> => {
24
+ return handlePossibleAxiosErrors(async () => {
25
+ const response = await httpZauru.post<{ id: number }>(
26
+ `/purchases/consolidates/create_for_special_invoice.json`,
27
+ body,
28
+ {
29
+ headers,
30
+ }
31
+ );
32
+
33
+ return response.data;
34
+ });
35
+ };
36
+
37
+ /**
38
+ * generateConsolidatePDF
39
+ * @param headers
40
+ * @param body
41
+ */
42
+ export const generateConsolidatePDF = async (
43
+ headers: any,
44
+ session: Session,
45
+ body: GeneratePDFBody
46
+ ): Promise<AxiosUtilsResponse<{ status: number; zid: number }>> => {
47
+ return handlePossibleAxiosErrors(async () => {
48
+ const { consolidated_template_id } = await getVariablesByName(
49
+ headers,
50
+ session,
51
+ ["consolidated_template_id"]
52
+ );
53
+ body.print_template = consolidated_template_id;
54
+ const response = await httpZauru.post<{ status: number; zid: number }>(
55
+ "/purchases/consolidates/gen_print_all.json",
56
+ body,
57
+ { headers }
58
+ );
59
+
60
+ return response.data;
61
+ });
62
+ };
63
+
64
+ /**
65
+ * getConsolidatedPDFResult
66
+ * @param headers
67
+ * @param zid
68
+ * @returns
69
+ */
70
+ export const getConsolidatedPDFResult = async (
71
+ headers: any,
72
+ zid: number | string
73
+ ): Promise<AxiosUtilsResponse<PDFResult>> => {
74
+ return handlePossibleAxiosErrors(async () => {
75
+ const response = await httpZauru.get<PDFResult>(
76
+ "purchases/consolidates/check_print_all",
77
+ {
78
+ headers,
79
+ params: { zid },
80
+ }
81
+ );
82
+ return response.data;
83
+ });
84
+ };
85
+
86
+ /**
87
+ *
88
+ * @param session
89
+ * @param dates
90
+ * @returns
91
+ */
92
+ export const getConsolidatesBetweenDates = async (
93
+ session: Session,
94
+ dates: {
95
+ startDate: string;
96
+ endDate: string;
97
+ }
98
+ ): Promise<AxiosUtilsResponse<ConsolidateGraphQL[]>> => {
99
+ return handlePossibleAxiosErrors(async () => {
100
+ const headers = await getGraphQLAPIHeaders(session);
101
+ const response = await httpGraphQLAPI.post<{
102
+ data: { consolidates: ConsolidateGraphQL[] };
103
+ errors?: {
104
+ message: string;
105
+ extensions: { path: string; code: string };
106
+ }[];
107
+ }>(
108
+ "",
109
+ {
110
+ query: getConsolidatesBetweenDatesStringQuery,
111
+ variables: {
112
+ startDate: formatDateToUTC(dates.startDate),
113
+ endDate: formatDateToUTC(dates.endDate),
114
+ },
115
+ },
116
+ { headers }
117
+ );
118
+
119
+ if (response.data.errors) {
120
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
121
+ }
122
+
123
+ if (!response?.data?.data.consolidates) {
124
+ return [];
125
+ }
126
+
127
+ return response.data?.data.consolidates;
128
+ });
129
+ };