Maintenance mode activates after current draw completes
- When admin enables maintenance, it's set to 'pending' state - Maintenance activates automatically after the current draw completes - Admin can use immediate=true to force immediate activation - Frontend shows 'Maintenance Scheduled' banner when pending - Telegram bot warns users but still allows purchases when pending - Both mode and pending status tracked in system_settings table
This commit is contained in:
@@ -8,6 +8,68 @@ import config from '../config';
|
||||
import { JackpotCycle, TicketPurchase, Ticket, Payout } from '../types';
|
||||
import { AuthRequest } from '../middleware/auth';
|
||||
|
||||
/**
|
||||
* GET /status/maintenance
|
||||
* Public endpoint to check maintenance mode
|
||||
*/
|
||||
export async function getPublicMaintenanceStatus(req: Request, res: Response) {
|
||||
try {
|
||||
const result = await db.query(
|
||||
`SELECT value FROM system_settings WHERE key = 'maintenance_mode'`
|
||||
);
|
||||
const pendingResult = await db.query(
|
||||
`SELECT value FROM system_settings WHERE key = 'maintenance_pending'`
|
||||
);
|
||||
const messageResult = await db.query(
|
||||
`SELECT value FROM system_settings WHERE key = 'maintenance_message'`
|
||||
);
|
||||
|
||||
const enabled = result.rows[0]?.value === 'true';
|
||||
const pending = pendingResult.rows[0]?.value === 'true';
|
||||
const message = messageResult.rows[0]?.value || 'System is under maintenance. Please try again later.';
|
||||
|
||||
return res.json({
|
||||
version: '1.0',
|
||||
data: {
|
||||
maintenance_mode: enabled,
|
||||
maintenance_pending: pending,
|
||||
message: enabled ? message : (pending ? 'Maintenance will begin after the current draw completes.' : null),
|
||||
},
|
||||
});
|
||||
} catch (error: any) {
|
||||
// If table doesn't exist yet, return not in maintenance
|
||||
return res.json({
|
||||
version: '1.0',
|
||||
data: {
|
||||
maintenance_mode: false,
|
||||
maintenance_pending: false,
|
||||
message: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to check if system is in maintenance mode
|
||||
*/
|
||||
async function isMaintenanceMode(): Promise<{ enabled: boolean; message: string }> {
|
||||
try {
|
||||
const result = await db.query(
|
||||
`SELECT value FROM system_settings WHERE key = 'maintenance_mode'`
|
||||
);
|
||||
const messageResult = await db.query(
|
||||
`SELECT value FROM system_settings WHERE key = 'maintenance_message'`
|
||||
);
|
||||
|
||||
return {
|
||||
enabled: result.rows[0]?.value === 'true',
|
||||
message: messageResult.rows[0]?.value || 'System is under maintenance. Please try again later.',
|
||||
};
|
||||
} catch {
|
||||
return { enabled: false, message: '' };
|
||||
}
|
||||
}
|
||||
|
||||
const toIsoString = (value: any): string => {
|
||||
if (!value) {
|
||||
return new Date().toISOString();
|
||||
@@ -140,6 +202,16 @@ export async function getNextJackpot(req: Request, res: Response) {
|
||||
*/
|
||||
export async function buyTickets(req: AuthRequest, res: Response) {
|
||||
try {
|
||||
// Check maintenance mode first
|
||||
const maintenance = await isMaintenanceMode();
|
||||
if (maintenance.enabled) {
|
||||
return res.status(503).json({
|
||||
version: '1.0',
|
||||
error: 'MAINTENANCE_MODE',
|
||||
message: maintenance.message,
|
||||
});
|
||||
}
|
||||
|
||||
const { tickets, lightning_address, nostr_pubkey, name, buyer_name } = req.body;
|
||||
const userId = req.user?.id || null;
|
||||
const authNostrPubkey = req.user?.nostr_pubkey || null;
|
||||
|
||||
Reference in New Issue
Block a user