washday-sdk 0.0.8 → 0.0.10
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/babel.config.js +8 -0
- package/dist/api/axiosInstance.js +42 -42
- package/dist/api/customers/get.js +48 -48
- package/dist/api/customers/index.js +1 -1
- package/dist/api/index.js +12 -12
- package/dist/enum/index.js +15 -15
- package/dist/index.js +33 -33
- package/dist/interfaces/Api.js +2 -2
- package/dist/interfaces/Company.js +1 -1
- package/dist/interfaces/Customer.js +2 -2
- package/dist/interfaces/Order.js +2 -2
- package/dist/interfaces/Permission.js +2 -2
- package/dist/interfaces/Product.js +2 -2
- package/dist/interfaces/Section.js +2 -2
- package/dist/interfaces/Store.js +2 -2
- package/dist/interfaces/StoreImage.js +2 -2
- package/dist/interfaces/User.js +2 -2
- package/dist/utils/index.js +17 -17
- package/dist/utils/orders/calculateOrderTotal.js +33 -33
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +65 -65
- package/dist/utils/orders/calculateTotalTaxesOverPrice.js +74 -74
- package/dist/utils/orders/helpers.js +64 -64
- package/dist/utils/orders/index.js +5 -5
- package/jest.config.js +0 -0
- package/package.json +28 -23
- package/src/api/axiosInstance.ts +45 -45
- package/src/api/customers/get.ts +32 -32
- package/src/api/index.ts +26 -21
- package/src/api/stores/get.ts +33 -0
- package/src/enum/index.ts +10 -10
- package/src/index.ts +4 -4
- package/src/interfaces/Api.ts +2 -2
- package/src/interfaces/Customer.ts +51 -51
- package/src/interfaces/Order.ts +95 -95
- package/src/interfaces/Permission.ts +24 -24
- package/src/interfaces/Product.ts +58 -58
- package/src/interfaces/Section.ts +14 -14
- package/src/interfaces/Store.ts +350 -350
- package/src/interfaces/StoreImage.ts +9 -9
- package/src/interfaces/User.ts +42 -42
- package/src/utils/index.ts +1 -1
- package/src/utils/orders/calculateOrderTotal.test.js +399 -0
- package/src/utils/orders/calculateOrderTotal.ts +60 -60
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +75 -75
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +82 -82
- package/src/utils/orders/helpers.ts +73 -73
- package/src/utils/orders/index.ts +4 -4
- package/tsconfig.json +9 -9
package/babel.config.js
ADDED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
// Define the type for the Axios instance
|
|
8
|
-
let axiosInstance = null;
|
|
9
|
-
const BASE_URL = 'https://washday-backend.herokuapp.com/';
|
|
10
|
-
// Function to create or return the singleton instance
|
|
11
|
-
const getAxiosInstance = () => {
|
|
12
|
-
if (!axiosInstance) {
|
|
13
|
-
axiosInstance = axios_1.default.create({
|
|
14
|
-
baseURL: BASE_URL,
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
// Add any default headers here
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
// Add interceptor to set token and other options for every request
|
|
21
|
-
axiosInstance.interceptors.request.use((config) => {
|
|
22
|
-
const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
|
|
23
|
-
if (token) {
|
|
24
|
-
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
-
}
|
|
26
|
-
if (contentType) {
|
|
27
|
-
config.headers['Content-Type'] = contentType;
|
|
28
|
-
}
|
|
29
|
-
if (responseType) {
|
|
30
|
-
config.responseType = responseType;
|
|
31
|
-
}
|
|
32
|
-
if (contentDisposition) {
|
|
33
|
-
config.headers['Content-Disposition'] = contentDisposition;
|
|
34
|
-
}
|
|
35
|
-
return config;
|
|
36
|
-
}, (error) => {
|
|
37
|
-
return Promise.reject(error);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return axiosInstance;
|
|
41
|
-
};
|
|
42
|
-
exports.default = getAxiosInstance();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
// Define the type for the Axios instance
|
|
8
|
+
let axiosInstance = null;
|
|
9
|
+
const BASE_URL = 'https://washday-backend.herokuapp.com/';
|
|
10
|
+
// Function to create or return the singleton instance
|
|
11
|
+
const getAxiosInstance = () => {
|
|
12
|
+
if (!axiosInstance) {
|
|
13
|
+
axiosInstance = axios_1.default.create({
|
|
14
|
+
baseURL: BASE_URL,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
// Add any default headers here
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
// Add interceptor to set token and other options for every request
|
|
21
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
22
|
+
const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
|
|
23
|
+
if (token) {
|
|
24
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
if (contentType) {
|
|
27
|
+
config.headers['Content-Type'] = contentType;
|
|
28
|
+
}
|
|
29
|
+
if (responseType) {
|
|
30
|
+
config.responseType = responseType;
|
|
31
|
+
}
|
|
32
|
+
if (contentDisposition) {
|
|
33
|
+
config.headers['Content-Disposition'] = contentDisposition;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
}, (error) => {
|
|
37
|
+
return Promise.reject(error);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return axiosInstance;
|
|
41
|
+
};
|
|
42
|
+
exports.default = getAxiosInstance();
|
|
@@ -1,48 +1,48 @@
|
|
|
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.getCustomerHighlightsById = exports.getCustomerById = void 0;
|
|
16
|
-
const axiosInstance_1 = __importDefault(require("../axiosInstance"));
|
|
17
|
-
const GET_SET_CUSTOMERS = 'api/customer';
|
|
18
|
-
const REQUEST_PARAMS = {
|
|
19
|
-
token: 'LOGGED_USER_TOKEN',
|
|
20
|
-
};
|
|
21
|
-
const getCustomerById = function (customerId) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
try {
|
|
24
|
-
REQUEST_PARAMS.token = this.apiToken;
|
|
25
|
-
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: Object.assign({}, REQUEST_PARAMS) });
|
|
26
|
-
return response.data;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Error fetching customer:', error);
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
exports.getCustomerById = getCustomerById;
|
|
35
|
-
const getCustomerHighlightsById = function (customerId) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
try {
|
|
38
|
-
REQUEST_PARAMS.token = this.apiToken;
|
|
39
|
-
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: Object.assign({}, REQUEST_PARAMS) });
|
|
40
|
-
return response.data;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error('Error fetching customer:', error);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
exports.getCustomerHighlightsById = getCustomerHighlightsById;
|
|
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.getCustomerHighlightsById = exports.getCustomerById = void 0;
|
|
16
|
+
const axiosInstance_1 = __importDefault(require("../axiosInstance"));
|
|
17
|
+
const GET_SET_CUSTOMERS = 'api/customer';
|
|
18
|
+
const REQUEST_PARAMS = {
|
|
19
|
+
token: 'LOGGED_USER_TOKEN',
|
|
20
|
+
};
|
|
21
|
+
const getCustomerById = function (customerId) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
try {
|
|
24
|
+
REQUEST_PARAMS.token = this.apiToken;
|
|
25
|
+
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: Object.assign({}, REQUEST_PARAMS) });
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error fetching customer:', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.getCustomerById = getCustomerById;
|
|
35
|
+
const getCustomerHighlightsById = function (customerId) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
try {
|
|
38
|
+
REQUEST_PARAMS.token = this.apiToken;
|
|
39
|
+
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: Object.assign({}, REQUEST_PARAMS) });
|
|
40
|
+
return response.data;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Error fetching customer:', error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.getCustomerHighlightsById = getCustomerHighlightsById;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
package/dist/api/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const get_1 = require("./customers/get");
|
|
4
|
-
const WashdayClient = function WashdayClient(apiToken) {
|
|
5
|
-
this.apiToken = apiToken;
|
|
6
|
-
WashdayClient.prototype.customers.apiToken = apiToken;
|
|
7
|
-
};
|
|
8
|
-
WashdayClient.prototype.customers = {
|
|
9
|
-
getCustomerById: get_1.getCustomerById,
|
|
10
|
-
getCustomerHighlightsById: get_1.getCustomerHighlightsById
|
|
11
|
-
};
|
|
12
|
-
exports.default = WashdayClient;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const get_1 = require("./customers/get");
|
|
4
|
+
const WashdayClient = function WashdayClient(apiToken) {
|
|
5
|
+
this.apiToken = apiToken;
|
|
6
|
+
WashdayClient.prototype.customers.apiToken = apiToken;
|
|
7
|
+
};
|
|
8
|
+
WashdayClient.prototype.customers = {
|
|
9
|
+
getCustomerById: get_1.getCustomerById,
|
|
10
|
+
getCustomerHighlightsById: get_1.getCustomerHighlightsById
|
|
11
|
+
};
|
|
12
|
+
exports.default = WashdayClient;
|
package/dist/enum/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BuyAndGetConditionsTypes = exports.DiscountCodeTypes = void 0;
|
|
4
|
-
var DiscountCodeTypes;
|
|
5
|
-
(function (DiscountCodeTypes) {
|
|
6
|
-
DiscountCodeTypes["PERCENTAGE"] = "percentage";
|
|
7
|
-
DiscountCodeTypes["NUMBER"] = "number";
|
|
8
|
-
DiscountCodeTypes["FREE_DELIVERY"] = "freeDelivery";
|
|
9
|
-
DiscountCodeTypes["BUY_X_GET_Y"] = "buyXGetY";
|
|
10
|
-
})(DiscountCodeTypes || (exports.DiscountCodeTypes = DiscountCodeTypes = {}));
|
|
11
|
-
var BuyAndGetConditionsTypes;
|
|
12
|
-
(function (BuyAndGetConditionsTypes) {
|
|
13
|
-
BuyAndGetConditionsTypes["PERCENTAGE"] = "percentage";
|
|
14
|
-
BuyAndGetConditionsTypes["FREE"] = "free";
|
|
15
|
-
})(BuyAndGetConditionsTypes || (exports.BuyAndGetConditionsTypes = BuyAndGetConditionsTypes = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuyAndGetConditionsTypes = exports.DiscountCodeTypes = void 0;
|
|
4
|
+
var DiscountCodeTypes;
|
|
5
|
+
(function (DiscountCodeTypes) {
|
|
6
|
+
DiscountCodeTypes["PERCENTAGE"] = "percentage";
|
|
7
|
+
DiscountCodeTypes["NUMBER"] = "number";
|
|
8
|
+
DiscountCodeTypes["FREE_DELIVERY"] = "freeDelivery";
|
|
9
|
+
DiscountCodeTypes["BUY_X_GET_Y"] = "buyXGetY";
|
|
10
|
+
})(DiscountCodeTypes || (exports.DiscountCodeTypes = DiscountCodeTypes = {}));
|
|
11
|
+
var BuyAndGetConditionsTypes;
|
|
12
|
+
(function (BuyAndGetConditionsTypes) {
|
|
13
|
+
BuyAndGetConditionsTypes["PERCENTAGE"] = "percentage";
|
|
14
|
+
BuyAndGetConditionsTypes["FREE"] = "free";
|
|
15
|
+
})(BuyAndGetConditionsTypes || (exports.BuyAndGetConditionsTypes = BuyAndGetConditionsTypes = {}));
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.utils = exports.WashdayClient = void 0;
|
|
30
|
-
const utils = __importStar(require("./utils"));
|
|
31
|
-
exports.utils = utils;
|
|
32
|
-
const api_1 = __importDefault(require("./api"));
|
|
33
|
-
exports.WashdayClient = api_1.default;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.utils = exports.WashdayClient = void 0;
|
|
30
|
+
const utils = __importStar(require("./utils"));
|
|
31
|
+
exports.utils = utils;
|
|
32
|
+
const api_1 = __importDefault(require("./api"));
|
|
33
|
+
exports.WashdayClient = api_1.default;
|
package/dist/interfaces/Api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/interfaces/Order.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/interfaces/Store.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/interfaces/User.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/utils/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./orders"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./orders"), exports);
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateOrderTotal = void 0;
|
|
4
|
-
const enum_1 = require("../../enum");
|
|
5
|
-
const calculateTotalTaxesIncluded_1 = require("./calculateTotalTaxesIncluded");
|
|
6
|
-
const calculateTotalTaxesOverPrice_1 = require("./calculateTotalTaxesOverPrice");
|
|
7
|
-
const helpers_1 = require("./helpers");
|
|
8
|
-
const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasShippingCost, storeDiscounts = [], discountCodeObj) => {
|
|
9
|
-
var _a;
|
|
10
|
-
try {
|
|
11
|
-
const appliedOrderDiscounts = {};
|
|
12
|
-
const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price' ? calculateTotalTaxesOverPrice_1.calculateTotalTaxesOverPrice : calculateTotalTaxesIncluded_1.calculateTotalTaxesIncluded;
|
|
13
|
-
const productTableImports = productTableCalculator(order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj);
|
|
14
|
-
// PRODUCT LINE TOTALS
|
|
15
|
-
const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount } = (0, helpers_1.getProductLineTotals)(productTableImports);
|
|
16
|
-
// DISCOUNT TOTAL AND SHIPPING SERVICE COST
|
|
17
|
-
let discountCodeAmount = 0;
|
|
18
|
-
let shippingCost = (0, helpers_1.getShippingCost)(discountCodeObj, hasShippingCost, storeSettings);
|
|
19
|
-
if (discountCodeObj && discountCodeObj.type === enum_1.DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
|
|
20
|
-
const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr) => discountCodeObj.products.includes(curr._id));
|
|
21
|
-
discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
|
|
22
|
-
}
|
|
23
|
-
// ORDER TOTAL CALCULATION AND CREDIT APPLIED
|
|
24
|
-
let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
|
|
25
|
-
let creditApplied = (0, helpers_1.getCreditApplied)(selectedCustomer, orderTotalWithOutCredit);
|
|
26
|
-
let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
|
|
27
|
-
return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts });
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.calculateOrderTotal = calculateOrderTotal;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateOrderTotal = void 0;
|
|
4
|
+
const enum_1 = require("../../enum");
|
|
5
|
+
const calculateTotalTaxesIncluded_1 = require("./calculateTotalTaxesIncluded");
|
|
6
|
+
const calculateTotalTaxesOverPrice_1 = require("./calculateTotalTaxesOverPrice");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasShippingCost, storeDiscounts = [], discountCodeObj) => {
|
|
9
|
+
var _a;
|
|
10
|
+
try {
|
|
11
|
+
const appliedOrderDiscounts = {};
|
|
12
|
+
const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price' ? calculateTotalTaxesOverPrice_1.calculateTotalTaxesOverPrice : calculateTotalTaxesIncluded_1.calculateTotalTaxesIncluded;
|
|
13
|
+
const productTableImports = productTableCalculator(order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj);
|
|
14
|
+
// PRODUCT LINE TOTALS
|
|
15
|
+
const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount } = (0, helpers_1.getProductLineTotals)(productTableImports);
|
|
16
|
+
// DISCOUNT TOTAL AND SHIPPING SERVICE COST
|
|
17
|
+
let discountCodeAmount = 0;
|
|
18
|
+
let shippingCost = (0, helpers_1.getShippingCost)(discountCodeObj, hasShippingCost, storeSettings);
|
|
19
|
+
if (discountCodeObj && discountCodeObj.type === enum_1.DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
|
|
20
|
+
const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr) => discountCodeObj.products.includes(curr._id));
|
|
21
|
+
discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
|
|
22
|
+
}
|
|
23
|
+
// ORDER TOTAL CALCULATION AND CREDIT APPLIED
|
|
24
|
+
let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
|
|
25
|
+
let creditApplied = (0, helpers_1.getCreditApplied)(selectedCustomer, orderTotalWithOutCredit);
|
|
26
|
+
let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
|
|
27
|
+
return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.calculateOrderTotal = calculateOrderTotal;
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateTotalTaxesIncluded = void 0;
|
|
4
|
-
const helpers_1 = require("./helpers");
|
|
5
|
-
const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
|
|
6
|
-
const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
|
|
7
|
-
var _a, _b;
|
|
8
|
-
let discPercentageInteger = 0;
|
|
9
|
-
let productPercentageDiscount = 0;
|
|
10
|
-
let customerDiscount = 0;
|
|
11
|
-
let qty = current.qty || 0;
|
|
12
|
-
const extraAmountPerUnit = current.extraAmount / qty;
|
|
13
|
-
const prodPrice = (order.express ? current.expressPrice : current.price) + extraAmountPerUnit;
|
|
14
|
-
if (!order.discountCode) {
|
|
15
|
-
const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
|
|
16
|
-
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
17
|
-
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
18
|
-
if (next.type === 'percentage') {
|
|
19
|
-
return prev + next.value;
|
|
20
|
-
}
|
|
21
|
-
return prev;
|
|
22
|
-
}, 0);
|
|
23
|
-
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
24
|
-
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'percentage') {
|
|
28
|
-
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
29
|
-
if (!discountCodeObj.applyToAllProducts) {
|
|
30
|
-
discPercentageInteger = ((_b = discountCodeObj.products) === null || _b === void 0 ? void 0 : _b.includes(current._id))
|
|
31
|
-
? +(discountCodeObj.value / 100).toFixed(2)
|
|
32
|
-
: 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'buyXGetY') {
|
|
36
|
-
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
37
|
-
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
38
|
-
if (discountType === 'percentage' && current.isBuyAndGetProduct) {
|
|
39
|
-
discPercentageInteger = +(discountValue / 100).toFixed(2);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const taxPercentage = (0, helpers_1.getProductTaxesPercentage)(current, storeSettings);
|
|
44
|
-
const taxPercentageInteger = taxPercentage / 100;
|
|
45
|
-
const unitPrice = prodPrice / (1 + taxPercentageInteger);
|
|
46
|
-
const discountAmountPerUnit = discPercentageInteger
|
|
47
|
-
? unitPrice * discPercentageInteger
|
|
48
|
-
: (current.discountAmount || 0) / (1 + taxPercentageInteger);
|
|
49
|
-
const prodPriceWithDiscountPerUnit = unitPrice - discountAmountPerUnit;
|
|
50
|
-
const taxesAmountPerUnit = prodPriceWithDiscountPerUnit * taxPercentageInteger;
|
|
51
|
-
const totalTaxesApplied = +(taxesAmountPerUnit * qty).toFixed(2);
|
|
52
|
-
const lineDiscount = qty * discountAmountPerUnit;
|
|
53
|
-
const prodLinePriceWithDiscount = +(qty * prodPriceWithDiscountPerUnit).toFixed(2);
|
|
54
|
-
return {
|
|
55
|
-
product: current,
|
|
56
|
-
qty: qty,
|
|
57
|
-
productLineImportTotal: unitPrice * qty,
|
|
58
|
-
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
59
|
-
productLineTaxesTotal: totalTaxesApplied,
|
|
60
|
-
lineDiscountAmount: lineDiscount
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
return productTableImports;
|
|
64
|
-
};
|
|
65
|
-
exports.calculateTotalTaxesIncluded = calculateTotalTaxesIncluded;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateTotalTaxesIncluded = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
|
|
6
|
+
const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
let discPercentageInteger = 0;
|
|
9
|
+
let productPercentageDiscount = 0;
|
|
10
|
+
let customerDiscount = 0;
|
|
11
|
+
let qty = current.qty || 0;
|
|
12
|
+
const extraAmountPerUnit = current.extraAmount / qty;
|
|
13
|
+
const prodPrice = (order.express ? current.expressPrice : current.price) + extraAmountPerUnit;
|
|
14
|
+
if (!order.discountCode) {
|
|
15
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
|
|
16
|
+
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
17
|
+
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
18
|
+
if (next.type === 'percentage') {
|
|
19
|
+
return prev + next.value;
|
|
20
|
+
}
|
|
21
|
+
return prev;
|
|
22
|
+
}, 0);
|
|
23
|
+
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
24
|
+
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'percentage') {
|
|
28
|
+
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
29
|
+
if (!discountCodeObj.applyToAllProducts) {
|
|
30
|
+
discPercentageInteger = ((_b = discountCodeObj.products) === null || _b === void 0 ? void 0 : _b.includes(current._id))
|
|
31
|
+
? +(discountCodeObj.value / 100).toFixed(2)
|
|
32
|
+
: 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'buyXGetY') {
|
|
36
|
+
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
37
|
+
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
38
|
+
if (discountType === 'percentage' && current.isBuyAndGetProduct) {
|
|
39
|
+
discPercentageInteger = +(discountValue / 100).toFixed(2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const taxPercentage = (0, helpers_1.getProductTaxesPercentage)(current, storeSettings);
|
|
44
|
+
const taxPercentageInteger = taxPercentage / 100;
|
|
45
|
+
const unitPrice = prodPrice / (1 + taxPercentageInteger);
|
|
46
|
+
const discountAmountPerUnit = discPercentageInteger
|
|
47
|
+
? unitPrice * discPercentageInteger
|
|
48
|
+
: (current.discountAmount || 0) / (1 + taxPercentageInteger);
|
|
49
|
+
const prodPriceWithDiscountPerUnit = unitPrice - discountAmountPerUnit;
|
|
50
|
+
const taxesAmountPerUnit = prodPriceWithDiscountPerUnit * taxPercentageInteger;
|
|
51
|
+
const totalTaxesApplied = +(taxesAmountPerUnit * qty).toFixed(2);
|
|
52
|
+
const lineDiscount = qty * discountAmountPerUnit;
|
|
53
|
+
const prodLinePriceWithDiscount = +(qty * prodPriceWithDiscountPerUnit).toFixed(2);
|
|
54
|
+
return {
|
|
55
|
+
product: current,
|
|
56
|
+
qty: qty,
|
|
57
|
+
productLineImportTotal: unitPrice * qty,
|
|
58
|
+
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
59
|
+
productLineTaxesTotal: totalTaxesApplied,
|
|
60
|
+
lineDiscountAmount: lineDiscount
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return productTableImports;
|
|
64
|
+
};
|
|
65
|
+
exports.calculateTotalTaxesIncluded = calculateTotalTaxesIncluded;
|