washday-sdk 0.0.23 → 0.0.25

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.
Files changed (40) hide show
  1. package/babel.config.js +7 -7
  2. package/dist/api/axiosInstance.js +2 -1
  3. package/dist/api/index.js +8 -2
  4. package/dist/api/products/get.js +7 -0
  5. package/dist/api/products/post.js +7 -0
  6. package/dist/api/products/put.js +36 -0
  7. package/dist/api/stores/post.js +37 -0
  8. package/dist/utils/receipt/generateReceiptHTML.js +157 -0
  9. package/dist/utils/util.js +46 -0
  10. package/package.json +29 -28
  11. package/src/api/axiosInstance.ts +47 -46
  12. package/src/api/customers/get.ts +32 -32
  13. package/src/api/index.ts +37 -29
  14. package/src/api/products/get.ts +9 -0
  15. package/src/api/products/post.ts +11 -0
  16. package/src/api/products/put.ts +21 -0
  17. package/src/api/stores/get.ts +36 -36
  18. package/src/api/stores/post.ts +23 -0
  19. package/src/api/stores/put.ts +20 -20
  20. package/src/enum/index.ts +10 -10
  21. package/src/index.ts +4 -4
  22. package/src/interfaces/Api.ts +2 -2
  23. package/src/interfaces/Customer.ts +51 -51
  24. package/src/interfaces/Order.ts +95 -95
  25. package/src/interfaces/Permission.ts +24 -24
  26. package/src/interfaces/Product.ts +58 -58
  27. package/src/interfaces/Section.ts +14 -14
  28. package/src/interfaces/Store.ts +350 -350
  29. package/src/interfaces/StoreImage.ts +9 -9
  30. package/src/interfaces/User.ts +42 -42
  31. package/src/utils/index.ts +1 -1
  32. package/src/utils/orders/calculateOrderTotal.test.js +399 -399
  33. package/src/utils/orders/calculateOrderTotal.ts +60 -60
  34. package/src/utils/orders/calculateTotalTaxesIncluded.ts +75 -75
  35. package/src/utils/orders/calculateTotalTaxesOverPrice.ts +82 -82
  36. package/src/utils/orders/helpers.ts +73 -73
  37. package/src/utils/orders/index.ts +4 -4
  38. package/src/utils/receipt/generateReceiptHTML.ts +163 -0
  39. package/src/utils/util.ts +47 -0
  40. package/tsconfig.json +9 -9
package/babel.config.js CHANGED
@@ -1,8 +1,8 @@
1
- module.exports = {
2
- presets: [
3
- ['@babel/preset-env', {targets: {node: 'current'}}],
4
- '@babel/preset-typescript',
5
- ],
6
- };
7
-
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', {targets: {node: 'current'}}],
4
+ '@babel/preset-typescript',
5
+ ],
6
+ };
7
+
8
8
 
@@ -19,8 +19,9 @@ const getAxiosInstance = () => {
19
19
  });
20
20
  // Add interceptor to set token and other options for every request
21
21
  axiosInstance.interceptors.request.use((config) => {
22
- const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
22
+ const { token, responseType = 'json', contentDisposition } = config.params || {};
23
23
  const { Authorization } = config.headers || {};
24
+ const contentType = config.headers['Content-Type'] || 'application/json';
24
25
  if (Authorization || token) {
25
26
  config.headers.Authorization = Authorization || `Bearer ${token}`;
26
27
  }
package/dist/api/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const get_1 = require("./customers/get");
4
+ const put_1 = require("./products/put");
4
5
  const get_2 = require("./stores/get");
5
- const put_1 = require("./stores/put");
6
+ const post_1 = require("./stores/post");
7
+ const put_2 = require("./stores/put");
6
8
  const WashdayClient = function WashdayClient(apiToken) {
7
9
  this.apiToken = apiToken;
8
10
  WashdayClient.prototype.customers.apiToken = apiToken;
@@ -15,6 +17,10 @@ WashdayClient.prototype.customers = {
15
17
  WashdayClient.prototype.stores = {
16
18
  getStores: get_2.getStores,
17
19
  getStoreById: get_2.getStoreById,
18
- updateStoreById: put_1.updateStoreById
20
+ updateStoreById: put_2.updateStoreById,
21
+ createStoreImage: post_1.createStoreImage
22
+ };
23
+ WashdayClient.prototype.products = {
24
+ bulkUpdate: put_1.bulkUpdate,
19
25
  };
20
26
  exports.default = WashdayClient;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET_SET_PRODUCTS = void 0;
4
+ exports.GET_SET_PRODUCTS = 'api/product';
5
+ const REQUEST_PARAMS = {
6
+ token: 'LOGGED_USER_TOKEN',
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const GET_SET_STORES = 'api/store';
4
+ const GET_SET_STORE_IMAGE = 'api/store-image';
5
+ const REQUEST_PARAMS = {
6
+ token: 'LOGGED_USER_TOKEN',
7
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.bulkUpdate = void 0;
16
+ const axiosInstance_1 = __importDefault(require("../axiosInstance"));
17
+ const GET_SET_PRODUCTS = 'api/product';
18
+ const REQUEST_PARAMS = {
19
+ token: 'LOGGED_USER_TOKEN',
20
+ };
21
+ const bulkUpdate = function (storeId, data) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ try {
24
+ const config = {
25
+ headers: { Authorization: `Bearer ${this.apiToken}` }
26
+ };
27
+ const response = yield axiosInstance_1.default.put(`${GET_SET_PRODUCTS}/${storeId}/bulk`, data, config);
28
+ return response.data || {};
29
+ }
30
+ catch (error) {
31
+ console.error('Error fetching getStoreById:', error);
32
+ throw error;
33
+ }
34
+ });
35
+ };
36
+ exports.bulkUpdate = bulkUpdate;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createStoreImage = void 0;
16
+ const axiosInstance_1 = __importDefault(require("../axiosInstance"));
17
+ const GET_SET_STORES = 'api/store';
18
+ const GET_SET_STORE_IMAGE = 'api/store-image';
19
+ const REQUEST_PARAMS = {
20
+ token: 'LOGGED_USER_TOKEN',
21
+ };
22
+ const createStoreImage = function (data) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ const config = {
26
+ headers: { Authorization: `Bearer ${this.apiToken}`, contentType: 'multipart/form-data' }
27
+ };
28
+ const response = yield axiosInstance_1.default.post(`${GET_SET_STORE_IMAGE}`, data, config);
29
+ return response;
30
+ }
31
+ catch (error) {
32
+ console.error('Error fetching createStoreImage:', error);
33
+ throw error;
34
+ }
35
+ });
36
+ };
37
+ exports.createStoreImage = createStoreImage;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ // import moment from "moment";
3
+ // import { formatMoneyString, truncateOrFill } from "../util";
4
+ // export const generateReceiptThermalPrinter = (order, storeSettings, ticketStructure, charsPerLine = 32) => {
5
+ // //THIS STRING IS FORMED WITH THE EXPECTED USE OF react-native-thermal-receipt-printer PACKAGE
6
+ // const PAPER_LINE_LENGTH = charsPerLine;
7
+ // const orderProducts = order?.products || [];
8
+ // const orderBuyAndGerProducts = order?.buyAndGetProducts || [];
9
+ // const orderAllProducts = [...orderProducts, ...orderBuyAndGerProducts];
10
+ // console.log('PAPER_LINE_LENGTH', PAPER_LINE_LENGTH);
11
+ // const paymentLinesTotal =
12
+ // order.paymentLines?.reduce((prev, next) => {
13
+ // return prev + (next?.amountPaid || 0);
14
+ // }, 0) || 0;
15
+ // let headers = `
16
+ // ${ticketStructure.showStoreName ? `<CM>${storeSettings.name}</CM>` : ''}
17
+ // ${ticketStructure.showStorePhone ? `Tel: ${storeSettings.phone}` : ''}
18
+ // ${'-'.repeat(PAPER_LINE_LENGTH)}
19
+ // ${ticketStructure.showEmisionDate
20
+ // ? `Fecha emision: ${moment(order?.createdDate).format('DD/MM/YYYY')}`
21
+ // : ''
22
+ // }
23
+ // ${ticketStructure.showEmisionTime
24
+ // ? `Hora emision: ${moment(order?.createdDate).format('hh:mm a')}`
25
+ // : ''
26
+ // }
27
+ // ${ticketStructure.showCreatedByName ? `Atendio: ${order.createdBy.name}` : ''}
28
+ // Pedido: WD-${order.sequence}
29
+ // ${ticketStructure.showCustomerName ? `Cliente: ${order.customer.name}` : ''}
30
+ // ${ticketStructure.showDeliveryDate
31
+ // ? `Entrega: ${moment(order?.deliveryInfo?.date).format('DD/MM/YYYY')} ${ticketStructure.showDeliveryTime
32
+ // ? moment(order?.deliveryInfo?.fromTime).format('HH:mm')
33
+ // : ''
34
+ // }`
35
+ // : ''
36
+ // }
37
+ // ${ticketStructure.showTotalPieces ? `Piezas: ${orderAllProducts?.reduce((prev, curr) => {
38
+ // return prev + +curr.pieces * curr.quantity;
39
+ // }, 0)}` : ''}
40
+ // ${ticketStructure.showOrderNotes && order.notes ? `${order.notes}` : ''}
41
+ // `;
42
+ // let middle = '';
43
+ // //Add order products
44
+ // orderAllProducts.forEach(prod => {
45
+ // //CHARS PER LINE: 32 in 58MM PAPER
46
+ // const quantityFixed = truncateOrFill(
47
+ // `x${prod.quantity.toString()}`,
48
+ // 3,
49
+ // 'right',
50
+ // );
51
+ // const prodNameFixed = truncateOrFill(
52
+ // prod.name,
53
+ // PAPER_LINE_LENGTH - 3 - 7 - 7 - 3,
54
+ // 'right',
55
+ // );
56
+ // const unitPriceFixed = truncateOrFill(
57
+ // formatMoneyString(
58
+ // (order?.express ? +prod.expressPrice : +prod.price) +
59
+ // (+prod.extraAmount / +prod.quantity || 0),
60
+ // ),
61
+ // 7,
62
+ // 'left',
63
+ // );
64
+ // const totalPriceFixed = truncateOrFill(
65
+ // formatMoneyString(
66
+ // (order?.express ? +prod.expressPrice : +prod.price) * +prod.quantity +
67
+ // (+prod.extraAmount || 0),
68
+ // ),
69
+ // 7,
70
+ // 'left',
71
+ // );
72
+ // middle =
73
+ // middle +
74
+ // `${quantityFixed} ${prodNameFixed} ${unitPriceFixed} ${totalPriceFixed}\n`;
75
+ // });
76
+ // let footer = '';
77
+ // footer =
78
+ // footer +
79
+ // `\n${truncateOrFill(
80
+ // 'Subtotal: ' +
81
+ // formatMoneyString(order.productTotalWithoutDiscount || 0),
82
+ // PAPER_LINE_LENGTH,
83
+ // 'left',
84
+ // )}`;
85
+ // if (ticketStructure.showDiscounts) {
86
+ // footer =
87
+ // footer +
88
+ // `\n${truncateOrFill(
89
+ // 'Descuento: ' + formatMoneyString(order.totalDiscountAmount || 0),
90
+ // PAPER_LINE_LENGTH,
91
+ // 'left',
92
+ // )}`;
93
+ // }
94
+ // if (ticketStructure.showCredit) {
95
+ // footer =
96
+ // footer +
97
+ // `\n${truncateOrFill(
98
+ // 'Credito: ' + formatMoneyString(order.creditApplied || 0),
99
+ // PAPER_LINE_LENGTH,
100
+ // 'left',
101
+ // )}`;
102
+ // }
103
+ // if (ticketStructure.showTaxes) {
104
+ // footer =
105
+ // footer +
106
+ // `\n${truncateOrFill(
107
+ // 'Impuestos: ' + formatMoneyString(order.taxesTotal || 0),
108
+ // PAPER_LINE_LENGTH,
109
+ // 'left',
110
+ // )}`;
111
+ // }
112
+ // footer =
113
+ // footer +
114
+ // `${order.delivery || order.pickup
115
+ // ? `\n${truncateOrFill(
116
+ // 'Servicio a domicilio: ' +
117
+ // formatMoneyString(order.shippingServiceTotal || 0),
118
+ // PAPER_LINE_LENGTH,
119
+ // 'left',
120
+ // )}`
121
+ // : ''
122
+ // }`;
123
+ // footer =
124
+ // footer +
125
+ // '\n' +
126
+ // `${truncateOrFill(
127
+ // 'Total: ' + formatMoneyString(order.total || 0),
128
+ // PAPER_LINE_LENGTH,
129
+ // 'left',
130
+ // )}`;
131
+ // footer =
132
+ // footer +
133
+ // '\n' +
134
+ // `${truncateOrFill(
135
+ // 'Pago: ' + formatMoneyString(paymentLinesTotal),
136
+ // PAPER_LINE_LENGTH,
137
+ // 'left',
138
+ // )}`;
139
+ // footer =
140
+ // footer +
141
+ // '\n' +
142
+ // `${truncateOrFill(
143
+ // 'Debe: ' + ((order.total || 0) - paymentLinesTotal).toFixed(2),
144
+ // PAPER_LINE_LENGTH,
145
+ // 'left',
146
+ // )}`;
147
+ // footer = footer + `\n${'-'.repeat(PAPER_LINE_LENGTH)}\n`;
148
+ // // footer = footer + `${ticketStructure.showPaymentMethod ? `<C>${translatePaymentType(order.paymentMethod)}</C>\n` : ''}`
149
+ // footer =
150
+ // footer +
151
+ // `${ticketStructure.showLegend
152
+ // ? `<C>${ticketStructure.ticketLegendText}</C>`
153
+ // : ''
154
+ // }`;
155
+ // const ticket = headers + '\n' + middle + '\n' + footer;
156
+ // return ticket;
157
+ // }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // export function truncateOrFill(str: string, n: number, side: string = 'right') {
3
+ // let needSpacesQty = n - str.length;
4
+ // let whiteSpace = '';
5
+ // if (needSpacesQty > 0) {
6
+ // for (let i = 0; i < needSpacesQty; i++) {
7
+ // whiteSpace += ' ';
8
+ // }
9
+ // }
10
+ // return str.length > n
11
+ // ? str.substr(0, n - 3) + '...'
12
+ // : side === 'right'
13
+ // ? str + whiteSpace
14
+ // : whiteSpace + str;
15
+ // }
16
+ // export const formatMoneyString = (
17
+ // amount: string | number = 0,
18
+ // decimalCount: number = 2,
19
+ // decimal = '.',
20
+ // thousands = ',',
21
+ // currencySymbol = '$',
22
+ // ) => {
23
+ // try {
24
+ // decimalCount = Math.abs(decimalCount);
25
+ // decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
26
+ // const negativeSign = amount < 0 ? '-' : '';
27
+ // let i = parseInt(
28
+ // (amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)),
29
+ // ).toString();
30
+ // let j = i.length > 3 ? i.length % 3 : 0;
31
+ // return (
32
+ // currencySymbol +
33
+ // negativeSign +
34
+ // (j ? i.substr(0, j) + thousands : '') +
35
+ // i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousands) +
36
+ // (decimalCount
37
+ // ? decimal +
38
+ // Math.abs(amount - i)
39
+ // .toFixed(decimalCount)
40
+ // .slice(2)
41
+ // : '')
42
+ // );
43
+ // } catch (e) {
44
+ // console.log(e);
45
+ // }
46
+ // };
package/package.json CHANGED
@@ -1,28 +1,29 @@
1
- {
2
- "name": "washday-sdk",
3
- "version": "0.0.23",
4
- "description": "Washday utilities functions and API",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "jest",
8
- "build": "tsc",
9
- "publish": "npm run build && npm publish --access public"
10
- },
11
- "keywords": [
12
- "washday"
13
- ],
14
- "author": "Washday",
15
- "license": "ISC",
16
- "devDependencies": {
17
- "@babel/core": "^7.24.4",
18
- "@babel/preset-env": "^7.24.4",
19
- "@babel/preset-typescript": "^7.24.1",
20
- "babel-jest": "^29.7.0",
21
- "jest": "^29.7.0",
22
- "typescript": "^5.4.4"
23
- },
24
- "dependencies": {
25
- "axios": "^1.6.8",
26
- "joi": "^17.12.3"
27
- }
28
- }
1
+ {
2
+ "name": "washday-sdk",
3
+ "version": "0.0.25",
4
+ "description": "Washday utilities functions and API",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "build": "tsc",
9
+ "publish": "npm run build && npm publish --access public"
10
+ },
11
+ "keywords": [
12
+ "washday"
13
+ ],
14
+ "author": "Washday",
15
+ "license": "ISC",
16
+ "devDependencies": {
17
+ "@babel/core": "^7.24.4",
18
+ "@babel/preset-env": "^7.24.4",
19
+ "@babel/preset-typescript": "^7.24.1",
20
+ "babel-jest": "^29.7.0",
21
+ "jest": "^29.7.0",
22
+ "typescript": "^5.4.4"
23
+ },
24
+ "dependencies": {
25
+ "axios": "^1.6.8",
26
+ "joi": "^17.12.3",
27
+ "moment": "^2.30.1"
28
+ }
29
+ }
@@ -1,46 +1,47 @@
1
- import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
-
3
- // Define the type for the Axios instance
4
- let axiosInstance: AxiosInstance | null = null;
5
-
6
- const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
7
-
8
- // Function to create or return the singleton instance
9
- const getAxiosInstance = (): AxiosInstance => {
10
- if (!axiosInstance) {
11
- axiosInstance = axios.create({
12
- baseURL: BASE_URL,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- // Add any default headers here
16
- },
17
- });
18
-
19
- // Add interceptor to set token and other options for every request
20
- axiosInstance.interceptors.request.use(
21
- (config) => {
22
- const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
23
- const { Authorization } = config.headers || {};
24
- if (Authorization || token) {
25
- config.headers.Authorization = Authorization || `Bearer ${token}`;
26
- }
27
- if (contentType) {
28
- config.headers['Content-Type'] = contentType;
29
- }
30
- if (responseType) {
31
- config.responseType = responseType;
32
- }
33
- if (contentDisposition) {
34
- config.headers['Content-Disposition'] = contentDisposition;
35
- }
36
- return config;
37
- },
38
- (error) => {
39
- return Promise.reject(error);
40
- }
41
- );
42
- }
43
- return axiosInstance;
44
- };
45
-
46
- export default getAxiosInstance();
1
+ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+
3
+ // Define the type for the Axios instance
4
+ let axiosInstance: AxiosInstance | null = null;
5
+
6
+ const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
7
+
8
+ // Function to create or return the singleton instance
9
+ const getAxiosInstance = (): AxiosInstance => {
10
+ if (!axiosInstance) {
11
+ axiosInstance = axios.create({
12
+ baseURL: BASE_URL,
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ // Add any default headers here
16
+ },
17
+ });
18
+
19
+ // Add interceptor to set token and other options for every request
20
+ axiosInstance.interceptors.request.use(
21
+ (config) => {
22
+ const { token, responseType = 'json', contentDisposition } = config.params || {};
23
+ const { Authorization } = config.headers || {};
24
+ const contentType = config.headers['Content-Type'] || 'application/json';
25
+ if (Authorization || token) {
26
+ config.headers.Authorization = Authorization || `Bearer ${token}`;
27
+ }
28
+ if (contentType) {
29
+ config.headers['Content-Type'] = contentType;
30
+ }
31
+ if (responseType) {
32
+ config.responseType = responseType;
33
+ }
34
+ if (contentDisposition) {
35
+ config.headers['Content-Disposition'] = contentDisposition;
36
+ }
37
+ return config;
38
+ },
39
+ (error) => {
40
+ return Promise.reject(error);
41
+ }
42
+ );
43
+ }
44
+ return axiosInstance;
45
+ };
46
+
47
+ export default getAxiosInstance();
@@ -1,32 +1,32 @@
1
- import { WashdayClientInstance } from "../../interfaces/Api";
2
- import { ICustomer } from "../../interfaces/Customer";
3
- import { IOrderInfo } from "../../interfaces/Order";
4
- import axiosInstance from "../axiosInstance";
5
-
6
- const GET_SET_CUSTOMERS = 'api/customer';
7
- const REQUEST_PARAMS = {
8
- token: 'LOGGED_USER_TOKEN',
9
- };
10
-
11
-
12
- export const getCustomerById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
13
- try {
14
- REQUEST_PARAMS.token = this.apiToken;
15
- const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: { ...REQUEST_PARAMS } });
16
- return response.data;
17
- } catch (error) {
18
- console.error('Error fetching customer:', error);
19
- throw error;
20
- }
21
- };
22
-
23
- export const getCustomerHighlightsById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
24
- try {
25
- REQUEST_PARAMS.token = this.apiToken;
26
- const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: { ...REQUEST_PARAMS } });
27
- return response.data;
28
- } catch (error) {
29
- console.error('Error fetching getCustomerHighlightsById:', error);
30
- throw error;
31
- }
32
- };
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+ import { ICustomer } from "../../interfaces/Customer";
3
+ import { IOrderInfo } from "../../interfaces/Order";
4
+ import axiosInstance from "../axiosInstance";
5
+
6
+ const GET_SET_CUSTOMERS = 'api/customer';
7
+ const REQUEST_PARAMS = {
8
+ token: 'LOGGED_USER_TOKEN',
9
+ };
10
+
11
+
12
+ export const getCustomerById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
13
+ try {
14
+ REQUEST_PARAMS.token = this.apiToken;
15
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: { ...REQUEST_PARAMS } });
16
+ return response.data;
17
+ } catch (error) {
18
+ console.error('Error fetching customer:', error);
19
+ throw error;
20
+ }
21
+ };
22
+
23
+ export const getCustomerHighlightsById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
24
+ try {
25
+ REQUEST_PARAMS.token = this.apiToken;
26
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: { ...REQUEST_PARAMS } });
27
+ return response.data;
28
+ } catch (error) {
29
+ console.error('Error fetching getCustomerHighlightsById:', error);
30
+ throw error;
31
+ }
32
+ };
package/src/api/index.ts CHANGED
@@ -1,29 +1,37 @@
1
- import { WashdayClientInstance } from "../interfaces/Api";
2
- import { getCustomerById, getCustomerHighlightsById } from "./customers/get";
3
- import { getStoreById, getStores } from "./stores/get";
4
- import { updateStoreById } from "./stores/put";
5
-
6
- type WashdayClientConstructor = {
7
- new(apiToken: string): {
8
- apiToken: string;
9
- };
10
- };
11
-
12
- const WashdayClient: WashdayClientConstructor = function WashdayClient(this: WashdayClientInstance, apiToken: string) {
13
- this.apiToken = apiToken;
14
- WashdayClient.prototype.customers.apiToken = apiToken;
15
- WashdayClient.prototype.stores.apiToken = apiToken;
16
- } as any;
17
-
18
- WashdayClient.prototype.customers = {
19
- getCustomerById: getCustomerById,
20
- getCustomerHighlightsById: getCustomerHighlightsById
21
- };
22
-
23
- WashdayClient.prototype.stores = {
24
- getStores: getStores,
25
- getStoreById: getStoreById,
26
- updateStoreById: updateStoreById
27
- };
28
-
29
- export default WashdayClient;
1
+ import { WashdayClientInstance } from "../interfaces/Api";
2
+ import { getCustomerById, getCustomerHighlightsById } from "./customers/get";
3
+ import { bulkUpdate } from "./products/put";
4
+ import { getStoreById, getStores } from "./stores/get";
5
+ import { createStoreImage } from "./stores/post";
6
+ import { updateStoreById } from "./stores/put";
7
+
8
+ type WashdayClientConstructor = {
9
+ new(apiToken: string): {
10
+ apiToken: string;
11
+ };
12
+ };
13
+
14
+ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: WashdayClientInstance, apiToken: string) {
15
+ this.apiToken = apiToken;
16
+ WashdayClient.prototype.customers.apiToken = apiToken;
17
+ WashdayClient.prototype.stores.apiToken = apiToken;
18
+ } as any;
19
+
20
+ WashdayClient.prototype.customers = {
21
+ getCustomerById: getCustomerById,
22
+ getCustomerHighlightsById: getCustomerHighlightsById
23
+ };
24
+
25
+ WashdayClient.prototype.stores = {
26
+ getStores: getStores,
27
+ getStoreById: getStoreById,
28
+ updateStoreById: updateStoreById,
29
+ createStoreImage: createStoreImage
30
+ };
31
+
32
+
33
+ WashdayClient.prototype.products = {
34
+ bulkUpdate: bulkUpdate,
35
+ };
36
+
37
+ export default WashdayClient;
@@ -0,0 +1,9 @@
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+ import { IStore } from "../../interfaces/Store";
3
+ import axiosInstance from "../axiosInstance";
4
+
5
+ export const GET_SET_PRODUCTS = 'api/product';
6
+ const REQUEST_PARAMS = {
7
+ token: 'LOGGED_USER_TOKEN',
8
+ };
9
+
@@ -0,0 +1,11 @@
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+ import { IStore } from "../../interfaces/Store";
3
+ import axiosInstance from "../axiosInstance";
4
+
5
+ const GET_SET_STORES = 'api/store';
6
+ const GET_SET_STORE_IMAGE = 'api/store-image';
7
+
8
+ const REQUEST_PARAMS = {
9
+ token: 'LOGGED_USER_TOKEN',
10
+ };
11
+