@zauru-sdk/services 1.0.49 → 1.0.52
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/dist/cjs/common.js +235 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/sessions/sessions.js +18 -0
- package/dist/cjs/sessions/upstash.js +59 -0
- package/dist/cjs/zauru/httpGraphQL.js +42 -0
- package/dist/cjs/zauru/httpOauth.js +42 -0
- package/dist/cjs/zauru/httpZauru.js +42 -0
- package/dist/cjs/zauru/zauru-agencies.js +27 -0
- package/dist/cjs/zauru/zauru-automatic-numbers.js +28 -0
- package/dist/cjs/zauru/zauru-bookings.js +90 -0
- package/dist/cjs/zauru/zauru-bundles.js +104 -0
- package/dist/cjs/zauru/zauru-cases.js +30 -0
- package/dist/cjs/zauru/zauru-consolidated.js +81 -0
- package/dist/cjs/zauru/zauru-currencies.js +27 -0
- package/dist/cjs/zauru/zauru-deliveries.js +53 -0
- package/dist/cjs/zauru/zauru-discharges.js +55 -0
- package/dist/cjs/zauru/zauru-employees.js +30 -0
- package/dist/cjs/zauru/zauru-forms.js +363 -0
- package/dist/cjs/zauru/zauru-invoices.js +104 -0
- package/dist/cjs/zauru/zauru-items.js +293 -0
- package/dist/cjs/zauru/zauru-lote-record.js +33 -0
- package/dist/cjs/zauru/zauru-lotes.js +312 -0
- package/dist/cjs/zauru/zauru-motivos-rechazo.js +57 -0
- package/dist/cjs/zauru/zauru-payees.js +247 -0
- package/dist/cjs/zauru/zauru-payment-terms.js +75 -0
- package/dist/cjs/zauru/zauru-price-lists.js +49 -0
- package/dist/cjs/zauru/zauru-profiles.js +80 -0
- package/dist/cjs/zauru/zauru-purchase-orders.js +438 -0
- package/dist/cjs/zauru/zauru-receptions.js +104 -0
- package/dist/cjs/zauru/zauru-shipments.js +62 -0
- package/dist/cjs/zauru/zauru-suggested-prices.js +94 -0
- package/dist/cjs/zauru/zauru-tags.js +20 -0
- package/dist/cjs/zauru/zauru-templates.js +22 -0
- package/dist/cjs/zauru/zauru-variables.js +56 -0
- package/dist/cjs/zauru/zauru-web-app-tables.js +167 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -232
- package/src/common.ts +0 -343
- package/src/index.ts +0 -37
- package/src/sessions/sessions.ts +0 -17
- package/src/sessions/upstash.ts +0 -55
- package/src/zauru/httpGraphQL.ts +0 -55
- package/src/zauru/httpOauth.ts +0 -55
- package/src/zauru/httpZauru.ts +0 -56
- package/src/zauru/zauru-agencies.ts +0 -32
- package/src/zauru/zauru-automatic-numbers.ts +0 -35
- package/src/zauru/zauru-bookings.ts +0 -134
- package/src/zauru/zauru-bundles.ts +0 -157
- package/src/zauru/zauru-cases.ts +0 -44
- package/src/zauru/zauru-consolidated.ts +0 -129
- package/src/zauru/zauru-currencies.ts +0 -39
- package/src/zauru/zauru-deliveries.ts +0 -70
- package/src/zauru/zauru-discharges.ts +0 -90
- package/src/zauru/zauru-employees.ts +0 -43
- package/src/zauru/zauru-forms.ts +0 -618
- package/src/zauru/zauru-invoices.ts +0 -142
- package/src/zauru/zauru-items.ts +0 -481
- package/src/zauru/zauru-lote-record.ts +0 -77
- package/src/zauru/zauru-lotes.ts +0 -484
- package/src/zauru/zauru-motivos-rechazo.ts +0 -121
- package/src/zauru/zauru-payees.ts +0 -402
- package/src/zauru/zauru-payment-terms.ts +0 -126
- package/src/zauru/zauru-price-lists.ts +0 -68
- package/src/zauru/zauru-profiles.ts +0 -106
- package/src/zauru/zauru-purchase-orders.ts +0 -701
- package/src/zauru/zauru-receptions.ts +0 -148
- package/src/zauru/zauru-shipments.ts +0 -88
- package/src/zauru/zauru-suggested-prices.ts +0 -137
- package/src/zauru/zauru-tags.ts +0 -22
- package/src/zauru/zauru-templates.ts +0 -24
- package/src/zauru/zauru-variables.ts +0 -67
- package/src/zauru/zauru-web-app-tables.ts +0 -256
- package/tsconfig.json +0 -24
- /package/dist/{common.js → esm/common.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{sessions → esm/sessions}/sessions.js +0 -0
- /package/dist/{sessions → esm/sessions}/upstash.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpGraphQL.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpOauth.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpZauru.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-agencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-automatic-numbers.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bookings.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bundles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-cases.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-consolidated.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-currencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-deliveries.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-discharges.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-employees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-forms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-invoices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-items.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lote-record.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lotes.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-motivos-rechazo.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payment-terms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-price-lists.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-profiles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-purchase-orders.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-receptions.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-shipments.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-suggested-prices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-tags.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-templates.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-variables.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-web-app-tables.js +0 -0
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
-
import {
|
|
4
|
-
AxiosUtilsResponse,
|
|
5
|
-
InvoiceGraphQL,
|
|
6
|
-
SubmissionInvoicesGraphQL,
|
|
7
|
-
} from "@zauru-sdk/types";
|
|
8
|
-
import { getGraphQLAPIHeaders } from "../common.js";
|
|
9
|
-
import httpGraphQLAPI from "./httpGraphQL.js";
|
|
10
|
-
import { getInvoicesByAgencyIdStringQuery } from "@zauru-sdk/graphql";
|
|
11
|
-
import httpZauru from "./httpZauru.js";
|
|
12
|
-
/**
|
|
13
|
-
* getInvoicesByAgencyId
|
|
14
|
-
*/
|
|
15
|
-
export async function getInvoicesByAgencyId(
|
|
16
|
-
session: Session,
|
|
17
|
-
id: string | null
|
|
18
|
-
): Promise<AxiosUtilsResponse<InvoiceGraphQL[]>> {
|
|
19
|
-
return handlePossibleAxiosErrors(async () => {
|
|
20
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
21
|
-
|
|
22
|
-
const response = await httpGraphQLAPI.post<{
|
|
23
|
-
data: { invoices: InvoiceGraphQL[] };
|
|
24
|
-
errors?: {
|
|
25
|
-
message: string;
|
|
26
|
-
extensions: { path: string; code: string };
|
|
27
|
-
}[];
|
|
28
|
-
}>(
|
|
29
|
-
"",
|
|
30
|
-
{
|
|
31
|
-
query: getInvoicesByAgencyIdStringQuery,
|
|
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
|
-
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
44
|
-
const registers = response?.data?.data?.invoices.map((x) => {
|
|
45
|
-
const groupedByVersion = x.submission_invoices?.reduce((acc, record) => {
|
|
46
|
-
const zid = record.settings_form_submission?.zid;
|
|
47
|
-
|
|
48
|
-
if (!acc[zid]) {
|
|
49
|
-
acc[zid] = record;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return acc;
|
|
53
|
-
}, {} as { [key: string]: SubmissionInvoicesGraphQL });
|
|
54
|
-
|
|
55
|
-
x.submission_invoices = Object.values(groupedByVersion)?.reverse() ?? [];
|
|
56
|
-
|
|
57
|
-
return x;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return registers;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* createInvoiceOrder
|
|
66
|
-
* @param headers
|
|
67
|
-
* @param body
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
export async function createInvoiceOrder(
|
|
71
|
-
headers: any,
|
|
72
|
-
body: Partial<InvoiceGraphQL>
|
|
73
|
-
): Promise<AxiosUtilsResponse<InvoiceGraphQL>> {
|
|
74
|
-
return handlePossibleAxiosErrors(async () => {
|
|
75
|
-
const sendBody = {
|
|
76
|
-
...body,
|
|
77
|
-
issued: false, // Esto lo hace una órden y no una factura
|
|
78
|
-
invoice_details_attributes: arrayToObject(body.invoice_details),
|
|
79
|
-
tag_ids: body.tagging_invoices?.map((x) => x.tag_id) ?? [],
|
|
80
|
-
} as any;
|
|
81
|
-
|
|
82
|
-
if (sendBody.deleted_invoice_details)
|
|
83
|
-
delete sendBody.deleted_invoice_details;
|
|
84
|
-
if (sendBody.__rvfInternalFormId) delete sendBody.__rvfInternalFormId;
|
|
85
|
-
if (sendBody.invoice_details) delete sendBody.invoice_details;
|
|
86
|
-
|
|
87
|
-
const response = await httpZauru.post<InvoiceGraphQL>(
|
|
88
|
-
`/sales/orders.json`,
|
|
89
|
-
{ invoice: sendBody },
|
|
90
|
-
{ headers }
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return response.data;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* updateInvoiceOrder
|
|
99
|
-
* @param headers
|
|
100
|
-
* @param body
|
|
101
|
-
* @returns
|
|
102
|
-
*/
|
|
103
|
-
export async function updateInvoiceOrder(
|
|
104
|
-
headers: any,
|
|
105
|
-
body: Partial<InvoiceGraphQL>
|
|
106
|
-
): Promise<AxiosUtilsResponse<InvoiceGraphQL>> {
|
|
107
|
-
return handlePossibleAxiosErrors(async () => {
|
|
108
|
-
const sendBody = {
|
|
109
|
-
...body,
|
|
110
|
-
invoice_details_attributes: arrayToObject(body.invoice_details),
|
|
111
|
-
} as any;
|
|
112
|
-
if (sendBody.deleted_invoice_details)
|
|
113
|
-
delete sendBody.deleted_invoice_details;
|
|
114
|
-
if (sendBody.__rvfInternalFormId) delete sendBody.__rvfInternalFormId;
|
|
115
|
-
if (sendBody.invoice_details) delete sendBody.invoice_details;
|
|
116
|
-
|
|
117
|
-
const response = await httpZauru.patch<InvoiceGraphQL>(
|
|
118
|
-
`/sales/orders/${body.id}.json`,
|
|
119
|
-
{ invoice: sendBody },
|
|
120
|
-
{ headers }
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
return response.data;
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* deleteInvoice
|
|
129
|
-
* @param headers
|
|
130
|
-
* @param body
|
|
131
|
-
*/
|
|
132
|
-
export async function deleteInvoiceOrder(
|
|
133
|
-
headers: any,
|
|
134
|
-
id: string | number
|
|
135
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
136
|
-
return handlePossibleAxiosErrors(async () => {
|
|
137
|
-
await httpZauru.get<any>(`/sales/orders/${id}/void`, {
|
|
138
|
-
headers,
|
|
139
|
-
});
|
|
140
|
-
return true;
|
|
141
|
-
});
|
|
142
|
-
}
|
package/src/zauru/zauru-items.ts
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
3
|
-
extractValueBetweenTags,
|
|
4
|
-
handlePossibleAxiosErrors,
|
|
5
|
-
} from "@zauru-sdk/common";
|
|
6
|
-
import {
|
|
7
|
-
AxiosUtilsResponse,
|
|
8
|
-
HTMLItemListSchema,
|
|
9
|
-
ItemCategoryGraphQL,
|
|
10
|
-
ItemDataTable,
|
|
11
|
-
ItemGraphQL,
|
|
12
|
-
ItemSuperCategoryGraphQL,
|
|
13
|
-
ResponseItemList,
|
|
14
|
-
SearchItemParams,
|
|
15
|
-
} from "@zauru-sdk/types";
|
|
16
|
-
import { getGraphQLAPIHeaders } from "../common.js";
|
|
17
|
-
import httpGraphQLAPI from "./httpGraphQL.js";
|
|
18
|
-
import {
|
|
19
|
-
getItemByNameStringQuery,
|
|
20
|
-
getItemCategoryByIdStringQuery,
|
|
21
|
-
getItemsByCategoryStringQuery,
|
|
22
|
-
getItemsBySuperCategoryStringQuery,
|
|
23
|
-
getItemsStringQuery,
|
|
24
|
-
getSuperCategoryByIdStringQuery,
|
|
25
|
-
} from "@zauru-sdk/graphql";
|
|
26
|
-
import httpZauru from "./httpZauru.js";
|
|
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
|
-
|
|
75
|
-
/**
|
|
76
|
-
* getItems
|
|
77
|
-
*/
|
|
78
|
-
export async function getItems(
|
|
79
|
-
session: Session
|
|
80
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> {
|
|
81
|
-
return handlePossibleAxiosErrors(async () => {
|
|
82
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
83
|
-
|
|
84
|
-
const response = await httpGraphQLAPI.post<{
|
|
85
|
-
data: { items: ItemGraphQL[] };
|
|
86
|
-
errors?: {
|
|
87
|
-
message: string;
|
|
88
|
-
extensions: { path: string; code: string };
|
|
89
|
-
}[];
|
|
90
|
-
}>(
|
|
91
|
-
"",
|
|
92
|
-
{
|
|
93
|
-
query: getItemsStringQuery,
|
|
94
|
-
},
|
|
95
|
-
{ headers }
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (response.data.errors) {
|
|
99
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const items = response?.data?.data?.items ?? [];
|
|
103
|
-
|
|
104
|
-
return items;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* getItemByName
|
|
110
|
-
*/
|
|
111
|
-
export async function getItemByName(
|
|
112
|
-
session: Session,
|
|
113
|
-
name: string
|
|
114
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL>> {
|
|
115
|
-
return handlePossibleAxiosErrors(async () => {
|
|
116
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
117
|
-
|
|
118
|
-
const response = await httpGraphQLAPI.post<{
|
|
119
|
-
data: { items: ItemGraphQL[] };
|
|
120
|
-
errors?: {
|
|
121
|
-
message: string;
|
|
122
|
-
extensions: { path: string; code: string };
|
|
123
|
-
}[];
|
|
124
|
-
}>(
|
|
125
|
-
"",
|
|
126
|
-
{
|
|
127
|
-
query: getItemByNameStringQuery,
|
|
128
|
-
variables: {
|
|
129
|
-
name,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
{ headers }
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
if (response.data.errors) {
|
|
136
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!response?.data?.data?.items[0]) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
`No se encontró ningún item con el nombre: ${name} asociado`
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const register = response?.data?.data?.items[0];
|
|
146
|
-
|
|
147
|
-
return register;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
//===================== ITEM CATEGORIES
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* getItemCategories
|
|
155
|
-
* @param headers
|
|
156
|
-
* @param agency_id
|
|
157
|
-
* @returns
|
|
158
|
-
*/
|
|
159
|
-
export async function getItemCategories(
|
|
160
|
-
headers: any,
|
|
161
|
-
item_category_id: string
|
|
162
|
-
): Promise<ItemCategoryGraphQL> {
|
|
163
|
-
const response = await httpZauru.get<ItemCategoryGraphQL>(
|
|
164
|
-
`/settings/items/item_categories/${item_category_id}.json`,
|
|
165
|
-
{
|
|
166
|
-
headers,
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
return response.data;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* getItemsByCategoryId
|
|
175
|
-
*/
|
|
176
|
-
export async function getItemsByCategoryId(
|
|
177
|
-
session: Session,
|
|
178
|
-
id: string
|
|
179
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> {
|
|
180
|
-
return handlePossibleAxiosErrors(async () => {
|
|
181
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
182
|
-
|
|
183
|
-
const response = await httpGraphQLAPI.post<{
|
|
184
|
-
data: { item_categories: ItemCategoryGraphQL[] };
|
|
185
|
-
errors?: {
|
|
186
|
-
message: string;
|
|
187
|
-
extensions: { path: string; code: string };
|
|
188
|
-
}[];
|
|
189
|
-
}>(
|
|
190
|
-
"",
|
|
191
|
-
{
|
|
192
|
-
query: getItemsByCategoryStringQuery,
|
|
193
|
-
variables: {
|
|
194
|
-
id,
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
{ headers }
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
if (response.data.errors) {
|
|
201
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (!response?.data?.data?.item_categories[0]) {
|
|
205
|
-
throw new Error("No se encontró la categoría de item indicada");
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const items = response?.data?.data?.item_categories[0]?.items ?? [];
|
|
209
|
-
|
|
210
|
-
return items;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* getItemCategory
|
|
216
|
-
* @param session
|
|
217
|
-
* @param id
|
|
218
|
-
*/
|
|
219
|
-
export async function getItemCategory(
|
|
220
|
-
session: Session,
|
|
221
|
-
id: number | string
|
|
222
|
-
): Promise<AxiosUtilsResponse<ItemCategoryGraphQL | undefined>> {
|
|
223
|
-
return handlePossibleAxiosErrors(async () => {
|
|
224
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
225
|
-
|
|
226
|
-
const response = await httpGraphQLAPI.post<{
|
|
227
|
-
data: { item_categories: ItemCategoryGraphQL[] };
|
|
228
|
-
errors?: {
|
|
229
|
-
message: string;
|
|
230
|
-
extensions: { path: string; code: string };
|
|
231
|
-
}[];
|
|
232
|
-
}>(
|
|
233
|
-
"",
|
|
234
|
-
{
|
|
235
|
-
query: getItemCategoryByIdStringQuery,
|
|
236
|
-
variables: {
|
|
237
|
-
id,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
{ headers }
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
if (response.data.errors) {
|
|
244
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!response?.data?.data?.item_categories[0]) {
|
|
248
|
-
throw new Error("No se encontró la categoría de item indicada");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return response?.data?.data?.item_categories[0];
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* getItemCategoriesBySuperCategoryId
|
|
257
|
-
* @param session
|
|
258
|
-
* @param categoryId
|
|
259
|
-
* @returns
|
|
260
|
-
*/
|
|
261
|
-
export async function getItemCategoriesBySuperCategoryId(
|
|
262
|
-
session: Session,
|
|
263
|
-
id: number | string
|
|
264
|
-
): Promise<AxiosUtilsResponse<ItemCategoryGraphQL[]>> {
|
|
265
|
-
return handlePossibleAxiosErrors(async () => {
|
|
266
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
267
|
-
const response = await httpGraphQLAPI.post<{
|
|
268
|
-
data: {
|
|
269
|
-
item_super_categories: ItemSuperCategoryGraphQL[];
|
|
270
|
-
};
|
|
271
|
-
errors?: {
|
|
272
|
-
message: string;
|
|
273
|
-
extensions: { path: string; code: string };
|
|
274
|
-
}[];
|
|
275
|
-
}>(
|
|
276
|
-
``,
|
|
277
|
-
{
|
|
278
|
-
query: getSuperCategoryByIdStringQuery,
|
|
279
|
-
variables: { id },
|
|
280
|
-
},
|
|
281
|
-
{ headers }
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
if (response.data.errors) {
|
|
285
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (!response?.data?.data.item_super_categories[0].item_categories) {
|
|
289
|
-
return [];
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return response.data?.data.item_super_categories[0]?.item_categories;
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* getItemsBySuperCategoryId
|
|
298
|
-
* @param session
|
|
299
|
-
* @param categoryId
|
|
300
|
-
* @returns
|
|
301
|
-
*/
|
|
302
|
-
export async function getItemsBySuperCategoryId(
|
|
303
|
-
session: Session,
|
|
304
|
-
id: number | string,
|
|
305
|
-
agency_id: number | string
|
|
306
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> {
|
|
307
|
-
return handlePossibleAxiosErrors(async () => {
|
|
308
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
309
|
-
const response = await httpGraphQLAPI.post<{
|
|
310
|
-
data: {
|
|
311
|
-
item_super_categories: ItemSuperCategoryGraphQL[];
|
|
312
|
-
};
|
|
313
|
-
errors?: {
|
|
314
|
-
message: string;
|
|
315
|
-
extensions: { path: string; code: string };
|
|
316
|
-
}[];
|
|
317
|
-
}>(
|
|
318
|
-
``,
|
|
319
|
-
{
|
|
320
|
-
query: getItemsBySuperCategoryStringQuery,
|
|
321
|
-
variables: { id, agency_id },
|
|
322
|
-
},
|
|
323
|
-
{ headers }
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
if (response.data.errors) {
|
|
327
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!response?.data?.data.item_super_categories[0].item_categories) {
|
|
331
|
-
return [];
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const items: ItemGraphQL[] = [];
|
|
335
|
-
|
|
336
|
-
response.data?.data.item_super_categories[0]?.item_categories.forEach((x) =>
|
|
337
|
-
items.push(...x.items)
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
return items;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* createItemSuperCategory
|
|
346
|
-
* @param session
|
|
347
|
-
* @param headers
|
|
348
|
-
* @returns
|
|
349
|
-
*/
|
|
350
|
-
export async function createItemSuperCategory(
|
|
351
|
-
headers: any,
|
|
352
|
-
body: Partial<ItemSuperCategoryGraphQL>
|
|
353
|
-
): Promise<AxiosUtilsResponse<ItemSuperCategoryGraphQL>> {
|
|
354
|
-
return handlePossibleAxiosErrors(async () => {
|
|
355
|
-
const response = await httpZauru.post<ItemSuperCategoryGraphQL>(
|
|
356
|
-
"/settings/items/item_super_categories.json",
|
|
357
|
-
{ item_super_category: body },
|
|
358
|
-
{ headers }
|
|
359
|
-
);
|
|
360
|
-
return response.data;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* createItemCategory
|
|
366
|
-
* @param session
|
|
367
|
-
* @param headers
|
|
368
|
-
* @returns
|
|
369
|
-
*/
|
|
370
|
-
export async function createItemCategory(
|
|
371
|
-
headers: any,
|
|
372
|
-
body: Partial<ItemCategoryGraphQL>
|
|
373
|
-
): Promise<AxiosUtilsResponse<ItemCategoryGraphQL>> {
|
|
374
|
-
return handlePossibleAxiosErrors(async () => {
|
|
375
|
-
const itemCategoryResponse = await httpZauru.post<ItemCategoryGraphQL>(
|
|
376
|
-
"/settings/items/item_categories",
|
|
377
|
-
{ item_category: body },
|
|
378
|
-
{ headers }
|
|
379
|
-
);
|
|
380
|
-
return itemCategoryResponse.data;
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* deleteItemCategory
|
|
386
|
-
* @param headers
|
|
387
|
-
* @param id
|
|
388
|
-
* @returns
|
|
389
|
-
*/
|
|
390
|
-
export async function deleteItemCategory(
|
|
391
|
-
headers: any,
|
|
392
|
-
id: string | number
|
|
393
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
394
|
-
return handlePossibleAxiosErrors(async () => {
|
|
395
|
-
await httpZauru.delete<any>(
|
|
396
|
-
`/settings/items/item_categories/${id}?destroy=true`,
|
|
397
|
-
{
|
|
398
|
-
headers,
|
|
399
|
-
}
|
|
400
|
-
);
|
|
401
|
-
return true;
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* updatePayee
|
|
407
|
-
* @param session
|
|
408
|
-
* @param headers
|
|
409
|
-
* @returns
|
|
410
|
-
*/
|
|
411
|
-
export async function updateItemCategory(
|
|
412
|
-
headers: any,
|
|
413
|
-
body: Partial<ItemCategoryGraphQL>
|
|
414
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
415
|
-
return handlePossibleAxiosErrors(async () => {
|
|
416
|
-
await httpZauru.patch<any>(
|
|
417
|
-
`/settings/items/item_categories/${body.id}`,
|
|
418
|
-
{ item_category: body },
|
|
419
|
-
{ headers }
|
|
420
|
-
);
|
|
421
|
-
return true;
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* createItem
|
|
427
|
-
* @param headers
|
|
428
|
-
* @param body
|
|
429
|
-
* @returns
|
|
430
|
-
*/
|
|
431
|
-
export async function createItem(
|
|
432
|
-
headers: any,
|
|
433
|
-
body: Partial<ItemGraphQL>
|
|
434
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL>> {
|
|
435
|
-
return handlePossibleAxiosErrors(async () => {
|
|
436
|
-
const response = await httpZauru.post<ItemGraphQL>(
|
|
437
|
-
`/settings/items.json`,
|
|
438
|
-
{ item: body },
|
|
439
|
-
{ headers }
|
|
440
|
-
);
|
|
441
|
-
return response.data;
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* updateItem
|
|
447
|
-
* @param headers
|
|
448
|
-
* @param body
|
|
449
|
-
* @param id
|
|
450
|
-
* @returns
|
|
451
|
-
*/
|
|
452
|
-
export async function updateItem(headers: any, body: Partial<ItemGraphQL>) {
|
|
453
|
-
return handlePossibleAxiosErrors(async () => {
|
|
454
|
-
await httpZauru.patch<Partial<ItemGraphQL>>(
|
|
455
|
-
`/settings/items/${body.id}.json`,
|
|
456
|
-
body,
|
|
457
|
-
{
|
|
458
|
-
headers,
|
|
459
|
-
}
|
|
460
|
-
);
|
|
461
|
-
return true;
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* deleteItemCategory
|
|
467
|
-
* @param headers
|
|
468
|
-
* @param id
|
|
469
|
-
* @returns
|
|
470
|
-
*/
|
|
471
|
-
export async function deleteItem(
|
|
472
|
-
headers: any,
|
|
473
|
-
id: string | number
|
|
474
|
-
): Promise<AxiosUtilsResponse<boolean>> {
|
|
475
|
-
return handlePossibleAxiosErrors(async () => {
|
|
476
|
-
await httpZauru.delete<any>(`/settings/items/${id}?destroy=true`, {
|
|
477
|
-
headers,
|
|
478
|
-
});
|
|
479
|
-
return true;
|
|
480
|
-
});
|
|
481
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import { LoteRecordBody, WebAppRowGraphQL } from "@zauru-sdk/types";
|
|
3
|
-
import { getVariablesByName } from "../common.js";
|
|
4
|
-
import {
|
|
5
|
-
createWebAppTableRegister,
|
|
6
|
-
deleteWebAppTableRegister,
|
|
7
|
-
getWebAppTableRegisters,
|
|
8
|
-
} from "./zauru-web-app-tables.js";
|
|
9
|
-
|
|
10
|
-
export async function getLoteRecord(
|
|
11
|
-
headers: any,
|
|
12
|
-
session: Session
|
|
13
|
-
): Promise<WebAppRowGraphQL<LoteRecordBody>[]> {
|
|
14
|
-
const { lote_record_webapp_table_id: webapp_table_id } =
|
|
15
|
-
await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
|
|
16
|
-
|
|
17
|
-
const response = await getWebAppTableRegisters<LoteRecordBody>(
|
|
18
|
-
session,
|
|
19
|
-
webapp_table_id
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
if (response.error) {
|
|
23
|
-
throw new Error(`Error al obtener el lote: ${response.userMsg}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const lotes = response.data ?? [];
|
|
27
|
-
|
|
28
|
-
return lotes;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function deleteLoteRecord(
|
|
32
|
-
headers: any,
|
|
33
|
-
session: Session,
|
|
34
|
-
id: number
|
|
35
|
-
): Promise<any> {
|
|
36
|
-
const { lote_record_webapp_table_id: webapp_table_id } =
|
|
37
|
-
await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
|
|
38
|
-
|
|
39
|
-
const response = await deleteWebAppTableRegister(
|
|
40
|
-
headers,
|
|
41
|
-
webapp_table_id,
|
|
42
|
-
id
|
|
43
|
-
);
|
|
44
|
-
return response.data;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function createLoteRecord(
|
|
48
|
-
headers: any,
|
|
49
|
-
session: Session,
|
|
50
|
-
body: LoteRecordBody
|
|
51
|
-
) {
|
|
52
|
-
const { lote_record_webapp_table_id: webapp_table_id } =
|
|
53
|
-
await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
|
|
54
|
-
|
|
55
|
-
const response = await createWebAppTableRegister<LoteRecordBody>(
|
|
56
|
-
headers,
|
|
57
|
-
webapp_table_id,
|
|
58
|
-
body
|
|
59
|
-
);
|
|
60
|
-
return response.data;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function updateLoteRecord(
|
|
64
|
-
headers: any,
|
|
65
|
-
session: Session,
|
|
66
|
-
id: number
|
|
67
|
-
): Promise<any> {
|
|
68
|
-
const { lote_record_webapp_table_id: webapp_table_id } =
|
|
69
|
-
await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
|
|
70
|
-
|
|
71
|
-
const response = await deleteWebAppTableRegister(
|
|
72
|
-
headers,
|
|
73
|
-
webapp_table_id,
|
|
74
|
-
id
|
|
75
|
-
);
|
|
76
|
-
return response.data;
|
|
77
|
-
}
|