-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-subscription.js
More file actions
56 lines (49 loc) · 1.73 KB
/
update-subscription.js
File metadata and controls
56 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Script to manually update subscription status
require('dotenv').config();
const { pool } = require('@vercel/postgres');
const moment = require('moment');
async function updateSubscription() {
// Get your email from command line arguments or environment
const email = process.argv[2] || process.env.USER_EMAIL;
if (!email) {
console.error('Please provide an email address as argument: node update-subscription.js your-email@example.com');
process.exit(1);
}
const client = await pool.connect();
try {
console.log(`Updating subscription for ${email}...`);
// Check if user already has a subscription
const checkResult = await client.query(
'SELECT * FROM "user_subscription" WHERE email = $1',
[email]
);
if (checkResult.rows.length > 0) {
// Update existing subscription
await client.query(
`UPDATE "user_subscription"
SET active = true,
subscription_id = $1,
payment_id = $2,
expiry_date = $3
WHERE email = $4`,
['sub_QBvjRyP9t5pF4N', 'manual_update', '28/04/2025', email]
);
console.log('Subscription updated successfully!');
} else {
// Insert new subscription
await client.query(
`INSERT INTO "user_subscription"
(email, user_name, active, payment_id, subscription_id, join_date, expiry_date)
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
[email, 'User', true, 'manual_update', 'sub_QBvjRyP9t5pF4N',
moment().format('DD/MM/yyyy'), '28/04/2025']
);
console.log('Subscription created successfully!');
}
} catch (error) {
console.error('Error updating subscription:', error);
} finally {
client.release();
}
}
updateSubscription();