/api/maintenance/database-stats
Get database statistics including user, subscription, promotion, and coupon counts (requires administrator access)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr...
Response (200 OK):
{
"users": {
"total": 1523,
"active": 1450,
"subscribers": 890,
"nonSubscribers": 560,
"admins": 3
},
"subscriptions": {
"total": 920,
"active": 890,
"cancelled": 25,
"pastDue": 5
},
"promotions": {
"total": 45,
"active": 32,
"totalRedemptions": 478
},
"coupons": {
"total": 12,
"active": 8
},
"timestamp": "2024-01-15T10:30:00.000Z"
}
Error Responses:
{
"message": "Administrator access required"
}
Notes:
total - Total number of users in the systemactive - Number of users with is_active = truesubscribers - Number of users with user_type_code = 'SUBS'nonSubscribers - Number of users with user_type_code = 'NONS'admins - Number of users with user_type_code = 'ADMI'total - Total number of subscriptionsactive - Number of subscriptions with status = 'active'cancelled - Number of subscriptions with status = 'canceled'pastDue - Number of subscriptions with status = 'past_due'total - Total number of promotionsactive - Number of promotions with is_active = truetotalRedemptions - Sum of all redemption_count values across all promotionstotal - Total number of couponsactive - Number of coupons with is_active = true/api/maintenance/system-info
Get system information including database and server stats (requires administrator access)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr...
Response (200 OK):
{
"database": {
"version": "1.11",
"connectionStatus": "connected",
"poolSize": 20,
"activeConnections": 5
},
"server": {
"nodeVersion": "v18.17.0",
"uptime": 86400,
"memoryUsage": {
"heapUsed": 45,
"heapTotal": 60,
"external": 2,
"rss": 120
}
},
"timestamp": "2024-01-15T10:30:00.000Z"
}
Error Responses:
{
"message": "Administrator access required"
}
Notes:
/api/maintenance/activate-subscriptions
Activate subscriptions for NONS users who don't have NONS promotions applied (requires administrator access and CSRF token)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr... x-csrf-token: a8d7f9c6e5b4a3c2d1e0f9a8d7f6c5b4a3
Request Body:
{
"dryRun": true, // Optional: Set to true to preview changes without applying them (default: false)
"onlyWithSubscriptions": true // Optional: If true, only activate users with active subscriptions; if false (default), activate all NONS users without NONS promotions
}
Response (200 OK) - Dry Run (All NONS Users):
{
"message": "Dry run completed successfully",
"dryRun": true,
"usersProcessed": 50,
"usersActivated": 48,
"usersSkipped": 0,
"errors": [],
"details": [
{
"userId": 15,
"userEmail": "john@example.com",
"action": "activated"
},
{
"userId": 23,
"userEmail": "jane@example.com",
"action": "activated"
}
]
}
Response (200 OK) - Dry Run (Only Users With Subscriptions):
{
"message": "Dry run completed successfully",
"dryRun": true,
"usersProcessed": 25,
"usersActivated": 23,
"usersSkipped": 0,
"errors": [],
"details": [
{
"userId": 15,
"userEmail": "john@example.com",
"action": "activated"
},
{
"userId": 23,
"userEmail": "jane@example.com",
"action": "activated"
}
]
}
Response (200 OK) - Actual Activation:
{
"message": "Subscription activation completed",
"dryRun": false,
"usersProcessed": 25,
"usersActivated": 23,
"usersSkipped": 0,
"errors": [
"User 42 (user@example.com): Failed to activate: Database error"
],
"details": [
{
"userId": 15,
"userEmail": "john@example.com",
"action": "activated"
},
{
"userId": 23,
"userEmail": "jane@example.com",
"action": "activated"
}
]
}
Error Responses:
{
"message": "Administrator access required"
}
Notes:
dryRun: true): Analyzes what would happen without making any changes. Returns statistics about which users would be activated. Recommended to run first to preview the activation.dryRun: false or omitted): Performs the actual activation by changing user_type_code from 'NONS' to 'SUBS'onlyWithSubscriptions: false (default) - Activates all NONS users without NONS promotions, regardless of whether they have active subscriptionsonlyWithSubscriptions: true - Only activates NONS users who have active subscriptions in the user_subscriptions tableonlyWithSubscriptions: true when you want to be more conservative and only activate users with confirmed subscriptions/api/maintenance/deactivate-subscriptions
Deactivate subscriptions for SUBS users who don't have NONS promotions applied (requires administrator access and CSRF token)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr... x-csrf-token: a8d7f9c6e5b4a3c2d1e0f9a8d7f6c5b4a3
Request Body:
{
"dryRun": true, // Optional: Set to true to preview changes without applying them (default: false)
"onlyWithSubscriptions": true // Optional: If true, only deactivate users with active subscriptions; if false (default), deactivate all SUBS users without NONS promotions
}
Response (200 OK) - Dry Run (All SUBS Users):
{
"message": "Dry run completed successfully",
"dryRun": true,
"usersProcessed": 35,
"usersDeactivated": 33,
"usersSkipped": 0,
"errors": [],
"details": [
{
"userId": 31,
"userEmail": "bob@example.com",
"action": "deactivated"
},
{
"userId": 45,
"userEmail": "alice@example.com",
"action": "deactivated"
}
]
}
Response (200 OK) - Dry Run (Only Users With Subscriptions):
{
"message": "Dry run completed successfully",
"dryRun": true,
"usersProcessed": 18,
"usersDeactivated": 17,
"usersSkipped": 0,
"errors": [],
"details": [
{
"userId": 31,
"userEmail": "bob@example.com",
"action": "deactivated"
},
{
"userId": 45,
"userEmail": "alice@example.com",
"action": "deactivated"
}
]
}
Response (200 OK) - Actual Deactivation:
{
"message": "Subscription deactivation completed",
"dryRun": false,
"usersProcessed": 18,
"usersDeactivated": 17,
"usersSkipped": 0,
"errors": [
"User 56 (user@example.com): Failed to deactivate: Database error"
],
"details": [
{
"userId": 31,
"userEmail": "bob@example.com",
"action": "deactivated"
},
{
"userId": 45,
"userEmail": "alice@example.com",
"action": "deactivated"
}
]
}
Error Responses:
{
"message": "Administrator access required"
}
Notes:
dryRun: true): Analyzes what would happen without making any changes. Returns statistics about which users would be deactivated. Recommended to run first to preview the deactivation.dryRun: false or omitted): Performs the actual deactivation by changing user_type_code from 'SUBS' to 'NONS'onlyWithSubscriptions: false (default) - Deactivates all SUBS users without NONS promotions, regardless of whether they have active subscriptionsonlyWithSubscriptions: true - Only deactivates SUBS users who have active subscriptions in the user_subscriptions tableonlyWithSubscriptions: true when you want to be more conservative and only deactivate users with confirmed subscriptions/api/maintenance/migrate-legacy-user-groups
Migrate legacy user groups to coupons and promotions (requires administrator access and CSRF token)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr... x-csrf-token: a8d7f9c6e5b4a3c2d1e0f9a8d7f6c5b4a3
Request Body:
{
"dryRun": true
}
Response (200 OK) - Dry Run:
{
"message": "Dry run completed successfully",
"dryRun": true,
"couponsCreated": 0,
"promotionsCreated": 10,
"usersProcessed": 0,
"errors": [],
"summary": {
"totalGroups": 10,
"totalUsers": 1462,
"nonsCouponCount": 4,
"discountCouponCount": 3,
"uniqueDiscountPercentages": [25, 50, 75]
}
}
Response (200 OK) - Actual Migration:
{
"message": "Migration completed successfully",
"dryRun": false,
"couponsCreated": 3,
"promotionsCreated": 10,
"usersProcessed": 1462,
"errors": [],
"summary": {
"totalGroups": 10,
"totalUsers": 1462,
"nonsCouponCount": 4,
"discountCouponCount": 3,
"uniqueDiscountPercentages": [25, 50, 75]
}
}
Error Responses:
{
"message": "Administrator access required"
}
Notes:
dryRun: true): Analyzes what would happen without making any changes. Returns statistics about groups, users, and discount percentages. Recommended to run first to preview the migration.dryRun: false): Creates coupons for each unique discount percentage (except 100%), creates one promotion per legacy user group, and applies promotions to all users in each group.