@zauru-sdk/utils 6.24.1 → 6.25.0
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/esm/index.js
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { checkProviderRestrictionValue, handlePossibleAxiosErrors, matchReceptionTypeCode, normalizeProviderRestrictionValues, PROVIDER_ITEM_RESTRICTIONS_TABLE_VAR, PROVIDER_TYPE_RESTRICTIONS_TABLE_VAR, } from "@zauru-sdk/common";
|
|
2
|
+
import { createWebAppTableRegister, getVariablesByName, getWebAppTableRegisters, updateWebAppTableRegister, } from "@zauru-sdk/services";
|
|
3
|
+
const toRule = (row) => ({
|
|
4
|
+
...row.data,
|
|
5
|
+
payee_id: Number(row.data?.payee_id),
|
|
6
|
+
values: normalizeProviderRestrictionValues(row.data?.values),
|
|
7
|
+
});
|
|
8
|
+
export const mapProviderRestrictionRows = (rows) => (rows ?? []).map(toRule);
|
|
9
|
+
const getTableId = async (headers, session, varName) => {
|
|
10
|
+
const vars = await getVariablesByName(headers, session, [varName]);
|
|
11
|
+
return vars[varName];
|
|
12
|
+
};
|
|
13
|
+
const getRules = (headers, session, varName, label) => handlePossibleAxiosErrors(async () => {
|
|
14
|
+
const tableId = await getTableId(headers, session, varName);
|
|
15
|
+
const response = await getWebAppTableRegisters(session, tableId);
|
|
16
|
+
if (response.error) {
|
|
17
|
+
throw new Error(`Ocurrió un error al consultar ${label}: ${response.userMsg}`);
|
|
18
|
+
}
|
|
19
|
+
return response.data ?? [];
|
|
20
|
+
});
|
|
21
|
+
const createRule = (headers, session, varName, body) => handlePossibleAxiosErrors(async () => {
|
|
22
|
+
const tableId = await getTableId(headers, session, varName);
|
|
23
|
+
return createWebAppTableRegister(headers, tableId, body);
|
|
24
|
+
});
|
|
25
|
+
const updateRule = (headers, session, varName, id, body) => handlePossibleAxiosErrors(async () => {
|
|
26
|
+
const tableId = await getTableId(headers, session, varName);
|
|
27
|
+
return updateWebAppTableRegister(headers, tableId, id, body);
|
|
28
|
+
});
|
|
29
|
+
export const getProviderTypeRestrictions = (headers, session) => getRules(headers, session, PROVIDER_TYPE_RESTRICTIONS_TABLE_VAR, "las restricciones de tipos por proveedor");
|
|
30
|
+
export const createProviderTypeRestriction = (headers, session, body) => createRule(headers, session, PROVIDER_TYPE_RESTRICTIONS_TABLE_VAR, body);
|
|
31
|
+
export const updateProviderTypeRestriction = (headers, session, id, body) => updateRule(headers, session, PROVIDER_TYPE_RESTRICTIONS_TABLE_VAR, id, body);
|
|
32
|
+
export const getProviderItemRestrictions = (headers, session) => getRules(headers, session, PROVIDER_ITEM_RESTRICTIONS_TABLE_VAR, "las restricciones de verduras por proveedor");
|
|
33
|
+
export const createProviderItemRestriction = (headers, session, body) => createRule(headers, session, PROVIDER_ITEM_RESTRICTIONS_TABLE_VAR, body);
|
|
34
|
+
export const updateProviderItemRestriction = (headers, session, id, body) => updateRule(headers, session, PROVIDER_ITEM_RESTRICTIONS_TABLE_VAR, id, body);
|
|
35
|
+
const receptionTypeFromRow = (entry) => {
|
|
36
|
+
if (entry && typeof entry === "object" && "data" in entry) {
|
|
37
|
+
return entry.data;
|
|
38
|
+
}
|
|
39
|
+
return entry;
|
|
40
|
+
};
|
|
41
|
+
export const evaluateProviderReceptionRestrictions = (input) => {
|
|
42
|
+
const typeRules = mapProviderRestrictionRows(input.typeRules);
|
|
43
|
+
const itemRules = mapProviderRestrictionRows(input.itemRules);
|
|
44
|
+
const receptionTypes = (input.receptionTypes ?? [])
|
|
45
|
+
.map(receptionTypeFromRow)
|
|
46
|
+
.filter((type) => Boolean(type));
|
|
47
|
+
const typeUniverse = receptionTypes
|
|
48
|
+
.map((type) => String(type.Codigo ?? "").trim())
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
if (input.typeValue) {
|
|
51
|
+
const code = matchReceptionTypeCode(input.typeValue, receptionTypes);
|
|
52
|
+
const typeCheck = checkProviderRestrictionValue({
|
|
53
|
+
payeeId: input.payeeId,
|
|
54
|
+
date: input.date,
|
|
55
|
+
value: code,
|
|
56
|
+
valueLabel: input.typeLabel || input.typeValue,
|
|
57
|
+
label: "Tipo",
|
|
58
|
+
rules: typeRules,
|
|
59
|
+
universe: typeUniverse,
|
|
60
|
+
});
|
|
61
|
+
if (!typeCheck.allowed) {
|
|
62
|
+
return typeCheck;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (input.itemId != null && Number(input.itemId) > 0) {
|
|
66
|
+
const itemCheck = checkProviderRestrictionValue({
|
|
67
|
+
payeeId: input.payeeId,
|
|
68
|
+
date: input.date,
|
|
69
|
+
value: Number(input.itemId),
|
|
70
|
+
valueLabel: input.itemLabel || String(input.itemId),
|
|
71
|
+
label: "Verdura",
|
|
72
|
+
rules: itemRules,
|
|
73
|
+
universe: input.itemIds ?? [],
|
|
74
|
+
});
|
|
75
|
+
if (!itemCheck.allowed) {
|
|
76
|
+
return itemCheck;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { allowed: true };
|
|
80
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import type { AxiosUtilsResponse, ProviderRestrictionCheckResult, ProviderRestrictionRule, ReceptionType, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
3
|
+
export declare const mapProviderRestrictionRows: (rows?: WebAppRowGraphQL<ProviderRestrictionRule>[]) => ProviderRestrictionRule[];
|
|
4
|
+
export declare const getProviderTypeRestrictions: (headers: any, session: Session) => Promise<AxiosUtilsResponse<WebAppRowGraphQL<ProviderRestrictionRule>[]>>;
|
|
5
|
+
export declare const createProviderTypeRestriction: (headers: any, session: Session, body: ProviderRestrictionRule) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
6
|
+
export declare const updateProviderTypeRestriction: (headers: any, session: Session, id: number, body: Partial<ProviderRestrictionRule>) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
7
|
+
export declare const getProviderItemRestrictions: (headers: any, session: Session) => Promise<AxiosUtilsResponse<WebAppRowGraphQL<ProviderRestrictionRule>[]>>;
|
|
8
|
+
export declare const createProviderItemRestriction: (headers: any, session: Session, body: ProviderRestrictionRule) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
9
|
+
export declare const updateProviderItemRestriction: (headers: any, session: Session, id: number, body: Partial<ProviderRestrictionRule>) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
10
|
+
export declare const evaluateProviderReceptionRestrictions: (input: {
|
|
11
|
+
payeeId: number;
|
|
12
|
+
date: string;
|
|
13
|
+
typeValue?: string;
|
|
14
|
+
itemId?: number;
|
|
15
|
+
typeRules?: WebAppRowGraphQL<ProviderRestrictionRule>[];
|
|
16
|
+
itemRules?: WebAppRowGraphQL<ProviderRestrictionRule>[];
|
|
17
|
+
receptionTypes?: Array<WebAppRowGraphQL<ReceptionType> | ReceptionType>;
|
|
18
|
+
itemIds?: Array<string | number>;
|
|
19
|
+
typeLabel?: string;
|
|
20
|
+
itemLabel?: string;
|
|
21
|
+
}) => ProviderRestrictionCheckResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.25.0",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@aws-sdk/client-cloudwatch-logs": "^3.1123.0",
|
|
73
73
|
"@remix-run/node": "^2.8.1",
|
|
74
|
-
"@zauru-sdk/common": "^6.
|
|
74
|
+
"@zauru-sdk/common": "^6.11.0",
|
|
75
75
|
"@zauru-sdk/config": "^6.0.0",
|
|
76
76
|
"@zauru-sdk/graphql": "^6.9.0",
|
|
77
|
-
"@zauru-sdk/services": "^6.
|
|
78
|
-
"@zauru-sdk/types": "^6.
|
|
77
|
+
"@zauru-sdk/services": "^6.15.0",
|
|
78
|
+
"@zauru-sdk/types": "^6.27.0",
|
|
79
79
|
"moment": "^2.30.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "d8141f1d30edee6edb8d2777d0e12e2f4f1b2726"
|
|
82
82
|
}
|