washday-sdk 1.0.1 → 1.1.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/README.md +126 -0
- package/babel.config.js +8 -0
- package/dist/api/attendance/delete.js +2 -0
- package/dist/api/attendance/get.js +83 -0
- package/dist/api/attendance/index.js +4 -0
- package/dist/api/attendance/post.js +39 -0
- package/dist/api/attendance/put.js +25 -0
- package/dist/api/auth/index.js +3 -0
- package/dist/api/auth/post.js +170 -0
- package/dist/api/axiosInstance.js +46 -0
- package/dist/api/cashierbox/delete.js +40 -0
- package/dist/api/cashierbox/get.js +63 -0
- package/dist/api/cashierbox/post.js +42 -0
- package/dist/api/cashierbox/put.js +42 -0
- package/dist/api/cashups/delete.js +25 -0
- package/dist/api/cashups/get.js +60 -0
- package/dist/api/cashups/index.js +4 -0
- package/dist/api/cashups/post.js +25 -0
- package/dist/api/cashups/put.js +52 -0
- package/dist/api/cfdi/delete.js +25 -0
- package/dist/api/cfdi/get.js +126 -0
- package/dist/api/cfdi/index.js +4 -0
- package/dist/api/cfdi/post.js +41 -0
- package/dist/api/cfdi/put.js +52 -0
- package/dist/api/companies/get.js +29 -0
- package/dist/api/companies/post.js +41 -0
- package/dist/api/companies/put.js +57 -0
- package/dist/api/countries/get.js +29 -0
- package/dist/api/countries/post.js +1 -0
- package/dist/api/countries/put.js +1 -0
- package/dist/api/csv/get.js +325 -0
- package/dist/api/csv/index.js +1 -0
- package/dist/api/customers/delete.js +40 -0
- package/dist/api/customers/get.js +106 -0
- package/dist/api/customers/index.js +4 -0
- package/dist/api/customers/post.js +41 -0
- package/dist/api/customers/put.js +52 -0
- package/dist/api/discounts/get.js +120 -0
- package/dist/api/discounts/post.js +40 -0
- package/dist/api/discounts/put.js +68 -0
- package/dist/api/index.js +319 -0
- package/dist/api/inventory/delete.js +26 -0
- package/dist/api/inventory/get.js +62 -0
- package/dist/api/inventory/index.js +4 -0
- package/dist/api/inventory/post.js +26 -0
- package/dist/api/inventory/put.js +41 -0
- package/dist/api/order/delete.js +40 -0
- package/dist/api/order/get.js +181 -0
- package/dist/api/order/index.js +4 -0
- package/dist/api/order/post.js +115 -0
- package/dist/api/order/put.js +202 -0
- package/dist/api/outsourcedOrders/delete.js +25 -0
- package/dist/api/outsourcedOrders/get.js +62 -0
- package/dist/api/outsourcedOrders/index.js +4 -0
- package/dist/api/outsourcedOrders/post.js +25 -0
- package/dist/api/outsourcedOrders/put.js +25 -0
- package/dist/api/partners/delete.js +25 -0
- package/dist/api/partners/get.js +40 -0
- package/dist/api/partners/index.js +4 -0
- package/dist/api/partners/post.js +25 -0
- package/dist/api/partners/put.js +25 -0
- package/dist/api/pdf/get.js +43 -0
- package/dist/api/pdf/index.js +1 -0
- package/dist/api/products/delete.js +40 -0
- package/dist/api/products/get.js +25 -0
- package/dist/api/products/index.js +4 -0
- package/dist/api/products/post.js +60 -0
- package/dist/api/products/put.js +40 -0
- package/dist/api/publics/get.js +26 -0
- package/dist/api/publics/index.js +1 -0
- package/dist/api/reports/get.js +303 -0
- package/dist/api/reports/index.js +1 -0
- package/dist/api/reviews/delete.js +15 -0
- package/dist/api/reviews/get.js +41 -0
- package/dist/api/reviews/index.js +4 -0
- package/dist/api/reviews/post.js +20 -0
- package/dist/api/reviews/put.js +52 -0
- package/dist/api/routes/delete.js +25 -0
- package/dist/api/routes/get.js +95 -0
- package/dist/api/routes/index.js +4 -0
- package/dist/api/routes/post.js +67 -0
- package/dist/api/routes/put.js +54 -0
- package/dist/api/sections/delete.js +25 -0
- package/dist/api/sections/get.js +71 -0
- package/dist/api/sections/index.js +4 -0
- package/dist/api/sections/post.js +26 -0
- package/dist/api/sections/put.js +25 -0
- package/dist/api/staff/delete.js +26 -0
- package/dist/api/staff/get.js +40 -0
- package/dist/api/staff/post.js +26 -0
- package/dist/api/staff/put.js +26 -0
- package/dist/api/stores/get.js +110 -0
- package/dist/api/stores/post.js +61 -0
- package/dist/api/stores/put.js +44 -0
- package/dist/api/stripe/get.js +1 -0
- package/dist/api/stripe/post.js +71 -0
- package/dist/api/stripe/put.js +1 -0
- package/dist/api/supplies/delete.js +26 -0
- package/dist/api/supplies/get.js +62 -0
- package/dist/api/supplies/post.js +26 -0
- package/dist/api/supplies/put.js +41 -0
- package/dist/api/users/delete.js +26 -0
- package/dist/api/users/post.js +25 -0
- package/dist/api/users/put.js +29 -0
- package/dist/enum/index.js +12 -7
- package/dist/index.js +3 -28
- package/dist/interfaces/Api.js +1 -0
- package/dist/interfaces/Apple.js +16 -0
- package/dist/interfaces/Attendance.js +1 -0
- package/dist/interfaces/Customer.js +1 -2
- package/dist/interfaces/Order.js +1 -2
- package/dist/interfaces/Permission.js +1 -2
- package/dist/interfaces/Product.js +1 -2
- package/dist/interfaces/Section.js +1 -2
- package/dist/interfaces/Store.js +1 -2
- package/dist/interfaces/StoreImage.js +1 -2
- package/dist/interfaces/User.js +1 -2
- package/dist/utils/apiUtils.js +9 -0
- package/dist/utils/index.js +2 -17
- package/dist/utils/orders/calculateOrderTotal.js +30 -21
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +55 -29
- package/dist/utils/orders/calculateTotalTaxesOverPrice.js +56 -45
- package/dist/utils/orders/helpers.js +126 -17
- package/dist/utils/orders/index.js +3 -5
- package/dist/utils/receipt/generateReceiptHTML.js +157 -0
- package/dist/utils/util.js +63 -0
- package/docs/README.md +66 -0
- package/docs/examples/common-use-cases.md +487 -0
- package/docs/getting-started.md +237 -0
- package/docs/modules/attendance.md +404 -0
- package/jest.config.js +0 -0
- package/package.json +12 -4
- package/src/api/attendance/delete.ts +1 -0
- package/src/api/attendance/get.ts +81 -0
- package/src/api/attendance/index.ts +4 -0
- package/src/api/attendance/post.ts +37 -0
- package/src/api/attendance/put.ts +20 -0
- package/src/api/auth/index.ts +3 -0
- package/src/api/auth/post.ts +198 -0
- package/src/api/axiosInstance.ts +13 -3
- package/src/api/cashierbox/delete.ts +28 -0
- package/src/api/cashierbox/get.ts +53 -0
- package/src/api/cashierbox/post.ts +39 -0
- package/src/api/cashierbox/put.ts +32 -0
- package/src/api/cashups/delete.ts +15 -0
- package/src/api/cashups/get.ts +52 -0
- package/src/api/cashups/index.ts +4 -0
- package/src/api/cashups/post.ts +23 -0
- package/src/api/cashups/put.ts +53 -0
- package/src/api/cfdi/delete.ts +21 -0
- package/src/api/cfdi/get.ts +119 -0
- package/src/api/cfdi/index.ts +4 -0
- package/src/api/cfdi/post.ts +60 -0
- package/src/api/cfdi/put.ts +53 -0
- package/src/api/companies/get.ts +23 -0
- package/src/api/companies/post.ts +29 -0
- package/src/api/companies/put.ts +43 -0
- package/src/api/countries/get.ts +23 -0
- package/src/api/countries/post.ts +0 -0
- package/src/api/countries/put.ts +0 -0
- package/src/api/csv/get.ts +354 -0
- package/src/api/csv/index.ts +1 -0
- package/src/api/customers/delete.ts +29 -0
- package/src/api/customers/get.ts +83 -12
- package/src/api/customers/index.ts +4 -0
- package/src/api/customers/post.ts +48 -0
- package/src/api/customers/put.ts +68 -0
- package/src/api/discounts/get.ts +100 -0
- package/src/api/discounts/post.ts +35 -0
- package/src/api/discounts/put.ts +66 -0
- package/src/api/index.ts +320 -12
- package/src/api/inventory/delete.ts +16 -0
- package/src/api/inventory/get.ts +53 -0
- package/src/api/inventory/index.ts +4 -0
- package/src/api/inventory/post.ts +22 -0
- package/src/api/inventory/put.ts +35 -0
- package/src/api/order/delete.ts +29 -0
- package/src/api/order/get.ts +207 -0
- package/src/api/order/index.ts +4 -0
- package/src/api/order/post.ts +118 -0
- package/src/api/order/put.ts +224 -0
- package/src/api/outsourcedOrders/delete.ts +15 -0
- package/src/api/outsourcedOrders/get.ts +54 -0
- package/src/api/outsourcedOrders/index.ts +4 -0
- package/src/api/outsourcedOrders/post.ts +24 -0
- package/src/api/outsourcedOrders/put.ts +21 -0
- package/src/api/partners/delete.ts +15 -0
- package/src/api/partners/get.ts +28 -0
- package/src/api/partners/index.ts +4 -0
- package/src/api/partners/post.ts +21 -0
- package/src/api/partners/put.ts +21 -0
- package/src/api/pdf/get.ts +43 -0
- package/src/api/pdf/index.ts +1 -0
- package/src/api/products/delete.ts +28 -0
- package/src/api/products/get.ts +16 -0
- package/src/api/products/index.ts +4 -0
- package/src/api/products/post.ts +73 -0
- package/src/api/products/put.ts +49 -0
- package/src/api/publics/get.ts +16 -0
- package/src/api/publics/index.ts +1 -0
- package/src/api/reports/get.ts +329 -0
- package/src/api/reports/index.ts +1 -0
- package/src/api/reviews/delete.ts +15 -0
- package/src/api/reviews/get.ts +31 -0
- package/src/api/reviews/index.ts +4 -0
- package/src/api/reviews/post.ts +20 -0
- package/src/api/reviews/put.ts +53 -0
- package/src/api/routes/delete.ts +15 -0
- package/src/api/routes/get.ts +86 -0
- package/src/api/routes/index.ts +4 -0
- package/src/api/routes/post.ts +60 -0
- package/src/api/routes/put.ts +44 -0
- package/src/api/sections/delete.ts +15 -0
- package/src/api/sections/get.ts +67 -0
- package/src/api/sections/index.ts +4 -0
- package/src/api/sections/post.ts +22 -0
- package/src/api/sections/put.ts +23 -0
- package/src/api/staff/delete.ts +16 -0
- package/src/api/staff/get.ts +29 -0
- package/src/api/staff/post.ts +17 -0
- package/src/api/staff/put.ts +17 -0
- package/src/api/stores/get.ts +93 -0
- package/src/api/stores/post.ts +49 -0
- package/src/api/stores/put.ts +35 -0
- package/src/api/stripe/get.ts +0 -0
- package/src/api/stripe/post.ts +59 -0
- package/src/api/stripe/put.ts +0 -0
- package/src/api/supplies/delete.ts +16 -0
- package/src/api/supplies/get.ts +53 -0
- package/src/api/supplies/post.ts +26 -0
- package/src/api/supplies/put.ts +33 -0
- package/src/api/users/delete.ts +16 -0
- package/src/api/users/post.ts +18 -0
- package/src/api/users/put.ts +36 -0
- package/src/enum/index.ts +9 -1
- package/src/index.ts +1 -4
- package/src/interfaces/Api.ts +308 -0
- package/src/interfaces/Apple.ts +74 -0
- package/src/interfaces/Attendance.ts +45 -0
- package/src/interfaces/Customer.ts +15 -11
- package/src/interfaces/Order.ts +38 -1
- package/src/interfaces/Product.ts +1 -0
- package/src/interfaces/Store.ts +41 -0
- package/src/utils/apiUtils.ts +11 -0
- package/src/utils/index.ts +6 -1
- package/src/utils/orders/calculateOrderTotal.test.js +930 -0
- package/src/utils/orders/calculateOrderTotal.ts +60 -15
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +57 -25
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +57 -41
- package/src/utils/orders/helpers.ts +195 -47
- package/src/utils/orders/index.ts +3 -1
- package/src/utils/receipt/generateReceiptHTML.ts +163 -0
- package/src/utils/util.ts +65 -0
- package/tsconfig.json +13 -9
package/src/api/customers/get.ts
CHANGED
|
@@ -1,19 +1,46 @@
|
|
|
1
|
+
import { GenericAbortSignal } from "axios";
|
|
2
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
1
3
|
import { ICustomer } from "../../interfaces/Customer";
|
|
2
4
|
import { IOrderInfo } from "../../interfaces/Order";
|
|
5
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
3
6
|
import axiosInstance from "../axiosInstance";
|
|
4
|
-
|
|
7
|
+
const GET_SET_CUSTOMERS_APP = 'api/v2/washdayapp/customers';
|
|
5
8
|
const GET_SET_CUSTOMERS = 'api/customer';
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
export const getList = async function (this: WashdayClientInstance, params: {
|
|
11
|
+
searchTerm?: string
|
|
12
|
+
name?: string
|
|
13
|
+
phone?: string
|
|
14
|
+
email?: string
|
|
15
|
+
fromDate?: string
|
|
16
|
+
toDate?: string
|
|
17
|
+
limit: string
|
|
18
|
+
pageNum: string
|
|
19
|
+
signal?: GenericAbortSignal
|
|
20
|
+
}, options?: { signal?: GenericAbortSignal }): Promise<any> {
|
|
21
|
+
try {
|
|
22
|
+
const config = {
|
|
23
|
+
headers: { Authorization: `Bearer ${this.apiToken}` },
|
|
24
|
+
signal: options?.signal || params.signal || undefined
|
|
25
|
+
};
|
|
26
|
+
const queryParams = generateQueryParamsStr(['searchTerm', 'name', 'phone', 'email', 'fromDate', 'toDate', 'limit', 'pageNum'], params);
|
|
27
|
+
return await axiosInstance.get(`${GET_SET_CUSTOMERS}?${queryParams}`, config);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'CanceledError')) {
|
|
30
|
+
console.log('Request was cancelled');
|
|
31
|
+
throw new Error('Request cancelled');
|
|
32
|
+
}
|
|
33
|
+
console.error('Error fetching customers:', error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
8
36
|
};
|
|
9
37
|
|
|
10
|
-
const
|
|
11
|
-
return this.apiToken;
|
|
12
|
-
}
|
|
13
|
-
export const getCustomerById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
38
|
+
export const getCustomerById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
14
39
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
40
|
+
const config = {
|
|
41
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
42
|
+
};
|
|
43
|
+
const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, config);
|
|
17
44
|
return response.data;
|
|
18
45
|
} catch (error) {
|
|
19
46
|
console.error('Error fetching customer:', error);
|
|
@@ -21,13 +48,57 @@ export const getCustomerById = async function (customerId: string): Promise<{ cu
|
|
|
21
48
|
}
|
|
22
49
|
};
|
|
23
50
|
|
|
24
|
-
export const getCustomerHighlightsById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
51
|
+
export const getCustomerHighlightsById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
25
52
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
const config = {
|
|
54
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
55
|
+
};
|
|
56
|
+
const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, config);
|
|
28
57
|
return response.data;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error('Error fetching getCustomerHighlightsById:', error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getCustomerOrders = async function (this: WashdayClientInstance, customerId: string, params: {
|
|
65
|
+
limit: string
|
|
66
|
+
pageNum: string
|
|
67
|
+
}): Promise<{ orders: any, totalRowsCount: any }> {
|
|
68
|
+
try {
|
|
69
|
+
const config = {
|
|
70
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
71
|
+
};
|
|
72
|
+
const queryParams = generateQueryParamsStr(['limit', 'pageNum'], params);
|
|
73
|
+
return await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/orders?${queryParams}`, config);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error fetching getCustomerHighlightsById:', error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
export const getCustomerByIdCustomersApp = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer }> {
|
|
82
|
+
try {
|
|
83
|
+
const config = {
|
|
84
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
85
|
+
};
|
|
86
|
+
return await axiosInstance.get(`${GET_SET_CUSTOMERS_APP}/${customerId}`, config);
|
|
29
87
|
} catch (error) {
|
|
30
88
|
console.error('Error fetching customer:', error);
|
|
31
89
|
throw error;
|
|
32
90
|
}
|
|
33
91
|
};
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
export const getCustomerLoyaltyHistory = async function (this: WashdayClientInstance, customerId: string): Promise<any> {
|
|
95
|
+
try {
|
|
96
|
+
const config = {
|
|
97
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
98
|
+
};
|
|
99
|
+
return await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/loyalty-history`, config);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Error fetching getCustomerLoyaltyHistory:', error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import axiosInstance from "../axiosInstance";
|
|
3
|
+
const GET_SET_CUSTOMERS = 'api/customer';
|
|
4
|
+
|
|
5
|
+
export const create = async function (this: WashdayClientInstance, data: {
|
|
6
|
+
name: string;
|
|
7
|
+
lastName?: string;
|
|
8
|
+
phone?: string;
|
|
9
|
+
phoneCountryCode?: string;
|
|
10
|
+
phoneCountryName?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
address?: string;
|
|
13
|
+
notes?: string;
|
|
14
|
+
privateNotes?: string;
|
|
15
|
+
discount: number;
|
|
16
|
+
credit: number;
|
|
17
|
+
rfc?: string;
|
|
18
|
+
invoiceInfo?: {
|
|
19
|
+
legal_name?: string;
|
|
20
|
+
tax_system?: string;
|
|
21
|
+
zipCode?: string;
|
|
22
|
+
};
|
|
23
|
+
isActive: boolean;
|
|
24
|
+
}): Promise<any> {
|
|
25
|
+
try {
|
|
26
|
+
const config = {
|
|
27
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
28
|
+
};
|
|
29
|
+
const response = await axiosInstance.post(`${GET_SET_CUSTOMERS}`, data, config);
|
|
30
|
+
return response;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error('Error fetching create:', error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const bulkCreate = async function (this: WashdayClientInstance, storeId: string, data: any): Promise<any> {
|
|
38
|
+
try {
|
|
39
|
+
const config = {
|
|
40
|
+
headers: { Authorization: `Bearer ${this.apiToken}`, 'Content-Type': false }
|
|
41
|
+
};
|
|
42
|
+
const response = await axiosInstance.post(`${GET_SET_CUSTOMERS}/bulk`, data, config);
|
|
43
|
+
return response.data || {}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error fetching customers bulkCreate:', error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import axiosInstance from "../axiosInstance";
|
|
3
|
+
const GET_SET_CUSTOMERS = 'api/customer';
|
|
4
|
+
const GET_SET_CUSTOMERS_APP = 'api/v2/washdayapp/customers';
|
|
5
|
+
// export const bulkUpdate = async function (this: WashdayClientInstance, storeId: string, data: any): Promise<any> {
|
|
6
|
+
// try {
|
|
7
|
+
// const config = {
|
|
8
|
+
// headers: { Authorization: `Bearer ${this.apiToken}`, 'Content-Type': false }
|
|
9
|
+
// };
|
|
10
|
+
// const response = await axiosInstance.put(`${GET_SET_PRODUCTS}/${storeId}/bulk`, data, config);
|
|
11
|
+
// return response.data || {}
|
|
12
|
+
// } catch (error) {
|
|
13
|
+
// console.error('Error fetching getStoreById:', error);
|
|
14
|
+
// throw error;
|
|
15
|
+
// }
|
|
16
|
+
// };
|
|
17
|
+
|
|
18
|
+
export const updateById = async function (this: WashdayClientInstance, id: string, data: {
|
|
19
|
+
name?: string;
|
|
20
|
+
lastName?: string;
|
|
21
|
+
phone?: string;
|
|
22
|
+
phoneCountryCode?: string;
|
|
23
|
+
phoneCountryName?: string;
|
|
24
|
+
email?: string;
|
|
25
|
+
address?: string;
|
|
26
|
+
notes?: string;
|
|
27
|
+
privateNotes?: string;
|
|
28
|
+
discount?: number;
|
|
29
|
+
credit?: number;
|
|
30
|
+
rfc?: string;
|
|
31
|
+
invoiceInfo?: {
|
|
32
|
+
legal_name?: string;
|
|
33
|
+
tax_system?: string;
|
|
34
|
+
zipCode?: string;
|
|
35
|
+
};
|
|
36
|
+
isActive?: boolean;
|
|
37
|
+
}): Promise<any> {
|
|
38
|
+
try {
|
|
39
|
+
const config = {
|
|
40
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
41
|
+
};
|
|
42
|
+
return await axiosInstance.put(`${GET_SET_CUSTOMERS}/${id}`, data, config);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('Error fetching updateById:', error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const updateByIdCustomersApp = async function (this: WashdayClientInstance, id: string, data: {
|
|
50
|
+
name?: string;
|
|
51
|
+
lastName?: string;
|
|
52
|
+
phone?: string;
|
|
53
|
+
phoneCountryCode?: string;
|
|
54
|
+
phoneCountryName?: string;
|
|
55
|
+
address?: string;
|
|
56
|
+
notes?: string;
|
|
57
|
+
customersAppPushNotificationToken?: string;
|
|
58
|
+
}): Promise<any> {
|
|
59
|
+
try {
|
|
60
|
+
const config = {
|
|
61
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
62
|
+
};
|
|
63
|
+
return await axiosInstance.put(`${GET_SET_CUSTOMERS_APP}/${id}`, data, config);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error('Error fetching updateByIdCustomersApp:', error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
3
|
+
import axiosInstance from "../axiosInstance";
|
|
4
|
+
|
|
5
|
+
const GET_SET_DISCOUNT_CODES = 'api/v2/discountCodes';
|
|
6
|
+
const GET_SET_AUTOMATIC_DISCOUNTS = 'api/discounts';
|
|
7
|
+
const GET_AVAILABLE_AUTOMATIC_DISCOUNTS = 'api/availableDiscounts';
|
|
8
|
+
const GET_DISCOUNT_CODES_CUSTOMER_APP = 'api/v2/washdayapp/discountCodes';
|
|
9
|
+
|
|
10
|
+
export const getDiscountCodes = async function (this: WashdayClientInstance, storeId: string, params?: string): Promise<any> {
|
|
11
|
+
try {
|
|
12
|
+
let queryParams = '';
|
|
13
|
+
// if (params.isActive) {
|
|
14
|
+
// queryParams += `isActive=${params.isActive}`
|
|
15
|
+
// }
|
|
16
|
+
const config = {
|
|
17
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
18
|
+
};
|
|
19
|
+
return await axiosInstance.get(`${GET_SET_DISCOUNT_CODES}/${storeId}?${queryParams}`, config);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Error fetching getStores:', error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getAutomaticDiscounts = async function (this: WashdayClientInstance, storeId: string, params?: {}): Promise<any> {
|
|
27
|
+
try {
|
|
28
|
+
const queryParams = generateQueryParamsStr([
|
|
29
|
+
'currentDate',
|
|
30
|
+
], params);
|
|
31
|
+
|
|
32
|
+
const config = {
|
|
33
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
34
|
+
};
|
|
35
|
+
return await axiosInstance.get(`${GET_SET_AUTOMATIC_DISCOUNTS}/${storeId}?${queryParams}`, config);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Error fetching getStores:', error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const getDiscountCodeById = async function (this: WashdayClientInstance, storeId: string, discountId: string,): Promise<any> {
|
|
43
|
+
try {
|
|
44
|
+
const config = {
|
|
45
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
46
|
+
};
|
|
47
|
+
return await axiosInstance.get(`${GET_SET_DISCOUNT_CODES}/${storeId}/${discountId}`, config);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Error fetching getDiscountCodeById:', error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getAutomaticDiscountById = async function (this: WashdayClientInstance, storeId: string, discountId: string,): Promise<any> {
|
|
55
|
+
try {
|
|
56
|
+
const config = {
|
|
57
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
58
|
+
};
|
|
59
|
+
return await axiosInstance.get(`${GET_SET_AUTOMATIC_DISCOUNTS}/${storeId}/${discountId}`, config);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('Error fetching getDiscountCodeById:', error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const verifyDiscountCode = async function (this: WashdayClientInstance, storeId: string, code: string,): Promise<any> {
|
|
67
|
+
try {
|
|
68
|
+
const config = {
|
|
69
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
70
|
+
};
|
|
71
|
+
return await axiosInstance.get(`${GET_SET_DISCOUNT_CODES}/${storeId}/${code}/verify`, config);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error('Error fetching verifyDiscountCode:', error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const verifyDiscountCodeCustomersApp = async function (this: WashdayClientInstance, storeId: string, code: string,): Promise<any> {
|
|
79
|
+
try {
|
|
80
|
+
const config = {
|
|
81
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
82
|
+
};
|
|
83
|
+
return await axiosInstance.get(`${GET_DISCOUNT_CODES_CUSTOMER_APP}/${storeId}/${code}/verify`, config);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error('Error fetching verifyDiscountCodeCustomersApp:', error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const getAvailableAutomaticDiscounts = async function (this: WashdayClientInstance, storeId: string, date: string): Promise<any> {
|
|
91
|
+
try {
|
|
92
|
+
const config = {
|
|
93
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
94
|
+
};
|
|
95
|
+
return await axiosInstance.get(`${GET_AVAILABLE_AUTOMATIC_DISCOUNTS}/${storeId}?currentDate=${date}`, config);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error fetching getAvailableAutomaticDiscounts:', error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { IStore } from "../../interfaces/Store";
|
|
3
|
+
import axiosInstance from "../axiosInstance";
|
|
4
|
+
|
|
5
|
+
const GET_SET_DISCOUNT_CODES = 'api/v2/discountCodes';
|
|
6
|
+
const GET_SET_AUTOMATIC_DISCOUNTS = 'api/discounts';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const createAutomaticDiscount = async function (this: WashdayClientInstance, storeId: string, data: any): Promise<any> {
|
|
10
|
+
try {
|
|
11
|
+
const config = {
|
|
12
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
13
|
+
};
|
|
14
|
+
return await axiosInstance.post(`${GET_SET_AUTOMATIC_DISCOUNTS}/${storeId}`, data, config);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error('Error fetching createAutomaticDiscount:', error);
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export const createDiscountCode = async function (this: WashdayClientInstance, storeId: string, data: any): Promise<any> {
|
|
23
|
+
try {
|
|
24
|
+
const config = {
|
|
25
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
26
|
+
};
|
|
27
|
+
return await axiosInstance.post(`${GET_SET_DISCOUNT_CODES}/${storeId}`, data, config);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Error fetching createAutomaticDiscount:', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { IStore } from "../../interfaces/Store";
|
|
3
|
+
import axiosInstance from "../axiosInstance";
|
|
4
|
+
|
|
5
|
+
const GET_SET_DISCOUNT_CODES = 'api/v2/discountCodes';
|
|
6
|
+
const GET_SET_AUTOMATIC_DISCOUNTS = 'api/discounts';
|
|
7
|
+
|
|
8
|
+
export const deleteDiscountCodeById = async function (this: WashdayClientInstance, storeId: string, discountId: string): Promise<any> {
|
|
9
|
+
try {
|
|
10
|
+
const config = {
|
|
11
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
12
|
+
};
|
|
13
|
+
return await axiosInstance.delete(`${GET_SET_DISCOUNT_CODES}/${storeId}/${discountId}`, config);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error('Error fetching deleteDiscountCodeById:', error);
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const deleteAutomaticDiscountById = async function (this: WashdayClientInstance, storeId: string, discountId: string): Promise<any> {
|
|
21
|
+
try {
|
|
22
|
+
const config = {
|
|
23
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
24
|
+
};
|
|
25
|
+
return await axiosInstance.delete(`${GET_SET_AUTOMATIC_DISCOUNTS}/${storeId}/${discountId}`, config);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error('Error fetching deleteAutomaticDiscountById:', error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export const updateAutomaticDiscountById = async function (this: WashdayClientInstance, storeId: string, discountId: string, data: {
|
|
34
|
+
products: string[];
|
|
35
|
+
}): Promise<any> {
|
|
36
|
+
try {
|
|
37
|
+
const config = {
|
|
38
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
39
|
+
};
|
|
40
|
+
return await axiosInstance.put(`${GET_SET_AUTOMATIC_DISCOUNTS}/${storeId}/${discountId}`, data, config);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('Error fetching updateById:', error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const updateDiscountCodeById = async function (this: WashdayClientInstance, storeId: string, discountId: string, data: {
|
|
48
|
+
products?: string[];
|
|
49
|
+
buyAndGetConditions?: any;
|
|
50
|
+
freeProductSetting?: any;
|
|
51
|
+
name?: string;
|
|
52
|
+
code?: string;
|
|
53
|
+
fromDate?: string;
|
|
54
|
+
toDate?: string;
|
|
55
|
+
}): Promise<any> {
|
|
56
|
+
try {
|
|
57
|
+
const config = {
|
|
58
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
59
|
+
};
|
|
60
|
+
return await axiosInstance.put(`${GET_SET_DISCOUNT_CODES}/${storeId}/${discountId}`, data, config);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error fetching updateDiscountCodeById:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|