Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint ."
"lint": "eslint .",
"setup-stripe": "dotenv -e .env -- node scripts/setup-stripe.js",
"check-plans": "dotenv -e .env -- node scripts/check-active-plans.js",
"update-plans": "dotenv -e .env -- node scripts/update-plan-durations.js"
},
"devDependencies": {
"@iconify/svelte": "^3.1.4",
Expand All @@ -17,6 +20,7 @@
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"autoprefixer": "^10.4.15",
"dotenv-cli": "^8.0.0",
"eslint": "^8.28.0",
"eslint-plugin-svelte": "^2.30.0",
"mongodb": "^5.7.0",
Expand All @@ -34,7 +38,7 @@
"@google/generative-ai": "^0.21.0",
"@sveltejs/adapter-auto": "^2.1.1",
"@sveltejs/adapter-node": "^1.3.1",
"dotenv": "^16.3.1",
"dotenv": "^16.4.7",
"node-fetch": "^3.3.2",
"node-telegram-bot-api": "^0.61.0"
}
Expand Down
80 changes: 80 additions & 0 deletions scripts/update-plan-durations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { MongoClient } from 'mongodb';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Load environment variables from .env
dotenv.config({ path: resolve(__dirname, '../.env') });

if (!process.env.MONGO_URI) {
console.error('MONGO_URI is not defined in .env');
process.exit(1);
}

const uri = process.env.MONGO_URI;
const client = new MongoClient(uri);

const PLAN_LIMITS = {
weekend: {
maxDays: 7
},
vacation: {
maxDays: 14
},
extended: {
maxDays: 30
}
};

async function updatePlanDurations() {
try {
await client.connect();
console.log('Connected to MongoDB');

const db = client.db('splitgram');
const now = new Date();

// Find all users with active plans
const usersWithPlans = await db.collection('users').find({
'plan.expires_at': { $gt: now }
}).toArray();

console.log('\nActive Plans:', usersWithPlans.length);

for (const user of usersWithPlans) {
const planType = user.plan.type;
const startDate = new Date(user.plan.started_at);

// Calculate new expiry based on new durations
const newExpiryDate = new Date(startDate);
newExpiryDate.setDate(startDate.getDate() + PLAN_LIMITS[planType].maxDays);

console.log('\nUpdating plan for user:', user.id);
console.log('Plan Type:', planType);
console.log('Started:', startDate.toLocaleString());
console.log('Old Expiry:', new Date(user.plan.expires_at).toLocaleString());
console.log('New Expiry:', newExpiryDate.toLocaleString());

// Update the expiration date
const result = await db.collection('users').updateOne(
{ id: user.id },
{
$set: {
'plan.expires_at': newExpiryDate
}
}
);

console.log('Update result:', result.modifiedCount === 1 ? 'Success' : 'Failed');
console.log('---');
}

} finally {
await client.close();
}
}

updatePlanDurations().catch(console.error);
Loading