@darkpos/pricing 1.0.150 → 1.0.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- module.exports = ({ actions, modifierActions }) => {
1
+ module.exports = ({ actions, modifierActions, _ }) => {
2
2
  const getRemaining = (subscriptions, orderId) => {
3
3
  const remaining = subscriptions.reduce((total, subscription) => {
4
- const { usesLimit = 0, uses = 0, history = {} } = subscription;
4
+ const { usesLimit = 0, uses = 0, history = {} } = subscription.item || {};
5
5
  const orderHistory = history[orderId] || 0;
6
6
  return total + usesLimit + orderHistory - uses;
7
7
  }, 0);
@@ -37,8 +37,18 @@ module.exports = ({ actions, modifierActions }) => {
37
37
 
38
38
  const getSubscriptions = subscriptions =>
39
39
  subscriptions
40
- .map(each => modifierActions.getSubscriptionItem(each))
41
- .filter(Boolean);
40
+ .map(each => _.get(each, 'properties.subscription'))
41
+ .filter(Boolean)
42
+ .filter(each => {
43
+ const renewalType = _.get(each, 'item.renewalType');
44
+ const endDate = _.get(each, 'dateLimit.to');
45
+ const today = new Date();
46
+
47
+ if (renewalType === 'none' && endDate && new Date(endDate) < today)
48
+ return false;
49
+
50
+ return true;
51
+ });
42
52
 
43
53
  return function hasRemainingSubscription({ order, item }) {
44
54
  if (!order || !item || !item.itemId) return [false];
@@ -53,7 +63,9 @@ module.exports = ({ actions, modifierActions }) => {
53
63
  subscriptions = getSubscriptions(subscriptions);
54
64
 
55
65
  const isUnlimited = subscriptions.some(
56
- each => !each.usesLimit || each.renewalType === 'limit_reached'
66
+ each =>
67
+ !_.get(each, 'item.usesLimit') ||
68
+ _.get(each, 'item.renewalType') === 'limit_reached'
57
69
  );
58
70
  if (isUnlimited) return [true];
59
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.150",
3
+ "version": "1.0.151",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -54,5 +54,5 @@
54
54
  "supertest": "^6.2.3",
55
55
  "supervisor": "^0.12.0"
56
56
  },
57
- "gitHead": "5ba2aa85fa455644dfa228072d30f8a8560d161c"
57
+ "gitHead": "f95dc7f14dcf4673e5fe25cb2faeb5eee26fb592"
58
58
  }