@zauru-sdk/utils 1.0.7 → 1.0.9
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 +16 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.js +23 -2
- package/dist/zauru/automatic-number.utils.d.ts +9 -0
- package/dist/zauru/automatic-number.utils.js +24 -0
- package/dist/zauru/bitacora-edicion-masiva.utils.d.ts +23 -0
- package/dist/zauru/bitacora-edicion-masiva.utils.js +50 -0
- package/dist/zauru/bundles.utils.d.ts +39 -0
- package/dist/zauru/bundles.utils.js +160 -0
- package/dist/zauru/cases.utils.d.ts +9 -0
- package/dist/zauru/cases.utils.js +17 -0
- package/dist/zauru/consolidated-history.utils.d.ts +24 -0
- package/dist/zauru/consolidated-history.utils.js +52 -0
- package/dist/zauru/costos-items.utils.d.ts +87 -0
- package/dist/zauru/costos-items.utils.js +601 -0
- package/dist/zauru/deliveries.utils.d.ts +17 -0
- package/dist/zauru/deliveries.utils.js +46 -0
- package/dist/zauru/discharges-histsory.utils.d.ts +24 -0
- package/dist/zauru/discharges-histsory.utils.js +46 -0
- package/dist/zauru/employees.utils.d.ts +16 -0
- package/dist/zauru/employees.utils.js +39 -0
- package/dist/zauru/form.utils.d.ts +34 -0
- package/dist/zauru/form.utils.js +152 -0
- package/dist/zauru/invoices.utils.d.ts +22 -0
- package/dist/zauru/invoices.utils.js +79 -0
- package/dist/zauru/items.utils.d.ts +52 -0
- package/dist/zauru/items.utils.js +152 -0
- package/dist/zauru/lotes.utils.d.ts +31 -0
- package/dist/zauru/lotes.utils.js +307 -0
- package/dist/zauru/motivos-rechazo.utils.d.ts +10 -0
- package/dist/zauru/motivos-rechazo.utils.js +18 -0
- package/dist/zauru/payees.utils.d.ts +42 -0
- package/dist/zauru/payees.utils.js +128 -0
- package/dist/zauru/profiles.utils.d.ts +15 -0
- package/dist/zauru/profiles.utils.js +37 -0
- package/dist/zauru/providers.utils.d.ts +13 -0
- package/dist/zauru/providers.utils.js +36 -0
- package/dist/zauru/purchase-orders.utils.d.ts +114 -0
- package/dist/zauru/purchase-orders.utils.js +376 -0
- package/dist/zauru/shipments.utils.d.ts +21 -0
- package/dist/zauru/shipments.utils.js +90 -0
- package/dist/zauru/specialItem.utils.d.ts +34 -0
- package/dist/zauru/specialItem.utils.js +62 -0
- package/dist/zauru/templates.utils.d.ts +49 -0
- package/dist/zauru/templates.utils.js +93 -0
- package/dist/zauru/tiposMuestra.utils.d.ts +34 -0
- package/dist/zauru/tiposMuestra.utils.js +62 -0
- package/dist/zauru/webapp-tables.utils.d.ts +16 -0
- package/dist/zauru/webapp-tables.utils.js +51 -0
- package/package.json +6 -6
- package/src/index.ts +23 -0
- package/src/zauru/bitacora-edicion-masiva.utils.ts +99 -0
- package/src/zauru/bundles.utils.ts +251 -0
- package/src/zauru/cases.utils.ts +31 -0
- package/src/zauru/consolidated-history.utils.ts +102 -0
- package/src/zauru/costos-items.utils.ts +865 -0
- package/src/zauru/deliveries.utils.ts +77 -0
- package/src/zauru/discharges-histsory.utils.ts +105 -0
- package/src/zauru/employees.utils.ts +59 -0
- package/src/zauru/form.utils.ts +243 -0
- package/src/zauru/invoices.utils.ts +114 -0
- package/src/zauru/items.utils.ts +269 -0
- package/src/zauru/lotes.utils.ts +411 -0
- package/src/zauru/motivos-rechazo.utils.ts +47 -0
- package/src/zauru/payees.utils.ts +213 -0
- package/src/zauru/profiles.utils.ts +44 -0
- package/src/zauru/providers.utils.ts +67 -0
- package/src/zauru/purchase-orders.utils.ts +594 -0
- package/src/zauru/shipments.utils.ts +139 -0
- package/src/zauru/specialItem.utils.ts +126 -0
- package/src/zauru/templates.utils.ts +199 -0
- package/src/zauru/tiposMuestra.utils.ts +136 -0
- package/src/zauru/webapp-tables.utils.ts +94 -0
- /package/src/{automatic-number.utils.ts → zauru/automatic-number.utils.ts} +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { getDatePickerCurrentDate, handlePossibleAxiosErrors, reduceAdd } from "@zauru-sdk/common";
|
|
3
|
+
import { getDeliveryByBooking, getMyAgencyLotStocks, getShipmentsByToAgencyLast100Id_booking, getVariablesByName, insertBookings } from "@zauru-sdk/services";
|
|
4
|
+
import { AxiosUtilsResponse, InsertBookingBody, MovementGraphQL, ShipmentGraphQL } from "@zauru-sdk/types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param headers
|
|
9
|
+
* @param session
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export const getShipmentsToMyAgency = async (
|
|
13
|
+
session: Session
|
|
14
|
+
): Promise<AxiosUtilsResponse<ShipmentGraphQL[]>> => {
|
|
15
|
+
return handlePossibleAxiosErrors(async () => {
|
|
16
|
+
const response = await getShipmentsByToAgencyLast100Id_booking(
|
|
17
|
+
session,
|
|
18
|
+
session.get("agency_id")
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (response.error) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Ocurrió un error al consultar los envíos a mi agencia actual: ${response.userMsg}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return response?.data ?? [];
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param headers
|
|
34
|
+
* @param session
|
|
35
|
+
* @param props
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export const shipmentToVirtualClientAgency = async (
|
|
39
|
+
headers: any,
|
|
40
|
+
session: Session,
|
|
41
|
+
props: {
|
|
42
|
+
deliver_quantity: number;
|
|
43
|
+
item_id: number;
|
|
44
|
+
esPerecedero?: boolean;
|
|
45
|
+
}
|
|
46
|
+
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
47
|
+
return handlePossibleAxiosErrors(async () => {
|
|
48
|
+
const { virtual_client_agency_id } = await getVariablesByName(
|
|
49
|
+
headers,
|
|
50
|
+
session,
|
|
51
|
+
["virtual_client_agency_id"]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
let bookingBody: Partial<InsertBookingBody> = {};
|
|
55
|
+
|
|
56
|
+
if (props?.esPerecedero) {
|
|
57
|
+
const responseStocks = await getMyAgencyLotStocks(session);
|
|
58
|
+
if (!responseStocks.data || responseStocks.error) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Ocurrió un error al tratar de obtener los stocks de mi agencia. ${responseStocks.userMsg}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let deliverQuantity = props.deliver_quantity;
|
|
65
|
+
const itemStocks = responseStocks.data
|
|
66
|
+
.filter((x) => x.lot.item_id === props.item_id)
|
|
67
|
+
.sort((a, b) => b.available - a.available);
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
itemStocks.map((x) => x.available).reduce(reduceAdd, 0) <
|
|
71
|
+
props.deliver_quantity
|
|
72
|
+
) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`No hay suficiente stock en los lotes para realizar el descuento.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const movements: Partial<MovementGraphQL>[] = itemStocks.reduce(
|
|
79
|
+
(acc: Partial<MovementGraphQL>[], stock) => {
|
|
80
|
+
if (deliverQuantity > 0 && stock.available > 0) {
|
|
81
|
+
const bookedQuantity = Math.min(stock.available, deliverQuantity);
|
|
82
|
+
deliverQuantity -= bookedQuantity;
|
|
83
|
+
|
|
84
|
+
acc.push({
|
|
85
|
+
item_id: props.item_id,
|
|
86
|
+
booked_quantity: bookedQuantity,
|
|
87
|
+
lot_id: stock.lot_id,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
},
|
|
92
|
+
[]
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
bookingBody = {
|
|
96
|
+
reference: "LABORATORIO - Descuento de stock, desde webapp.",
|
|
97
|
+
agency_from_id: session.get("agency_id"),
|
|
98
|
+
agency_to_id: Number(virtual_client_agency_id),
|
|
99
|
+
booker_id: session.get("employee_id"),
|
|
100
|
+
transporter_id: session.get("employee_id"),
|
|
101
|
+
planned_delivery: getDatePickerCurrentDate(),
|
|
102
|
+
needs_transport: false,
|
|
103
|
+
movements,
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
bookingBody = {
|
|
107
|
+
reference: "LABORATORIO - Descuento de stock, desde webapp.",
|
|
108
|
+
agency_from_id: session.get("agency_id"),
|
|
109
|
+
agency_to_id: Number(virtual_client_agency_id),
|
|
110
|
+
booker_id: session.get("employee_id"),
|
|
111
|
+
transporter_id: session.get("employee_id"),
|
|
112
|
+
planned_delivery: getDatePickerCurrentDate(),
|
|
113
|
+
needs_transport: false,
|
|
114
|
+
movements: [
|
|
115
|
+
{ item_id: props.item_id, booked_quantity: props.deliver_quantity },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const response1 = await insertBookings(headers, bookingBody);
|
|
121
|
+
|
|
122
|
+
if (response1.error || !response1.data) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Ocurrió un error al tratar de crear el envío a agencia virtual de cliente: ${response1.userMsg}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//Entregar el envío
|
|
129
|
+
const response2 = await getDeliveryByBooking(headers, response1.data.id);
|
|
130
|
+
|
|
131
|
+
if (response2.error || !response2.data) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Ocurrió un error al tratar de recibir: ${response1.userMsg}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return true;
|
|
138
|
+
});
|
|
139
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
+
import { createWebAppTableRegister, deleteWebAppTableRegister, getVariablesByName, getWebAppTableRegisters, updateWebAppTableRegister } from "@zauru-sdk/services";
|
|
4
|
+
import { AxiosUtilsResponse, SpecialItem, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get specialItems from the web app table.
|
|
9
|
+
* @param headers Request headers.
|
|
10
|
+
* @param session Session object.
|
|
11
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<SpecialItem>[]>>.
|
|
12
|
+
*/
|
|
13
|
+
export async function getSpecialItems(
|
|
14
|
+
headers: any,
|
|
15
|
+
session: Session
|
|
16
|
+
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<SpecialItem>[]>> {
|
|
17
|
+
return handlePossibleAxiosErrors(async () => {
|
|
18
|
+
const { special_product_web_app_table_id } = await getVariablesByName(
|
|
19
|
+
headers,
|
|
20
|
+
session,
|
|
21
|
+
["special_product_web_app_table_id"]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const response = await getWebAppTableRegisters<SpecialItem>(
|
|
25
|
+
session,
|
|
26
|
+
special_product_web_app_table_id
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (response.error) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Ocurrió un error al consultar los items especiales: ${response.userMsg}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const specialItems = response.data ?? [];
|
|
36
|
+
|
|
37
|
+
return specialItems;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a specialItem in the web app table.
|
|
43
|
+
* @param headers Request headers.
|
|
44
|
+
* @param session Session object.
|
|
45
|
+
* @param body SpecialItem data to be created.
|
|
46
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
47
|
+
*/
|
|
48
|
+
export async function createSpecialItem(
|
|
49
|
+
headers: any,
|
|
50
|
+
session: Session,
|
|
51
|
+
body: SpecialItem
|
|
52
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
53
|
+
return handlePossibleAxiosErrors(async () => {
|
|
54
|
+
const { special_product_web_app_table_id } = await getVariablesByName(
|
|
55
|
+
headers,
|
|
56
|
+
session,
|
|
57
|
+
["special_product_web_app_table_id"]
|
|
58
|
+
);
|
|
59
|
+
const response = await createWebAppTableRegister<SpecialItem>(
|
|
60
|
+
headers,
|
|
61
|
+
special_product_web_app_table_id,
|
|
62
|
+
body
|
|
63
|
+
);
|
|
64
|
+
return response;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Delete a specialItem from the web app table.
|
|
70
|
+
* @param headers Request headers.
|
|
71
|
+
* @param session Session object.
|
|
72
|
+
* @param id ID of the specialItem to be deleted.
|
|
73
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
74
|
+
*/
|
|
75
|
+
export async function deleteSpecialItem(
|
|
76
|
+
headers: any,
|
|
77
|
+
session: Session,
|
|
78
|
+
id: string
|
|
79
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
80
|
+
return handlePossibleAxiosErrors(async () => {
|
|
81
|
+
const { special_product_web_app_table_id } = await getVariablesByName(
|
|
82
|
+
headers,
|
|
83
|
+
session,
|
|
84
|
+
["special_product_web_app_table_id"]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const response = await deleteWebAppTableRegister(
|
|
88
|
+
headers,
|
|
89
|
+
special_product_web_app_table_id,
|
|
90
|
+
Number(id)
|
|
91
|
+
);
|
|
92
|
+
return response;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Update a specialItem in the web app table.
|
|
98
|
+
* @param headers Request headers.
|
|
99
|
+
* @param session Session object.
|
|
100
|
+
* @param id ID of the specialItem to be updated.
|
|
101
|
+
* @param body Updated specialItem data.
|
|
102
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
103
|
+
*/
|
|
104
|
+
export async function updateSpecialItem(
|
|
105
|
+
headers: any,
|
|
106
|
+
session: Session,
|
|
107
|
+
id: string,
|
|
108
|
+
body: Partial<SpecialItem>
|
|
109
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
110
|
+
return handlePossibleAxiosErrors(async () => {
|
|
111
|
+
const { special_product_web_app_table_id } = await getVariablesByName(
|
|
112
|
+
headers,
|
|
113
|
+
session,
|
|
114
|
+
["special_product_web_app_table_id"]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const response = await updateWebAppTableRegister(
|
|
118
|
+
headers,
|
|
119
|
+
special_product_web_app_table_id,
|
|
120
|
+
Number(id),
|
|
121
|
+
body
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return response;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
+
import {
|
|
4
|
+
createWebAppTableRegister,
|
|
5
|
+
deleteWebAppTableRegister,
|
|
6
|
+
getVariablesByName,
|
|
7
|
+
getWebAppTableRegisters,
|
|
8
|
+
updateWebAppTableRegister,
|
|
9
|
+
} from "@zauru-sdk/services";
|
|
10
|
+
import {
|
|
11
|
+
AxiosUtilsResponse,
|
|
12
|
+
WebAppRowGraphQL,
|
|
13
|
+
Template,
|
|
14
|
+
WebAppTableUpdateResponse,
|
|
15
|
+
HistoryTemplate,
|
|
16
|
+
} from "@zauru-sdk/types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get templates from the web app table.
|
|
20
|
+
* @param headers Request headers.
|
|
21
|
+
* @param session Session object.
|
|
22
|
+
* @returns A Promise of AxiosUtilsResponse<TemplateWebAppTable[]>.
|
|
23
|
+
*/
|
|
24
|
+
export async function getTemplates(
|
|
25
|
+
headers: any,
|
|
26
|
+
session: Session
|
|
27
|
+
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<Template>[]>> {
|
|
28
|
+
return handlePossibleAxiosErrors(async () => {
|
|
29
|
+
const { templates_web_app_table_id } = await getVariablesByName(
|
|
30
|
+
headers,
|
|
31
|
+
session,
|
|
32
|
+
["templates_web_app_table_id"]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const response = await getWebAppTableRegisters<Template>(
|
|
36
|
+
session,
|
|
37
|
+
templates_web_app_table_id
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (response.error) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Ocurrió un error al intentar obtener los templates: ${response.userMsg}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const templateRegisters = response.data ?? [];
|
|
47
|
+
|
|
48
|
+
return templateRegisters;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a template in the web app table.
|
|
54
|
+
* @param headers Request headers.
|
|
55
|
+
* @param session Session object.
|
|
56
|
+
* @param body Template data to be created.
|
|
57
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
58
|
+
*/
|
|
59
|
+
export async function createTemplate(
|
|
60
|
+
headers: any,
|
|
61
|
+
session: Session,
|
|
62
|
+
body: Template
|
|
63
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
64
|
+
return handlePossibleAxiosErrors(async () => {
|
|
65
|
+
const { templates_web_app_table_id } = await getVariablesByName(
|
|
66
|
+
headers,
|
|
67
|
+
session,
|
|
68
|
+
["templates_web_app_table_id"]
|
|
69
|
+
);
|
|
70
|
+
const response = await createWebAppTableRegister<Template>(
|
|
71
|
+
headers,
|
|
72
|
+
templates_web_app_table_id,
|
|
73
|
+
body
|
|
74
|
+
);
|
|
75
|
+
return response;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Delete a template from the web app table.
|
|
81
|
+
* @param headers Request headers.
|
|
82
|
+
* @param session Session object.
|
|
83
|
+
* @param id ID of the template to be deleted.
|
|
84
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
85
|
+
*/
|
|
86
|
+
export async function deleteTemplate(
|
|
87
|
+
headers: any,
|
|
88
|
+
session: Session,
|
|
89
|
+
id: string
|
|
90
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
91
|
+
return handlePossibleAxiosErrors(async () => {
|
|
92
|
+
const { templates_web_app_table_id } = await getVariablesByName(
|
|
93
|
+
headers,
|
|
94
|
+
session,
|
|
95
|
+
["templates_web_app_table_id"]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const response = await deleteWebAppTableRegister(
|
|
99
|
+
headers,
|
|
100
|
+
templates_web_app_table_id,
|
|
101
|
+
Number(id)
|
|
102
|
+
);
|
|
103
|
+
return response;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Update a template in the web app table.
|
|
109
|
+
* @param headers Request headers.
|
|
110
|
+
* @param session Session object.
|
|
111
|
+
* @param id ID of the template to be updated.
|
|
112
|
+
* @param body Updated template data.
|
|
113
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
114
|
+
*/
|
|
115
|
+
export async function updateTemplate(
|
|
116
|
+
headers: any,
|
|
117
|
+
session: Session,
|
|
118
|
+
id: string,
|
|
119
|
+
body: Partial<Template>
|
|
120
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
121
|
+
return handlePossibleAxiosErrors(async () => {
|
|
122
|
+
const { templates_web_app_table_id } = await getVariablesByName(
|
|
123
|
+
headers,
|
|
124
|
+
session,
|
|
125
|
+
["templates_web_app_table_id"]
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const response = await updateWebAppTableRegister(
|
|
129
|
+
headers,
|
|
130
|
+
templates_web_app_table_id,
|
|
131
|
+
Number(id),
|
|
132
|
+
body
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
return response;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Create a template history entry in the web app table.
|
|
141
|
+
* @param headers Request headers.
|
|
142
|
+
* @param session Session object.
|
|
143
|
+
* @param body Template history data to be created.
|
|
144
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
145
|
+
*/
|
|
146
|
+
export async function createTemplateHistory(
|
|
147
|
+
headers: any,
|
|
148
|
+
session: Session,
|
|
149
|
+
body: Partial<HistoryTemplate>
|
|
150
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
151
|
+
return handlePossibleAxiosErrors(async () => {
|
|
152
|
+
const { history_templates_web_app_table_id } = await getVariablesByName(
|
|
153
|
+
headers,
|
|
154
|
+
session,
|
|
155
|
+
["history_templates_web_app_table_id"]
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const response = await createWebAppTableRegister<Partial<HistoryTemplate>>(
|
|
159
|
+
headers,
|
|
160
|
+
history_templates_web_app_table_id,
|
|
161
|
+
body
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return response;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get template history entries from the web app table.
|
|
170
|
+
* @param headers Request headers.
|
|
171
|
+
* @param session Session object.
|
|
172
|
+
* @returns A Promise of AxiosUtilsResponse<TemplateHistoryWebAppTable[]>.
|
|
173
|
+
*/
|
|
174
|
+
export async function getTemplatesHistory(
|
|
175
|
+
headers: any,
|
|
176
|
+
session: Session
|
|
177
|
+
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<HistoryTemplate>[]>> {
|
|
178
|
+
return handlePossibleAxiosErrors(async () => {
|
|
179
|
+
const { history_templates_web_app_table_id } = await getVariablesByName(
|
|
180
|
+
headers,
|
|
181
|
+
session,
|
|
182
|
+
["history_templates_web_app_table_id"]
|
|
183
|
+
);
|
|
184
|
+
const response = await getWebAppTableRegisters<HistoryTemplate>(
|
|
185
|
+
session,
|
|
186
|
+
history_templates_web_app_table_id
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
if (response.error) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Ocurrió un error al intentar obtener los history templates: ${response.userMsg}`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const templateRegisters = response.data ?? [];
|
|
196
|
+
|
|
197
|
+
return templateRegisters;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
+
import {
|
|
4
|
+
createWebAppTableRegister,
|
|
5
|
+
deleteWebAppTableRegister,
|
|
6
|
+
getVariablesByName,
|
|
7
|
+
getWebAppTableRegisters,
|
|
8
|
+
updateWebAppTableRegister,
|
|
9
|
+
} from "@zauru-sdk/services";
|
|
10
|
+
import {
|
|
11
|
+
WebAppRowGraphQL,
|
|
12
|
+
TipoMuestra,
|
|
13
|
+
AxiosUtilsResponse,
|
|
14
|
+
WebAppTableUpdateResponse,
|
|
15
|
+
} from "@zauru-sdk/types";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get tipoMuestras from the web app table.
|
|
19
|
+
* @param headers Request headers.
|
|
20
|
+
* @param session Session object.
|
|
21
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<TipoMuestra>[]>>.
|
|
22
|
+
*/
|
|
23
|
+
export async function getTipoMuestras(
|
|
24
|
+
headers: any,
|
|
25
|
+
session: Session
|
|
26
|
+
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<TipoMuestra>[]>> {
|
|
27
|
+
return handlePossibleAxiosErrors(async () => {
|
|
28
|
+
const { tipo_muestra_web_app_table_id } = await getVariablesByName(
|
|
29
|
+
headers,
|
|
30
|
+
session,
|
|
31
|
+
["tipo_muestra_web_app_table_id"]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const response = await getWebAppTableRegisters<TipoMuestra>(
|
|
35
|
+
session,
|
|
36
|
+
tipo_muestra_web_app_table_id
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (response.error) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Ocurrió un error al consultar los tipos de muestra: ${response.userMsg}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const tipoMuestras = response.data ?? [];
|
|
46
|
+
|
|
47
|
+
return tipoMuestras;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a tipoMuestra in the web app table.
|
|
53
|
+
* @param headers Request headers.
|
|
54
|
+
* @param session Session object.
|
|
55
|
+
* @param body TipoMuestra data to be created.
|
|
56
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
57
|
+
*/
|
|
58
|
+
export async function createTipoMuestra(
|
|
59
|
+
headers: any,
|
|
60
|
+
session: Session,
|
|
61
|
+
body: TipoMuestra
|
|
62
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
63
|
+
return handlePossibleAxiosErrors(async () => {
|
|
64
|
+
const { tipo_muestra_web_app_table_id } = await getVariablesByName(
|
|
65
|
+
headers,
|
|
66
|
+
session,
|
|
67
|
+
["tipo_muestra_web_app_table_id"]
|
|
68
|
+
);
|
|
69
|
+
const response = await createWebAppTableRegister<TipoMuestra>(
|
|
70
|
+
headers,
|
|
71
|
+
tipo_muestra_web_app_table_id,
|
|
72
|
+
body
|
|
73
|
+
);
|
|
74
|
+
return response;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Delete a tipoMuestra from the web app table.
|
|
80
|
+
* @param headers Request headers.
|
|
81
|
+
* @param session Session object.
|
|
82
|
+
* @param id ID of the tipoMuestra to be deleted.
|
|
83
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
84
|
+
*/
|
|
85
|
+
export async function deleteTipoMuestra(
|
|
86
|
+
headers: any,
|
|
87
|
+
session: Session,
|
|
88
|
+
id: string
|
|
89
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
90
|
+
return handlePossibleAxiosErrors(async () => {
|
|
91
|
+
const { tipo_muestra_web_app_table_id } = await getVariablesByName(
|
|
92
|
+
headers,
|
|
93
|
+
session,
|
|
94
|
+
["tipo_muestra_web_app_table_id"]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const response = await deleteWebAppTableRegister(
|
|
98
|
+
headers,
|
|
99
|
+
tipo_muestra_web_app_table_id,
|
|
100
|
+
Number(id)
|
|
101
|
+
);
|
|
102
|
+
return response;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Update a tipoMuestra in the web app table.
|
|
108
|
+
* @param headers Request headers.
|
|
109
|
+
* @param session Session object.
|
|
110
|
+
* @param id ID of the tipoMuestra to be updated.
|
|
111
|
+
* @param body Updated tipoMuestra data.
|
|
112
|
+
* @returns A Promise of AxiosUtilsResponse<WebAppTableUpdateResponse>.
|
|
113
|
+
*/
|
|
114
|
+
export async function updateTipoMuestra(
|
|
115
|
+
headers: any,
|
|
116
|
+
session: Session,
|
|
117
|
+
id: string,
|
|
118
|
+
body: Partial<TipoMuestra>
|
|
119
|
+
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
120
|
+
return handlePossibleAxiosErrors(async () => {
|
|
121
|
+
const { tipo_muestra_web_app_table_id } = await getVariablesByName(
|
|
122
|
+
headers,
|
|
123
|
+
session,
|
|
124
|
+
["tipo_muestra_web_app_table_id"]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const response = await updateWebAppTableRegister(
|
|
128
|
+
headers,
|
|
129
|
+
tipo_muestra_web_app_table_id,
|
|
130
|
+
Number(id),
|
|
131
|
+
body
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return response;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
+
import {
|
|
4
|
+
getVariablesByName,
|
|
5
|
+
getWebAppTableRegisters,
|
|
6
|
+
} from "@zauru-sdk/services";
|
|
7
|
+
import httpZauru from "@zauru-sdk/services/dist/zauru/httpZauru.server.js";
|
|
8
|
+
import {
|
|
9
|
+
AxiosUtilsResponse,
|
|
10
|
+
MotivoRechazo,
|
|
11
|
+
RejectionWebAppTableObject,
|
|
12
|
+
WebAppRowGraphQL,
|
|
13
|
+
ReceptionType,
|
|
14
|
+
WebAppTableGraphQL,
|
|
15
|
+
} from "@zauru-sdk/types";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* getWebappTable
|
|
19
|
+
* @param headers
|
|
20
|
+
* @param session
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export const getRejectionWebAppTable = async (
|
|
24
|
+
headers: any,
|
|
25
|
+
session: Session
|
|
26
|
+
): Promise<AxiosUtilsResponse<RejectionWebAppTableObject>> => {
|
|
27
|
+
return handlePossibleAxiosErrors(async () => {
|
|
28
|
+
const {
|
|
29
|
+
recepciones_rejections_webapp_table_id,
|
|
30
|
+
recepciones_rejection_types_webapp_table_id,
|
|
31
|
+
} = await getVariablesByName(headers, session, [
|
|
32
|
+
"recepciones_rejections_webapp_table_id",
|
|
33
|
+
"recepciones_rejection_types_webapp_table_id",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const webappTableResponse = await httpZauru.get<WebAppTableGraphQL>(
|
|
37
|
+
`/apps/webapp_tables/${recepciones_rejections_webapp_table_id}.json`,
|
|
38
|
+
{ headers }
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const webappTableRejectionsResponse = await httpZauru.get<
|
|
42
|
+
WebAppRowGraphQL<MotivoRechazo>[]
|
|
43
|
+
>(
|
|
44
|
+
`/apps/webapp_tables/${recepciones_rejection_types_webapp_table_id}/webapp_rows.json`,
|
|
45
|
+
{ headers }
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const rejections_select: { value: string; label: string }[] = [];
|
|
49
|
+
const rejections_complete = webappTableRejectionsResponse.data;
|
|
50
|
+
const keyName: string = Object.keys(rejections_complete[0].data)[0]; //get the first value
|
|
51
|
+
const rejections_list: string[] = [];
|
|
52
|
+
rejections_complete.forEach((val: any) => {
|
|
53
|
+
rejections_list.push(val.data[keyName]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
rejections_complete.forEach((rc: any) => {
|
|
57
|
+
rejections_select.push({
|
|
58
|
+
value: rc.data[keyName],
|
|
59
|
+
label: rc.data[keyName],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
webapp_table: webappTableResponse.data.structure,
|
|
65
|
+
rejection_list: rejections_list,
|
|
66
|
+
rejection_select: rejections_select,
|
|
67
|
+
} as RejectionWebAppTableObject;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get template history entries from the web app table.
|
|
73
|
+
* @param headers Request headers.
|
|
74
|
+
* @param session Session object.
|
|
75
|
+
* @returns A Promise of AxiosUtilsResponse<ReceptionType[]>.
|
|
76
|
+
*/
|
|
77
|
+
export async function getReceptionTypes(
|
|
78
|
+
headers: any,
|
|
79
|
+
session: Session
|
|
80
|
+
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<ReceptionType>[]>> {
|
|
81
|
+
return handlePossibleAxiosErrors(async () => {
|
|
82
|
+
const { recepciones_receptions_type_table_id } = await getVariablesByName(
|
|
83
|
+
headers,
|
|
84
|
+
session,
|
|
85
|
+
["recepciones_receptions_type_table_id"]
|
|
86
|
+
);
|
|
87
|
+
const response = await getWebAppTableRegisters<ReceptionType>(
|
|
88
|
+
session,
|
|
89
|
+
recepciones_receptions_type_table_id
|
|
90
|
+
);
|
|
91
|
+
const receptionTypes = response?.data ?? [];
|
|
92
|
+
return receptionTypes;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
File without changes
|