Skip to content

Commit

Permalink
feat: allow to calc sub state in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Sep 3, 2022
1 parent a8817f5 commit 2bba501
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class Subscriptions {
}

await this._storage.put(ids, subscriptionModel)

return {
passthrough: {
v1: {
ids
}
}
}
}

/**
Expand Down Expand Up @@ -208,19 +216,21 @@ class Subscriptions {
/**
*
* @param {Object} subscription
* @param {Date} [atDate=new Date()] date for the calculation
* @returns {boolean} true subscription is active
*/
async isSubscriptionActive(subscription) {
return this._isOneOfSubscriptionsActive([subscription])
async isSubscriptionActive(subscription, atDate = new Date()) {
return this._isOneOfSubscriptionsActive([subscription], atDate)
}

/**
*
* @param {Array} subscriptions
* @param {Date} [atDate=new Date()] date for the calculation
* @returns {boolean} true if an active subscription was given
*/
async _isOneOfSubscriptionsActive(subscriptions) {
const now = Date.now()
async _isOneOfSubscriptionsActive(subscriptions, atDate) {
const now = atDate.getTime()

const allStatus = subscriptions.map(subscription => {
// filter all status object that have a start date in the past
Expand Down

0 comments on commit 2bba501

Please sign in to comment.