@zauru-sdk/utils 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.d.ts +23 -2
  3. package/dist/index.js +23 -2
  4. package/dist/zauru/automatic-number.utils.d.ts +9 -0
  5. package/dist/zauru/automatic-number.utils.js +24 -0
  6. package/dist/zauru/bitacora-edicion-masiva.utils.d.ts +23 -0
  7. package/dist/zauru/bitacora-edicion-masiva.utils.js +50 -0
  8. package/dist/zauru/bundles.utils.d.ts +39 -0
  9. package/dist/zauru/bundles.utils.js +160 -0
  10. package/dist/zauru/cases.utils.d.ts +9 -0
  11. package/dist/zauru/cases.utils.js +17 -0
  12. package/dist/zauru/consolidated-history.utils.d.ts +24 -0
  13. package/dist/zauru/consolidated-history.utils.js +52 -0
  14. package/dist/zauru/costos-items.utils.d.ts +87 -0
  15. package/dist/zauru/costos-items.utils.js +601 -0
  16. package/dist/zauru/deliveries.utils.d.ts +17 -0
  17. package/dist/zauru/deliveries.utils.js +46 -0
  18. package/dist/zauru/discharges-histsory.utils.d.ts +24 -0
  19. package/dist/zauru/discharges-histsory.utils.js +46 -0
  20. package/dist/zauru/employees.utils.d.ts +16 -0
  21. package/dist/zauru/employees.utils.js +39 -0
  22. package/dist/zauru/form.utils.d.ts +34 -0
  23. package/dist/zauru/form.utils.js +152 -0
  24. package/dist/zauru/invoices.utils.d.ts +22 -0
  25. package/dist/zauru/invoices.utils.js +79 -0
  26. package/dist/zauru/items.utils.d.ts +52 -0
  27. package/dist/zauru/items.utils.js +152 -0
  28. package/dist/zauru/lotes.utils.d.ts +31 -0
  29. package/dist/zauru/lotes.utils.js +307 -0
  30. package/dist/zauru/motivos-rechazo.utils.d.ts +10 -0
  31. package/dist/zauru/motivos-rechazo.utils.js +18 -0
  32. package/dist/zauru/payees.utils.d.ts +42 -0
  33. package/dist/zauru/payees.utils.js +128 -0
  34. package/dist/zauru/profiles.utils.d.ts +15 -0
  35. package/dist/zauru/profiles.utils.js +37 -0
  36. package/dist/zauru/providers.utils.d.ts +13 -0
  37. package/dist/zauru/providers.utils.js +36 -0
  38. package/dist/zauru/purchase-orders.utils.d.ts +114 -0
  39. package/dist/zauru/purchase-orders.utils.js +376 -0
  40. package/dist/zauru/shipments.utils.d.ts +21 -0
  41. package/dist/zauru/shipments.utils.js +90 -0
  42. package/dist/zauru/specialItem.utils.d.ts +34 -0
  43. package/dist/zauru/specialItem.utils.js +62 -0
  44. package/dist/zauru/templates.utils.d.ts +49 -0
  45. package/dist/zauru/templates.utils.js +93 -0
  46. package/dist/zauru/tiposMuestra.utils.d.ts +34 -0
  47. package/dist/zauru/tiposMuestra.utils.js +62 -0
  48. package/dist/zauru/webapp-tables.utils.d.ts +16 -0
  49. package/dist/zauru/webapp-tables.utils.js +51 -0
  50. package/package.json +6 -6
  51. package/src/index.ts +23 -0
  52. package/src/zauru/bitacora-edicion-masiva.utils.ts +99 -0
  53. package/src/zauru/bundles.utils.ts +251 -0
  54. package/src/zauru/cases.utils.ts +31 -0
  55. package/src/zauru/consolidated-history.utils.ts +102 -0
  56. package/src/zauru/costos-items.utils.ts +865 -0
  57. package/src/zauru/deliveries.utils.ts +77 -0
  58. package/src/zauru/discharges-histsory.utils.ts +105 -0
  59. package/src/zauru/employees.utils.ts +59 -0
  60. package/src/zauru/form.utils.ts +243 -0
  61. package/src/zauru/invoices.utils.ts +114 -0
  62. package/src/zauru/items.utils.ts +269 -0
  63. package/src/zauru/lotes.utils.ts +411 -0
  64. package/src/zauru/motivos-rechazo.utils.ts +47 -0
  65. package/src/zauru/payees.utils.ts +213 -0
  66. package/src/zauru/profiles.utils.ts +44 -0
  67. package/src/zauru/providers.utils.ts +67 -0
  68. package/src/zauru/purchase-orders.utils.ts +594 -0
  69. package/src/zauru/shipments.utils.ts +139 -0
  70. package/src/zauru/specialItem.utils.ts +126 -0
  71. package/src/zauru/templates.utils.ts +199 -0
  72. package/src/zauru/tiposMuestra.utils.ts +136 -0
  73. package/src/zauru/webapp-tables.utils.ts +94 -0
  74. /package/src/{automatic-number.utils.ts → zauru/automatic-number.utils.ts} +0 -0
@@ -0,0 +1,251 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ getVariablesByName,
5
+ getBundlesByItemCategoryId,
6
+ createBundle,
7
+ createForm,
8
+ deleteBundle,
9
+ getItemByName,
10
+ deleteItem,
11
+ getFormByName,
12
+ deleteForm,
13
+ } from "@zauru-sdk/services";
14
+ import {
15
+ AxiosUtilsResponse,
16
+ BundleGraphQL,
17
+ FormGraphQL,
18
+ ItemGraphQL,
19
+ } from "@zauru-sdk/types";
20
+ import { createNewLaboratoryItem } from "./items.utils.js";
21
+
22
+ export const LAB_BUNDLE_NAME = "LAB_BUNDLE_RECIP_";
23
+
24
+ /**
25
+ *
26
+ * @param headers
27
+ * @param session
28
+ * @returns
29
+ */
30
+ export const getBundlesRecipByLabCategory = async (
31
+ headers: any,
32
+ session: Session
33
+ ): Promise<AxiosUtilsResponse<BundleGraphQL[]>> => {
34
+ return handlePossibleAxiosErrors(async () => {
35
+ const { lab_bundles_recip_item_category_id } = await getVariablesByName(
36
+ headers,
37
+ session,
38
+ ["lab_bundles_recip_item_category_id"]
39
+ );
40
+
41
+ const response = await getBundlesByItemCategoryId(
42
+ session,
43
+ lab_bundles_recip_item_category_id
44
+ );
45
+
46
+ if (response.error) {
47
+ throw new Error(
48
+ `Ocurrió un error al consultar los paquetes por categoría de laboratorio: ${response.userMsg}`
49
+ );
50
+ }
51
+
52
+ return response?.data ?? [];
53
+ });
54
+ };
55
+
56
+ /**
57
+ *
58
+ * @param headers
59
+ * @param session
60
+ * @returns
61
+ */
62
+ export const getBundlesByLabCategory = async (
63
+ headers: any,
64
+ session: Session
65
+ ): Promise<AxiosUtilsResponse<BundleGraphQL[]>> => {
66
+ return handlePossibleAxiosErrors(async () => {
67
+ const { lab_bundles_item_category_id } = await getVariablesByName(
68
+ headers,
69
+ session,
70
+ ["lab_bundles_item_category_id"]
71
+ );
72
+
73
+ const response = await getBundlesByItemCategoryId(
74
+ session,
75
+ lab_bundles_item_category_id
76
+ );
77
+
78
+ if (response.error) {
79
+ throw new Error(
80
+ `Ocurrió un error al consultar los paquetes por categoría de laboratorio: ${response.userMsg}`
81
+ );
82
+ }
83
+
84
+ return response?.data ?? [];
85
+ });
86
+ };
87
+
88
+ /**
89
+ * createNewLabPaquete
90
+ * @param headers
91
+ * @param session
92
+ * @returns
93
+ */
94
+ export const createNewLabPaquete = async (
95
+ headers: any,
96
+ session: Session,
97
+ body: Partial<BundleGraphQL>
98
+ ): Promise<AxiosUtilsResponse<boolean>> => {
99
+ return handlePossibleAxiosErrors(async () => {
100
+ let msg = "";
101
+ const { lab_bundles_item_category_id } = await getVariablesByName(
102
+ headers,
103
+ session,
104
+ ["lab_bundles_item_category_id"]
105
+ );
106
+
107
+ const sendBody: Partial<BundleGraphQL> = {
108
+ ...body,
109
+ bundle_details: body?.bundle_details?.map((x) => {
110
+ x._destroy = false;
111
+ return x;
112
+ }),
113
+ item_category_id: Number(lab_bundles_item_category_id),
114
+ force_as_service_for_document_external_storage_service: true,
115
+ };
116
+ const bundleResponse = await createBundle(headers, sendBody);
117
+ if (bundleResponse.error) {
118
+ msg = `Ocurrió un error al intentar crear el paquete: ${bundleResponse.userMsg}`;
119
+ console.error(msg);
120
+ throw new Error(msg);
121
+ }
122
+
123
+ return true;
124
+ });
125
+ };
126
+
127
+ /**
128
+ * createNewLabEnsayo
129
+ * @param headers
130
+ * @param session
131
+ * @returns
132
+ */
133
+ export const createNewLabEnsayo = async (
134
+ headers: any,
135
+ session: Session,
136
+ body: Partial<BundleGraphQL>
137
+ ): Promise<AxiosUtilsResponse<boolean>> => {
138
+ return handlePossibleAxiosErrors(async () => {
139
+ let msg = "";
140
+ const {
141
+ lab_bundles_recip_item_category_id,
142
+ lab_services_item_category_id,
143
+ } = await getVariablesByName(headers, session, [
144
+ "lab_bundles_recip_item_category_id",
145
+ "lab_services_item_category_id",
146
+ ]);
147
+
148
+ //PASO 1
149
+ //Creamos el bundle -> Paquete, donde va la receta
150
+ const sendBody: Partial<BundleGraphQL> = {
151
+ ...body,
152
+ item_category_id: Number(lab_bundles_recip_item_category_id),
153
+ name: `${LAB_BUNDLE_NAME}${body.name}`,
154
+ };
155
+ const bundleResponse = await createBundle(headers, sendBody);
156
+ if (bundleResponse.error) {
157
+ msg = `Ocurrió un error al intentar crear el paquete: ${bundleResponse.userMsg}`;
158
+ console.error(msg);
159
+ throw new Error(msg);
160
+ }
161
+
162
+ console.log("-------------- BUNDLE CREADO ! ---------------");
163
+ //PASO 2
164
+ //Creamos el item
165
+ const itemSendBody: Partial<ItemGraphQL> = {
166
+ name: `LAB_SERVICE_${bundleResponse?.data?.id}; ${body.name}`,
167
+ code: `LAB_SERVICE_${bundleResponse?.data?.id}`,
168
+ stockable: false, //Esto lo vuelve servicio
169
+ purchasable: false,
170
+ sellable: true,
171
+ pays_vat: true,
172
+ item_category_id: Number(lab_services_item_category_id),
173
+ description: `Item creado desde la webapp de laboratorio, para representar el servicio del ensayo creado. Ensayo: ${bundleResponse?.data?.id}`,
174
+ };
175
+ const itemResponse = await createNewLaboratoryItem(headers, itemSendBody);
176
+
177
+ if (itemResponse.error) {
178
+ msg = `Ocurrió un error al intentar crear el item asociado al paquete: ${itemResponse.userMsg}`;
179
+ console.error(msg);
180
+ throw new Error(msg);
181
+ }
182
+
183
+ console.log("-------------- ITEM CREADO ! ---------------");
184
+ //PASO 3
185
+ //Creo el formulario
186
+ const formSendBody: Partial<FormGraphQL> = {
187
+ active: true,
188
+ name: `LAB_FORM_${itemResponse?.data?.id}; ${body.name}`,
189
+ description: `Formulario creado desde la webapp, que representa el formulario con las preguntas que se llenan en el ensayo al que hace referencia el mismo. Ensayo: ${itemResponse?.data?.id}`,
190
+ document_type: "invoice",
191
+ settings_form_fields: [
192
+ {
193
+ position: 1,
194
+ name: "Pregunta 1",
195
+ field_type: "text",
196
+ default_value: "",
197
+ print_var_name: "pregunta_1",
198
+ } as any,
199
+ ],
200
+ };
201
+ const formResponse = await createForm(headers, formSendBody);
202
+
203
+ if (formResponse.error) {
204
+ msg = `Ocurrió un error al intentar crear el formulario asociado al paquete: ${formResponse.userMsg}`;
205
+ console.error(msg);
206
+ throw new Error(msg);
207
+ }
208
+
209
+ console.log("-------------- FORM CREADO ! ---------------");
210
+ return true;
211
+ });
212
+ };
213
+
214
+ /**
215
+ * deleteLabBundle
216
+ * @param headers
217
+ * @param session
218
+ * @param bundle
219
+ * @returns
220
+ */
221
+ export const deleteLabBundle = async (
222
+ headers: any,
223
+ session: Session,
224
+ bundle: BundleGraphQL
225
+ ): Promise<AxiosUtilsResponse<boolean>> => {
226
+ return handlePossibleAxiosErrors(async () => {
227
+ await deleteBundle(headers, bundle.id);
228
+
229
+ //busco el item-servicio para eliminarlo
230
+ const responseItem = await getItemByName(
231
+ session,
232
+ `LAB_SERVICE_${bundle.id}; ${bundle.name}`
233
+ );
234
+
235
+ if (responseItem.data && !responseItem.error) {
236
+ await deleteItem(headers, responseItem.data.id);
237
+ }
238
+
239
+ //busco el formulario para eliminarlo
240
+ const responseForm = await getFormByName(
241
+ session,
242
+ `LAB_FORM_${bundle.id}; ${bundle.name}`
243
+ );
244
+
245
+ if (responseForm.data && !responseForm.error) {
246
+ await deleteForm(headers, responseForm.data.id);
247
+ }
248
+
249
+ return true;
250
+ });
251
+ };
@@ -0,0 +1,31 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import { getCasesByResponsibleId } from "@zauru-sdk/services";
4
+ import { AxiosUtilsResponse, CaseGraphQL } from "@zauru-sdk/types";
5
+
6
+ /**
7
+ *
8
+ * @param headers
9
+ * @param session
10
+ * @returns
11
+ */
12
+ export const getMyCases = async (
13
+ session: Session,
14
+ wheres: string[] = []
15
+ ): Promise<AxiosUtilsResponse<CaseGraphQL[]>> => {
16
+ return handlePossibleAxiosErrors(async () => {
17
+ const response = await getCasesByResponsibleId(
18
+ session,
19
+ session.get("employee_id"),
20
+ wheres
21
+ );
22
+
23
+ if (response.error) {
24
+ throw new Error(
25
+ `Ocurrió un error al consultar los casos asignados a este usuario: ${response.userMsg}`
26
+ );
27
+ }
28
+
29
+ return response?.data ?? [];
30
+ });
31
+ };
@@ -0,0 +1,102 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ createWebAppTableRegister,
5
+ getVariablesByName,
6
+ getWebAppTableRegisters,
7
+ updateWebAppTableRegister,
8
+ } from "@zauru-sdk/services";
9
+ import {
10
+ AxiosUtilsResponse,
11
+ WebAppRowGraphQL,
12
+ ConsolidatedHistory,
13
+ WebAppTableUpdateResponse,
14
+ } from "@zauru-sdk/types";
15
+
16
+ /**
17
+ * Get getConsolidatedHistories from the web app table.
18
+ * @param headers Request headers.
19
+ * @param session Session object.
20
+ * @returns A Promise of AxiosUtilsResponse<ConsolidatedHistory[]>.
21
+ */
22
+ export async function getConsolidatedHistories(
23
+ headers: any,
24
+ session: Session
25
+ ): Promise<AxiosUtilsResponse<WebAppRowGraphQL<ConsolidatedHistory>[]>> {
26
+ return handlePossibleAxiosErrors(async () => {
27
+ const { purchase_order_consolidates_web_app_table_id } =
28
+ await getVariablesByName(headers, session, [
29
+ "purchase_order_consolidates_web_app_table_id",
30
+ ]);
31
+
32
+ const response = await getWebAppTableRegisters<ConsolidatedHistory>(
33
+ session,
34
+ purchase_order_consolidates_web_app_table_id
35
+ );
36
+
37
+ if (response.error) {
38
+ throw new Error(
39
+ `Ocurrió un error al consultar el historial de consolidados: ${response.userMsg}`
40
+ );
41
+ }
42
+
43
+ const history = response?.data ?? [];
44
+
45
+ return history;
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Create a template in the web app table.
51
+ * @param headers Request headers.
52
+ * @param session Session object.
53
+ * @param body ConsolidatedHistory data to be created.
54
+ * @returns A Promise of AxiosUtilsResponse<ConsolidatedHistory>.
55
+ */
56
+ export async function createConsolidatedHistory(
57
+ headers: any,
58
+ session: Session,
59
+ body: ConsolidatedHistory
60
+ ): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
61
+ return handlePossibleAxiosErrors(async () => {
62
+ const { purchase_order_consolidates_web_app_table_id } =
63
+ await getVariablesByName(headers, session, [
64
+ "purchase_order_consolidates_web_app_table_id",
65
+ ]);
66
+ const response = await createWebAppTableRegister<ConsolidatedHistory>(
67
+ headers,
68
+ purchase_order_consolidates_web_app_table_id,
69
+ body
70
+ );
71
+ return response;
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Put updateConsolidatedHistory from the web app table.
77
+ * @param headers Request headers.
78
+ * @param session Session object.
79
+ * @returns A Promise of AxiosUtilsResponse<ConsolidatedHistory[]>.
80
+ */
81
+ export async function updateConsolidatedHistory(
82
+ headers: any,
83
+ session: Session,
84
+ body: ConsolidatedHistory,
85
+ id_registro: string | number
86
+ ): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
87
+ return handlePossibleAxiosErrors(async () => {
88
+ const { purchase_order_consolidates_web_app_table_id } =
89
+ await getVariablesByName(headers, session, [
90
+ "purchase_order_consolidates_web_app_table_id",
91
+ ]);
92
+
93
+ const response = await updateWebAppTableRegister<ConsolidatedHistory>(
94
+ headers,
95
+ purchase_order_consolidates_web_app_table_id,
96
+ id_registro,
97
+ { ...body }
98
+ );
99
+
100
+ return response;
101
+ });
102
+ }