Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit 76012fe

Browse files
committed
feat: allow to calc sub state in the future
1 parent 6999310 commit 76012fe

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/index.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ class Subscriptions {
107107
}
108108

109109
await this._storage.put(ids, subscriptionModel)
110+
111+
return {
112+
passthrough: {
113+
v1: {
114+
ids
115+
}
116+
}
117+
}
110118
}
111119

112120
/**
@@ -208,19 +216,21 @@ class Subscriptions {
208216
/**
209217
*
210218
* @param {Object} subscription
219+
* @param {Date} [atDate=new Date()] date for the calculation
211220
* @returns {boolean} true subscription is active
212221
*/
213-
async isSubscriptionActive(subscription) {
214-
return this._isOneOfSubscriptionsActive([subscription])
222+
async isSubscriptionActive(subscription, atDate = new Date()) {
223+
return this._isOneOfSubscriptionsActive([subscription], atDate)
215224
}
216225

217226
/**
218227
*
219228
* @param {Array} subscriptions
229+
* @param {Date} [atDate=new Date()] date for the calculation
220230
* @returns {boolean} true if an active subscription was given
221231
*/
222-
async _isOneOfSubscriptionsActive(subscriptions) {
223-
const now = Date.now()
232+
async _isOneOfSubscriptionsActive(subscriptions, atDate) {
233+
const now = atDate.getTime()
224234

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

0 commit comments

Comments
 (0)