Skip to content

Commit

Permalink
Add one day to subscription expiration, to account for the day the cr…
Browse files Browse the repository at this point in the history
…on runs.
  • Loading branch information
BrunoBernardino committed Nov 14, 2023
1 parent c466ed0 commit 6332764
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crons/check-subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { User, UserSession } from '/lib/types.ts';

const db = new Database();

const oneDayInSeconds = 86_400;

async function checkSubscriptions() {
try {
const users = await db.query<User>(
Expand Down Expand Up @@ -37,7 +39,8 @@ async function checkSubscriptions() {

matchingUser.subscription.isMonthly = subscription.items.data.some((item) => item.price.id.includes('monthly'));
matchingUser.subscription.updated_at = new Date().toISOString();
matchingUser.subscription.expires_at = new Date(subscription.current_period_end * 1000).toISOString();
matchingUser.subscription.expires_at = new Date((subscription.current_period_end + oneDayInSeconds) * 1000)
.toISOString();

if (['active', 'paused'].includes(subscription.status)) {
matchingUser.status = 'active';
Expand Down

0 comments on commit 6332764

Please sign in to comment.