@ancon/wildcat-utils 1.50.23 → 1.51.0-check-optimizations.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.
- package/check/getOrganizedCheckItemModifications.d.ts +2 -2
- package/check/getOrganizedCheckItemModifications.js +1 -1
- package/check/getOrganizedCheckItemModifications.mjs +74 -68
- package/check/getUniqueCheckItemModificationId.d.ts +2 -2
- package/check/getUniqueCheckItemModificationId.js +1 -1
- package/check/getUniqueCheckItemModificationId.mjs +5 -5
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckItemV2 } from '@ancon/wildcat-types';
|
|
2
2
|
import { OrganizedCheckItemModification } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Organizes all check item modifications including addon products into a array for easier visual representation.
|
|
@@ -7,4 +7,4 @@ import { OrganizedCheckItemModification } from './types';
|
|
|
7
7
|
* @param addOnProducts - The list of check item add-on products.
|
|
8
8
|
* @returns An array where the modifications are sorted by their modification kind and positions.
|
|
9
9
|
*/
|
|
10
|
-
export default function getOrganizedCheckItemModifications(currency: string, modifications:
|
|
10
|
+
export default function getOrganizedCheckItemModifications(currency: string, modifications: CheckItemV2['modifications'] | undefined, addOnProducts: CheckItemV2['addOnProducts'] | undefined): OrganizedCheckItemModification[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const h=require("@ancon/wildcat-types"),M=require("../toString-b771abdf.js"),P=require("../identity-58f9497d.js"),x=require("../_baseIteratee-374c60ca.js"),k=require("../_getTag-3d3032da.js"),$=require("../isObjectLike-963267e9.js"),O=require("./getUniqueCheckItemModificationId.js");require("../_baseIsEqual-7e335f42.js");require("../isObject-361bd834.js");function L(n){return function(i,r,e){for(var d=-1,t=Object(i),o=e(i),c=o.length;c--;){var a=o[n?c:++d];if(r(t[a],a,t)===!1)break}return i}}var E=L();const _=E;function G(n,i){return n&&_(n,i,k.keys)}function Q(n,i){return function(r,e){if(r==null)return r;if(!k.isArrayLike(r))return n(r,e);for(var d=r.length,t=i?d:-1,o=Object(r);(i?t--:++t<d)&&e(o[t],t,o)!==!1;);return r}}var U=Q(G);const Z=U;function z(n,i){var r=-1,e=k.isArrayLike(n)?Array(n.length):[];return Z(n,function(d,t,o){e[++r]=i(d,t,o)}),e}function V(n,i){var r=n.length;for(n.sort(i);r--;)n[r]=n[r].value;return n}function j(n,i){if(n!==i){var r=n!==void 0,e=n===null,d=n===n,t=M.isSymbol(n),o=i!==void 0,c=i===null,a=i===i,u=M.isSymbol(i);if(!c&&!u&&!t&&n>i||t&&o&&a&&!c&&!u||e&&o&&a||!r&&a||!d)return 1;if(!e&&!t&&!u&&n<i||u&&r&&d&&!e&&!t||c&&r&&d||!o&&d||!a)return-1}return 0}function H(n,i,r){for(var e=-1,d=n.criteria,t=i.criteria,o=d.length,c=r.length;++e<o;){var a=j(d[e],t[e]);if(a){if(e>=c)return a;var u=r[e];return a*(u=="desc"?-1:1)}}return n.index-i.index}function J(n,i,r){i.length?i=M.arrayMap(i,function(t){return $.isArray(t)?function(o){return P.baseGet(o,t.length===1?t[0]:t)}:t}):i=[P.identity];var e=-1;i=M.arrayMap(i,k.baseUnary(x.baseIteratee));var d=z(n,function(t,o,c){var a=M.arrayMap(i,function(u){return u(t)});return{criteria:a,index:++e,value:t}});return V(d,function(t,o){return H(t,o,r)})}function C(n,i,r,e){return n==null?[]:($.isArray(i)||(i=i==null?[]:[i]),r=e?void 0:r,$.isArray(r)||(r=r==null?[]:[r]),J(n,i,r))}function K(n,i,r){const{add:e,replace:d,remove:t}=i.reduce((a,u)=>{const{modification:A,position:s,freeAmount:f,name:y,quantity:p,cost:g,replacementName:T}=u,m=g===0;if(u.modification===h.ModificationType.Add){(f>0||m)&&a.add.push({id:O(u,"-free"),modificationType:A,name:y,freeAmount:m?p:f,quantity:m?p:f,currency:n,position:s,cost:0});const q=p-f;q>0&&!m&&a.add.push({id:O(u),modificationType:A,name:y,quantity:q,freeAmount:0,currency:n,position:s,cost:g*q})}return u.modification===h.ModificationType.Replace&&a.replace.push({id:O(u),modificationType:A,name:y,replacementName:T,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),u.modification===h.ModificationType.Remove&&a.remove.push({id:O(u),modificationType:A,name:y,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),a},{add:[],replace:[],remove:[]}),o=(r
|
|
1
|
+
"use strict";const h=require("@ancon/wildcat-types"),M=require("../toString-b771abdf.js"),P=require("../identity-58f9497d.js"),x=require("../_baseIteratee-374c60ca.js"),k=require("../_getTag-3d3032da.js"),$=require("../isObjectLike-963267e9.js"),O=require("./getUniqueCheckItemModificationId.js");require("../_baseIsEqual-7e335f42.js");require("../isObject-361bd834.js");function L(n){return function(i,r,e){for(var d=-1,t=Object(i),o=e(i),c=o.length;c--;){var a=o[n?c:++d];if(r(t[a],a,t)===!1)break}return i}}var E=L();const _=E;function G(n,i){return n&&_(n,i,k.keys)}function Q(n,i){return function(r,e){if(r==null)return r;if(!k.isArrayLike(r))return n(r,e);for(var d=r.length,t=i?d:-1,o=Object(r);(i?t--:++t<d)&&e(o[t],t,o)!==!1;);return r}}var U=Q(G);const Z=U;function z(n,i){var r=-1,e=k.isArrayLike(n)?Array(n.length):[];return Z(n,function(d,t,o){e[++r]=i(d,t,o)}),e}function V(n,i){var r=n.length;for(n.sort(i);r--;)n[r]=n[r].value;return n}function j(n,i){if(n!==i){var r=n!==void 0,e=n===null,d=n===n,t=M.isSymbol(n),o=i!==void 0,c=i===null,a=i===i,u=M.isSymbol(i);if(!c&&!u&&!t&&n>i||t&&o&&a&&!c&&!u||e&&o&&a||!r&&a||!d)return 1;if(!e&&!t&&!u&&n<i||u&&r&&d&&!e&&!t||c&&r&&d||!o&&d||!a)return-1}return 0}function H(n,i,r){for(var e=-1,d=n.criteria,t=i.criteria,o=d.length,c=r.length;++e<o;){var a=j(d[e],t[e]);if(a){if(e>=c)return a;var u=r[e];return a*(u=="desc"?-1:1)}}return n.index-i.index}function J(n,i,r){i.length?i=M.arrayMap(i,function(t){return $.isArray(t)?function(o){return P.baseGet(o,t.length===1?t[0]:t)}:t}):i=[P.identity];var e=-1;i=M.arrayMap(i,k.baseUnary(x.baseIteratee));var d=z(n,function(t,o,c){var a=M.arrayMap(i,function(u){return u(t)});return{criteria:a,index:++e,value:t}});return V(d,function(t,o){return H(t,o,r)})}function C(n,i,r,e){return n==null?[]:($.isArray(i)||(i=i==null?[]:[i]),r=e?void 0:r,$.isArray(r)||(r=r==null?[]:[r]),J(n,i,r))}function K(n,i,r){const{add:e,replace:d,remove:t}=(i??[]).reduce((a,u)=>{const{modification:A,position:s,freeAmount:f,name:y="",quantity:p,cost:g,replacementName:T}=u,m=g===0;if(u.modification===h.ModificationType.Add){(f>0||m)&&a.add.push({id:O(u,"-free"),modificationType:A,name:y,freeAmount:m?p:f,quantity:m?p:f,currency:n,position:s,cost:0});const q=p-f;q>0&&!m&&a.add.push({id:O(u),modificationType:A,name:y,quantity:q,freeAmount:0,currency:n,position:s,cost:g*q})}return u.modification===h.ModificationType.Replace&&a.replace.push({id:O(u),modificationType:A,name:y,replacementName:T,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),u.modification===h.ModificationType.Remove&&a.remove.push({id:O(u),modificationType:A,name:y,freeAmount:f,quantity:p,currency:n,position:s,cost:g}),a},{add:[],replace:[],remove:[]}),o=(r??[]).reduce((a,u)=>{const{product:A,freeAmount:s=0,quantity:f,position:y,addOnGroupId:p,productPriceInclTax:g}=u,{hasVariants:T,variantName:m="",productName:q="",productId:B,variantId:F}=A??{},b=g.unitPrice===0;(s>0||b)&&a.push({id:`${p}-${B}-free`,modificationType:h.ModificationType.Add,name:T?m:q,freeAmount:b?f:s,quantity:b?f:s,currency:n,position:y,cost:0,variantId:F});const w=f-s;return w>0&&!b&&a.push({id:`${p}-${B}`,modificationType:h.ModificationType.Add,name:T?m:q,freeAmount:0,quantity:w,currency:n,position:y,cost:g.unitPrice*w,variantId:F}),a},[]);return[...C([...e,...o],["position"],["asc"]),...C(d,["position"],["asc"]),...C(t,["position"],["asc"])]}module.exports=K;
|
|
@@ -8,10 +8,10 @@ import T from "./getUniqueCheckItemModificationId.mjs";
|
|
|
8
8
|
import "../_baseIsEqual-4ee44a4c.mjs";
|
|
9
9
|
import "../isObject-b8638513.mjs";
|
|
10
10
|
function U(n) {
|
|
11
|
-
return function(i, t,
|
|
12
|
-
for (var
|
|
13
|
-
var
|
|
14
|
-
if (t(r[
|
|
11
|
+
return function(i, t, o) {
|
|
12
|
+
for (var d = -1, r = Object(i), u = o(i), f = u.length; f--; ) {
|
|
13
|
+
var a = u[n ? f : ++d];
|
|
14
|
+
if (t(r[a], a, r) === !1)
|
|
15
15
|
break;
|
|
16
16
|
}
|
|
17
17
|
return i;
|
|
@@ -23,12 +23,12 @@ function V(n, i) {
|
|
|
23
23
|
return n && z(n, i, L);
|
|
24
24
|
}
|
|
25
25
|
function H(n, i) {
|
|
26
|
-
return function(t,
|
|
26
|
+
return function(t, o) {
|
|
27
27
|
if (t == null)
|
|
28
28
|
return t;
|
|
29
29
|
if (!P(t))
|
|
30
|
-
return n(t,
|
|
31
|
-
for (var
|
|
30
|
+
return n(t, o);
|
|
31
|
+
for (var d = t.length, r = i ? d : -1, u = Object(t); (i ? r-- : ++r < d) && o(u[r], r, u) !== !1; )
|
|
32
32
|
;
|
|
33
33
|
return t;
|
|
34
34
|
};
|
|
@@ -36,10 +36,10 @@ function H(n, i) {
|
|
|
36
36
|
var J = H(V);
|
|
37
37
|
const K = J;
|
|
38
38
|
function W(n, i) {
|
|
39
|
-
var t = -1,
|
|
40
|
-
return K(n, function(
|
|
41
|
-
|
|
42
|
-
}),
|
|
39
|
+
var t = -1, o = P(n) ? Array(n.length) : [];
|
|
40
|
+
return K(n, function(d, r, u) {
|
|
41
|
+
o[++t] = i(d, r, u);
|
|
42
|
+
}), o;
|
|
43
43
|
}
|
|
44
44
|
function X(n, i) {
|
|
45
45
|
var t = n.length;
|
|
@@ -49,22 +49,22 @@ function X(n, i) {
|
|
|
49
49
|
}
|
|
50
50
|
function Y(n, i) {
|
|
51
51
|
if (n !== i) {
|
|
52
|
-
var t = n !== void 0,
|
|
53
|
-
if (!f && !
|
|
52
|
+
var t = n !== void 0, o = n === null, d = n === n, r = F(n), u = i !== void 0, f = i === null, a = i === i, e = F(i);
|
|
53
|
+
if (!f && !e && !r && n > i || r && u && a && !f && !e || o && u && a || !t && a || !d)
|
|
54
54
|
return 1;
|
|
55
|
-
if (!
|
|
55
|
+
if (!o && !r && !e && n < i || e && t && d && !o && !r || f && t && d || !u && d || !a)
|
|
56
56
|
return -1;
|
|
57
57
|
}
|
|
58
58
|
return 0;
|
|
59
59
|
}
|
|
60
60
|
function _(n, i, t) {
|
|
61
|
-
for (var
|
|
62
|
-
var
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
return
|
|
66
|
-
var
|
|
67
|
-
return
|
|
61
|
+
for (var o = -1, d = n.criteria, r = i.criteria, u = d.length, f = t.length; ++o < u; ) {
|
|
62
|
+
var a = Y(d[o], r[o]);
|
|
63
|
+
if (a) {
|
|
64
|
+
if (o >= f)
|
|
65
|
+
return a;
|
|
66
|
+
var e = t[o];
|
|
67
|
+
return a * (e == "desc" ? -1 : 1);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return n.index - i.index;
|
|
@@ -75,104 +75,110 @@ function j(n, i, t) {
|
|
|
75
75
|
return E(u, r.length === 1 ? r[0] : r);
|
|
76
76
|
} : r;
|
|
77
77
|
}) : i = [x];
|
|
78
|
-
var
|
|
78
|
+
var o = -1;
|
|
79
79
|
i = q(i, Q(G));
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
return
|
|
80
|
+
var d = W(n, function(r, u, f) {
|
|
81
|
+
var a = q(i, function(e) {
|
|
82
|
+
return e(r);
|
|
83
83
|
});
|
|
84
|
-
return { criteria:
|
|
84
|
+
return { criteria: a, index: ++o, value: r };
|
|
85
85
|
});
|
|
86
|
-
return X(
|
|
86
|
+
return X(d, function(r, u) {
|
|
87
87
|
return _(r, u, t);
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function C(n, i, t,
|
|
91
|
-
return n == null ? [] : ($(i) || (i = i == null ? [] : [i]), t =
|
|
90
|
+
function C(n, i, t, o) {
|
|
91
|
+
return n == null ? [] : ($(i) || (i = i == null ? [] : [i]), t = o ? void 0 : t, $(t) || (t = t == null ? [] : [t]), j(n, i, t));
|
|
92
92
|
}
|
|
93
93
|
function rn(n, i, t) {
|
|
94
|
-
const { add:
|
|
95
|
-
(
|
|
94
|
+
const { add: o, replace: d, remove: r } = (i ?? []).reduce(
|
|
95
|
+
(a, e) => {
|
|
96
96
|
const {
|
|
97
97
|
modification: h,
|
|
98
|
-
position:
|
|
99
|
-
freeAmount:
|
|
100
|
-
name: m,
|
|
98
|
+
position: c,
|
|
99
|
+
freeAmount: p,
|
|
100
|
+
name: m = "",
|
|
101
101
|
quantity: s,
|
|
102
102
|
cost: g,
|
|
103
103
|
replacementName: O
|
|
104
|
-
} =
|
|
105
|
-
if (
|
|
106
|
-
(
|
|
107
|
-
id: T(
|
|
104
|
+
} = e, A = g === 0;
|
|
105
|
+
if (e.modification === y.Add) {
|
|
106
|
+
(p > 0 || A) && a.add.push({
|
|
107
|
+
id: T(e, "-free"),
|
|
108
108
|
modificationType: h,
|
|
109
109
|
name: m,
|
|
110
|
-
freeAmount: A ? s :
|
|
111
|
-
quantity: A ? s :
|
|
110
|
+
freeAmount: A ? s : p,
|
|
111
|
+
quantity: A ? s : p,
|
|
112
112
|
currency: n,
|
|
113
|
-
position:
|
|
113
|
+
position: c,
|
|
114
114
|
cost: 0
|
|
115
115
|
});
|
|
116
|
-
const b = s -
|
|
117
|
-
b > 0 && !A &&
|
|
118
|
-
id: T(
|
|
116
|
+
const b = s - p;
|
|
117
|
+
b > 0 && !A && a.add.push({
|
|
118
|
+
id: T(e),
|
|
119
119
|
modificationType: h,
|
|
120
120
|
name: m,
|
|
121
121
|
quantity: b,
|
|
122
122
|
freeAmount: 0,
|
|
123
123
|
currency: n,
|
|
124
|
-
position:
|
|
124
|
+
position: c,
|
|
125
125
|
cost: g * b
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
return
|
|
129
|
-
id: T(
|
|
128
|
+
return e.modification === y.Replace && a.replace.push({
|
|
129
|
+
id: T(e),
|
|
130
130
|
modificationType: h,
|
|
131
131
|
name: m,
|
|
132
132
|
replacementName: O,
|
|
133
|
-
freeAmount:
|
|
133
|
+
freeAmount: p,
|
|
134
134
|
quantity: s,
|
|
135
135
|
currency: n,
|
|
136
|
-
position:
|
|
136
|
+
position: c,
|
|
137
137
|
cost: g
|
|
138
|
-
}),
|
|
139
|
-
id: T(
|
|
138
|
+
}), e.modification === y.Remove && a.remove.push({
|
|
139
|
+
id: T(e),
|
|
140
140
|
modificationType: h,
|
|
141
141
|
name: m,
|
|
142
|
-
freeAmount:
|
|
142
|
+
freeAmount: p,
|
|
143
143
|
quantity: s,
|
|
144
144
|
currency: n,
|
|
145
|
-
position:
|
|
145
|
+
position: c,
|
|
146
146
|
cost: g
|
|
147
|
-
}),
|
|
147
|
+
}), a;
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
add: [],
|
|
151
151
|
replace: [],
|
|
152
152
|
remove: []
|
|
153
153
|
}
|
|
154
|
-
), u = (t
|
|
154
|
+
), u = (t ?? []).reduce((a, e) => {
|
|
155
155
|
const {
|
|
156
156
|
product: h,
|
|
157
|
-
|
|
158
|
-
quantity:
|
|
159
|
-
|
|
157
|
+
freeAmount: c = 0,
|
|
158
|
+
quantity: p,
|
|
159
|
+
position: m,
|
|
160
160
|
addOnGroupId: s,
|
|
161
161
|
productPriceInclTax: g
|
|
162
|
-
} =
|
|
163
|
-
|
|
162
|
+
} = e, {
|
|
163
|
+
hasVariants: O,
|
|
164
|
+
variantName: A = "",
|
|
165
|
+
productName: b = "",
|
|
166
|
+
productId: w,
|
|
167
|
+
variantId: B
|
|
168
|
+
} = h ?? {}, M = g.unitPrice === 0;
|
|
169
|
+
(c > 0 || M) && a.push({
|
|
164
170
|
id: `${s}-${w}-free`,
|
|
165
171
|
modificationType: y.Add,
|
|
166
172
|
name: O ? A : b,
|
|
167
|
-
freeAmount: M ?
|
|
168
|
-
quantity: M ?
|
|
173
|
+
freeAmount: M ? p : c,
|
|
174
|
+
quantity: M ? p : c,
|
|
169
175
|
currency: n,
|
|
170
176
|
position: m,
|
|
171
177
|
cost: 0,
|
|
172
178
|
variantId: B
|
|
173
179
|
});
|
|
174
|
-
const k =
|
|
175
|
-
return k > 0 && !M &&
|
|
180
|
+
const k = p - c;
|
|
181
|
+
return k > 0 && !M && a.push({
|
|
176
182
|
id: `${s}-${w}`,
|
|
177
183
|
modificationType: y.Add,
|
|
178
184
|
name: O ? A : b,
|
|
@@ -180,13 +186,13 @@ function rn(n, i, t) {
|
|
|
180
186
|
quantity: k,
|
|
181
187
|
currency: n,
|
|
182
188
|
position: m,
|
|
183
|
-
cost: g.unitPrice
|
|
189
|
+
cost: g.unitPrice * k,
|
|
184
190
|
variantId: B
|
|
185
|
-
}),
|
|
191
|
+
}), a;
|
|
186
192
|
}, []);
|
|
187
193
|
return [
|
|
188
|
-
...C([...
|
|
189
|
-
...C(
|
|
194
|
+
...C([...o, ...u], ["position"], ["asc"]),
|
|
195
|
+
...C(d, ["position"], ["asc"]),
|
|
190
196
|
...C(r, ["position"], ["asc"])
|
|
191
197
|
];
|
|
192
198
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckItemModificationV2 } from '@ancon/wildcat-types';
|
|
2
2
|
/**
|
|
3
3
|
* Generate a unique ID for a Check Item Modification
|
|
4
4
|
* @param modification - Check Item Modification
|
|
5
5
|
* @param suffix - Optional suffix to append to the ID
|
|
6
6
|
* @returns Unique ID string
|
|
7
7
|
*/
|
|
8
|
-
export default function getUniqueCheckItemModificationId(modification:
|
|
8
|
+
export default function getUniqueCheckItemModificationId(modification: CheckItemModificationV2, suffix?: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function p(n,e){const{modification:i,ingredientId:o,replaceId:$,addOnGroupId:c,quantity:d,cost:a,freeAmount:r,name:t="",replacementName:m,position:u}=n;return`modification-${i}-${o}-${$??0}-${c??null}-${d}-${a}-${r}-${t}-${m??t}-${u}${e?`-${e}`:""}`}module.exports=p;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function p(n, e) {
|
|
2
2
|
const {
|
|
3
3
|
modification: i,
|
|
4
4
|
ingredientId: o,
|
|
@@ -7,12 +7,12 @@ function u(n, e) {
|
|
|
7
7
|
quantity: d,
|
|
8
8
|
cost: c,
|
|
9
9
|
freeAmount: r,
|
|
10
|
-
name: t,
|
|
10
|
+
name: t = "",
|
|
11
11
|
replacementName: m,
|
|
12
|
-
position:
|
|
12
|
+
position: u
|
|
13
13
|
} = n;
|
|
14
|
-
return `modification-${i}-${o}-${$ ?? 0}-${a}-${d}-${c}-${r}-${t}-${m ?? t}-${
|
|
14
|
+
return `modification-${i}-${o}-${$ ?? 0}-${a ?? null}-${d}-${c}-${r}-${t}-${m ?? t}-${u}${e ? `-${e}` : ""}`;
|
|
15
15
|
}
|
|
16
16
|
export {
|
|
17
|
-
|
|
17
|
+
p as default
|
|
18
18
|
};
|