washday-sdk 0.0.170 → 0.0.172
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/api/discounts/get.js +4 -4
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +9 -1
- package/dist/utils/orders/calculateTotalTaxesOverPrice.js +9 -1
- package/dist/utils/orders/helpers.js +9 -1
- package/package.json +1 -1
- package/src/api/discounts/get.ts +6 -5
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +8 -1
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +8 -1
- package/src/utils/orders/helpers.ts +8 -1
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
10
11
|
import axiosInstance from "../axiosInstance";
|
|
11
12
|
const GET_SET_DISCOUNT_CODES = 'api/v2/discountCodes';
|
|
12
13
|
const GET_SET_AUTOMATIC_DISCOUNTS = 'api/discounts';
|
|
@@ -33,10 +34,9 @@ export const getDiscountCodes = function (storeId, params) {
|
|
|
33
34
|
export const getAutomaticDiscounts = function (storeId, params) {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
36
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// }
|
|
37
|
+
const queryParams = generateQueryParamsStr([
|
|
38
|
+
'currentDate',
|
|
39
|
+
], params);
|
|
40
40
|
const config = {
|
|
41
41
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
42
42
|
};
|
|
@@ -17,7 +17,15 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
17
17
|
let productPercentageDiscount = 0;
|
|
18
18
|
let customerDiscount = 0;
|
|
19
19
|
if (!order.discountCode) {
|
|
20
|
-
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) =>
|
|
20
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) => {
|
|
21
|
+
if (typeof p === 'string') {
|
|
22
|
+
return p === current._id;
|
|
23
|
+
}
|
|
24
|
+
else if (typeof p === 'object') {
|
|
25
|
+
return p._id === current._id;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}));
|
|
21
29
|
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
22
30
|
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
23
31
|
return next.type === 'percentage' ? prev + next.value : prev;
|
|
@@ -17,7 +17,15 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
|
|
|
17
17
|
const adjustedPrice = productBasePrice + unitExtra;
|
|
18
18
|
// Cálculo de descuento sobre el precio ajustado
|
|
19
19
|
if (!order.discountCode) {
|
|
20
|
-
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) =>
|
|
20
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) => {
|
|
21
|
+
if (typeof p === 'string') {
|
|
22
|
+
return p === current._id;
|
|
23
|
+
}
|
|
24
|
+
else if (typeof p === 'object') {
|
|
25
|
+
return p._id === current._id;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}));
|
|
21
29
|
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
22
30
|
productPercentageDiscount = discountsToApply.reduce((acc, discount) => {
|
|
23
31
|
return discount.type === 'percentage' ? acc + discount.value : acc;
|
|
@@ -64,7 +64,15 @@ export const applyDiscountToProducts = (discountCode, productsArr, isExpress, st
|
|
|
64
64
|
// Caso sin discountCode: se aplican descuentos automáticos solo sobre el precio del producto
|
|
65
65
|
return {
|
|
66
66
|
newOrderProds: productsArr.map((prod) => {
|
|
67
|
-
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) =>
|
|
67
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) => {
|
|
68
|
+
if (typeof p === 'string') {
|
|
69
|
+
return p === prod._id;
|
|
70
|
+
}
|
|
71
|
+
else if (typeof p === 'object') {
|
|
72
|
+
return p._id === prod._id;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}));
|
|
68
76
|
const customerDiscount = (selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.discount) / 100 || 0;
|
|
69
77
|
const productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
70
78
|
if (next.type === 'percentage') {
|
package/package.json
CHANGED
package/src/api/discounts/get.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
2
3
|
import axiosInstance from "../axiosInstance";
|
|
3
4
|
|
|
4
5
|
const GET_SET_DISCOUNT_CODES = 'api/v2/discountCodes';
|
|
@@ -22,12 +23,12 @@ export const getDiscountCodes = async function (this: WashdayClientInstance, sto
|
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
export const getAutomaticDiscounts = async function (this: WashdayClientInstance, storeId: string, params?:
|
|
26
|
+
export const getAutomaticDiscounts = async function (this: WashdayClientInstance, storeId: string, params?: {}): Promise<any> {
|
|
26
27
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const queryParams = generateQueryParamsStr([
|
|
29
|
+
'currentDate',
|
|
30
|
+
], params);
|
|
31
|
+
|
|
31
32
|
const config = {
|
|
32
33
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
33
34
|
};
|
|
@@ -29,7 +29,14 @@ export const calculateTotalTaxesIncluded = (
|
|
|
29
29
|
let customerDiscount = 0;
|
|
30
30
|
if (!order.discountCode) {
|
|
31
31
|
const discountsToApply = storeDiscounts.filter(
|
|
32
|
-
(discount) => discount.isActive && discount.products.some((p: any) =>
|
|
32
|
+
(discount: any) => discount.isActive && discount.products.some((p: any) => {
|
|
33
|
+
if(typeof p === 'string') {
|
|
34
|
+
return p === current._id
|
|
35
|
+
} else if(typeof p === 'object') {
|
|
36
|
+
return p._id === current._id
|
|
37
|
+
}
|
|
38
|
+
return false
|
|
39
|
+
})
|
|
33
40
|
);
|
|
34
41
|
customerDiscount = selectedCustomer?.customer?.discount || 0;
|
|
35
42
|
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
@@ -28,7 +28,14 @@ export const calculateTotalTaxesOverPrice = (
|
|
|
28
28
|
// Cálculo de descuento sobre el precio ajustado
|
|
29
29
|
if (!order.discountCode) {
|
|
30
30
|
const discountsToApply = storeDiscounts.filter(
|
|
31
|
-
(discount: any) => discount.isActive && discount.products.some((p: any) =>
|
|
31
|
+
(discount: any) => discount.isActive && discount.products.some((p: any) => {
|
|
32
|
+
if(typeof p === 'string') {
|
|
33
|
+
return p === current._id
|
|
34
|
+
} else if(typeof p === 'object') {
|
|
35
|
+
return p._id === current._id
|
|
36
|
+
}
|
|
37
|
+
return false
|
|
38
|
+
})
|
|
32
39
|
);
|
|
33
40
|
customerDiscount = selectedCustomer?.customer?.discount || 0;
|
|
34
41
|
productPercentageDiscount = discountsToApply.reduce((acc, discount) => {
|
|
@@ -94,7 +94,14 @@ export const applyDiscountToProducts = (
|
|
|
94
94
|
return {
|
|
95
95
|
newOrderProds: productsArr.map((prod: any) => {
|
|
96
96
|
const discountsToApply = storeDiscounts.filter(
|
|
97
|
-
(discount: any) => discount.isActive && discount.products.some((p: any) =>
|
|
97
|
+
(discount: any) => discount.isActive && discount.products.some((p: any) =>{
|
|
98
|
+
if(typeof p === 'string') {
|
|
99
|
+
return p === prod._id
|
|
100
|
+
} else if(typeof p === 'object') {
|
|
101
|
+
return p._id === prod._id
|
|
102
|
+
}
|
|
103
|
+
return false
|
|
104
|
+
})
|
|
98
105
|
);
|
|
99
106
|
const customerDiscount = selectedCustomer?.discount / 100 || 0;
|
|
100
107
|
const productPercentageDiscount = discountsToApply.reduce((prev: number, next: any) => {
|