washday-sdk 0.0.171 → 0.0.173

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.
@@ -1,8 +1,8 @@
1
1
  import axios from 'axios';
2
2
  // Define the type for the Axios instance
3
3
  let axiosInstance = null;
4
- // const BASE_URL: string = 'http://localhost:5555/';
5
- const BASE_URL = 'https://washday-backend.herokuapp.com/';
4
+ const BASE_URL = 'http://localhost:5555/';
5
+ // const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
6
6
  // Function to create or return the singleton instance
7
7
  const getAxiosInstance = () => {
8
8
  if (!axiosInstance) {
@@ -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
- let queryParams = '';
37
- // if (params.isActive) {
38
- // queryParams += `isActive=${params.isActive}`
39
- // }
37
+ const queryParams = generateQueryParamsStr([
38
+ 'currentDate',
39
+ ], params);
40
40
  const config = {
41
41
  headers: { Authorization: `Bearer ${this.apiToken}` }
42
42
  };
@@ -48,6 +48,9 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
48
48
  if (discountType === 'percentage' && current.isBuyAndGetProduct) {
49
49
  discPercentageInteger = +(discountValue / 100).toFixed(2);
50
50
  }
51
+ if (discountType === 'free' && current.isBuyAndGetProduct) {
52
+ discPercentageInteger = 1;
53
+ }
51
54
  }
52
55
  }
53
56
  // === NUEVO: Aplicar descuento sobre el precio total ajustado (producto base + extra prorrateado) ===
@@ -47,6 +47,9 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
47
47
  if (condition.getDiscountType === BuyAndGetConditionsTypes.PERCENTAGE && current.isBuyAndGetProduct) {
48
48
  discPercentageInteger = +(condition.discountValue / 100).toFixed(2);
49
49
  }
50
+ if (condition.getDiscountType === BuyAndGetConditionsTypes.FREE && current.isBuyAndGetProduct) {
51
+ discPercentageInteger = 1;
52
+ }
50
53
  }
51
54
  }
52
55
  // Calcular el descuento por unidad sobre el precio ajustado
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "0.0.171",
3
+ "version": "0.0.173",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -3,8 +3,8 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
3
3
  // Define the type for the Axios instance
4
4
  let axiosInstance: AxiosInstance | null = null;
5
5
 
6
- // const BASE_URL: string = 'http://localhost:5555/';
7
- const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
6
+ const BASE_URL: string = 'http://localhost:5555/';
7
+ // const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
8
8
 
9
9
  // Function to create or return the singleton instance
10
10
  const getAxiosInstance = (): AxiosInstance => {
@@ -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?: string): Promise<any> {
26
+ export const getAutomaticDiscounts = async function (this: WashdayClientInstance, storeId: string, params?: {}): Promise<any> {
26
27
  try {
27
- let queryParams = '';
28
- // if (params.isActive) {
29
- // queryParams += `isActive=${params.isActive}`
30
- // }
28
+ const queryParams = generateQueryParamsStr([
29
+ 'currentDate',
30
+ ], params);
31
+
31
32
  const config = {
32
33
  headers: { Authorization: `Bearer ${this.apiToken}` }
33
34
  };
@@ -30,9 +30,9 @@ export const calculateTotalTaxesIncluded = (
30
30
  if (!order.discountCode) {
31
31
  const discountsToApply = storeDiscounts.filter(
32
32
  (discount: any) => discount.isActive && discount.products.some((p: any) => {
33
- if(typeof p === 'string') {
33
+ if (typeof p === 'string') {
34
34
  return p === current._id
35
- } else if(typeof p === 'object') {
35
+ } else if (typeof p === 'object') {
36
36
  return p._id === current._id
37
37
  }
38
38
  return false
@@ -59,6 +59,9 @@ export const calculateTotalTaxesIncluded = (
59
59
  if (discountType === 'percentage' && current.isBuyAndGetProduct) {
60
60
  discPercentageInteger = +(discountValue / 100).toFixed(2);
61
61
  }
62
+ if (discountType === 'free' && current.isBuyAndGetProduct) {
63
+ discPercentageInteger = 1;
64
+ }
62
65
  }
63
66
  }
64
67
 
@@ -56,6 +56,9 @@ export const calculateTotalTaxesOverPrice = (
56
56
  if (condition.getDiscountType === BuyAndGetConditionsTypes.PERCENTAGE && current.isBuyAndGetProduct) {
57
57
  discPercentageInteger = +(condition.discountValue / 100).toFixed(2);
58
58
  }
59
+ if (condition.getDiscountType === BuyAndGetConditionsTypes.FREE && current.isBuyAndGetProduct) {
60
+ discPercentageInteger = 1;
61
+ }
59
62
  }
60
63
  }
61
64