foodbot-cart-calculations 1.0.0 → 1.0.2-dev.1

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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.0",
3
+ "version": "1.0.2-dev.1",
4
4
  "description": "Package for cart calculations in which it performs discount distribution and tax distribution on order",
5
- "main": "main.js",
5
+ "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "npm start"
8
8
  },
package/main.js DELETED
@@ -1,77 +0,0 @@
1
- const calculation = require('./calculations');
2
- async function calculateTax(inputJSON) {
3
- return new Promise(async (resolve, reject) => {
4
- try {
5
- const requiredFields = ['tax_type', 'order_items', 'tax_settings'];
6
- const missingFields = [];
7
- for (const field of requiredFields) {
8
- if (!inputJSON || !inputJSON[field]) {
9
- missingFields.push(field);
10
- }
11
- }
12
- if (missingFields.length > 0) {
13
- resolve({
14
- 'status': 'fail',
15
- 'status_code': 400,
16
- 'message': 'Field required',
17
- 'missing_fields': missingFields,
18
- });
19
- } else {
20
- let continueFlag = true;
21
- if (inputJSON.promotion_applied) {
22
- const promotionKeys = ['offer_discount_type', 'oo_offer_value', 'offer_id'];
23
- const missingPromotionKeys = promotionKeys.filter(key => !inputJSON.promotion_applied[key]);
24
- if (missingPromotionKeys.length > 0) {
25
- continueFlag = false;
26
- resolve({
27
- 'status': 'fail',
28
- 'status_code': 400,
29
- 'message': 'Field required for promotion_applied',
30
- 'missing_fields': missingPromotionKeys,
31
- });
32
- }
33
- }
34
- if (continueFlag) {
35
- calculation.applyDistribution(inputJSON).then(result => {
36
- const optionalFields = ['order_type', 'restaurant_id', 'branch_id', 'request_id'];
37
- const missingOptionalFields = optionalFields.filter(field => !inputJSON[field]);
38
- if (missingOptionalFields.length > 0) {
39
- resolve({
40
- 'status': 'success',
41
- 'status_code': 201,
42
- 'message': 'Tax calculated successfully with few details missing',
43
- 'missing_optional_fields': missingOptionalFields,
44
- 'data': result
45
- });
46
- } else {
47
- resolve({
48
- 'status': 'success',
49
- 'status_code': 200,
50
- 'message': 'Tax calculated successfully',
51
- 'data': result
52
- });
53
- }
54
- }).catch(err => {
55
- resolve({
56
- "status": 'fail',
57
- "status_code": 500,
58
- "message": 'Error during tax calculation',
59
- "error": err.stack,
60
- });
61
- })
62
- }
63
- }
64
- } catch (error) {
65
- resolve({
66
- 'status': 'error',
67
- 'status_code': 500,
68
- 'message': 'Internal server error',
69
- 'error': error.stack,
70
- });
71
- }
72
- })
73
- }
74
-
75
- module.exports = { calculateTax }
76
-
77
-