@zauru-sdk/utils 6.30.1 → 6.30.2
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.
|
@@ -103,10 +103,41 @@ export const filterActiveSpecialItems = (specialItems) => (specialItems ?? [])
|
|
|
103
103
|
.filter(isSpecialItemRow)
|
|
104
104
|
.filter((row) => !row.data?.fechaEliminacion)
|
|
105
105
|
.sort((a, b) => a.id - b.id);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
const normalizeOptionalSpecialValue = (value) => {
|
|
107
|
+
const normalized = normalizeComparableValue(value);
|
|
108
|
+
return normalized === "0" ? "" : normalized;
|
|
109
|
+
};
|
|
110
|
+
const optionalSpecialValueMatches = (configured, actual) => {
|
|
111
|
+
const expected = normalizeOptionalSpecialValue(configured);
|
|
112
|
+
return !expected || expected === normalizeOptionalSpecialValue(actual);
|
|
113
|
+
};
|
|
114
|
+
const specialItemSpecificity = (specialItem) => [
|
|
115
|
+
specialItem.provider,
|
|
116
|
+
specialItem.region,
|
|
117
|
+
specialItem.tipo,
|
|
118
|
+
specialItem.providerCategory,
|
|
119
|
+
].filter((value) => normalizeOptionalSpecialValue(value)).length;
|
|
120
|
+
export const matchSpecialItemForWeeklyPrice = (specialItems, params) => {
|
|
121
|
+
let bestMatch;
|
|
122
|
+
let bestSpecificity = -1;
|
|
123
|
+
for (const specialItem of filterActiveSpecialItems(specialItems)) {
|
|
124
|
+
const data = specialItem.data;
|
|
125
|
+
const matches = Number(data.item) === Number(params.itemId) &&
|
|
126
|
+
optionalSpecialValueMatches(data.provider, params.providerId) &&
|
|
127
|
+
optionalSpecialValueMatches(data.region, params.region) &&
|
|
128
|
+
optionalSpecialValueMatches(data.tipo, params.tipo) &&
|
|
129
|
+
optionalSpecialValueMatches(data.providerCategory, params.providerCategoryId);
|
|
130
|
+
if (!matches) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const specificity = specialItemSpecificity(data);
|
|
134
|
+
if (specificity > bestSpecificity) {
|
|
135
|
+
bestMatch = specialItem;
|
|
136
|
+
bestSpecificity = specificity;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return bestMatch;
|
|
140
|
+
};
|
|
110
141
|
export const pickLatestMassiveCostBitacora = (rows, date) => {
|
|
111
142
|
const masivas = (rows ?? [])
|
|
112
143
|
.filter((row) => row.data?.accion === MASSIVE_VEGETABLE_COST_ACCION)
|
|
@@ -136,6 +167,8 @@ export const calculateItemPriceFromWeeklyMatrix = (input) => {
|
|
|
136
167
|
itemId: input.itemId,
|
|
137
168
|
region: input.region,
|
|
138
169
|
tipo: input.tipo,
|
|
170
|
+
providerId: input.providerId,
|
|
171
|
+
providerCategoryId: input.providerCategoryId,
|
|
139
172
|
});
|
|
140
173
|
let source = "fallback";
|
|
141
174
|
let basePrice = FALLBACK_UNIT_COST;
|
|
@@ -219,6 +252,7 @@ export const resolveItemPriceFromLatestWeeklyMatrix = (headers, session, params)
|
|
|
219
252
|
date: params.date,
|
|
220
253
|
region: params.region,
|
|
221
254
|
tipo: params.tipo,
|
|
255
|
+
providerId: params.payeeId,
|
|
222
256
|
providerCategoryId,
|
|
223
257
|
matrix: matrixResponse.data,
|
|
224
258
|
specialItems: specialItemsResponse.data ?? [],
|
|
@@ -17,6 +17,8 @@ export declare const matchSpecialItemForWeeklyPrice: (specialItems: Array<Specia
|
|
|
17
17
|
itemId: number;
|
|
18
18
|
region?: string;
|
|
19
19
|
tipo?: string;
|
|
20
|
+
providerId?: number;
|
|
21
|
+
providerCategoryId?: number;
|
|
20
22
|
}) => WebAppRowGraphQL<SpecialItem> | undefined;
|
|
21
23
|
export declare const pickLatestMassiveCostBitacora: (rows: WebAppRowGraphQL<BitacoraCostosItems>[] | undefined, date?: string) => WebAppRowGraphQL<BitacoraCostosItems> | undefined;
|
|
22
24
|
export declare const calculateItemPriceFromWeeklyMatrix: (input: CalculateItemPriceFromWeeklyMatrixInput) => CalculateItemPriceFromWeeklyMatrixResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "6.30.
|
|
3
|
+
"version": "6.30.2",
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "npm run build:esm",
|
|
42
42
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
43
|
-
"test": "
|
|
43
|
+
"test": "pnpm --dir ../common exec tsx --test ../utils/src/zauru/*.test.ts"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"@zauru-sdk/config": "^6.0.0",
|
|
76
76
|
"@zauru-sdk/graphql": "^6.9.1",
|
|
77
77
|
"@zauru-sdk/services": "^6.18.0",
|
|
78
|
-
"@zauru-sdk/types": "^6.30.
|
|
78
|
+
"@zauru-sdk/types": "^6.30.1",
|
|
79
79
|
"moment": "^2.30.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "07c7b4434055c88b7d12f452a04e83b67ddeea61"
|
|
82
82
|
}
|