Files
LightningLotto/back_end/src/routes/admin.ts
Michilis 404fdf2610 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
2025-12-09 00:46:55 +00:00

206 lines
4.9 KiB
TypeScript

import { Router } from 'express';
import {
listCycles,
runDrawManually,
retryPayout,
listPayouts,
getMaintenanceStatus,
setMaintenanceMode
} from '../controllers/admin';
import { verifyAdmin } from '../middleware/auth';
const router = Router();
// All admin routes require admin key
router.use(verifyAdmin);
/**
* @swagger
* /admin/cycles:
* get:
* summary: List all jackpot cycles
* tags: [Admin]
* security:
* - adminKey: []
* parameters:
* - in: query
* name: status
* schema:
* type: string
* description: Filter by status
* - in: query
* name: cycle_type
* schema:
* type: string
* description: Filter by cycle type
* - in: query
* name: limit
* schema:
* type: integer
* default: 50
* - in: query
* name: offset
* schema:
* type: integer
* default: 0
* responses:
* 200:
* description: List of cycles
* 403:
* description: Invalid admin key
*/
router.get('/cycles', listCycles);
/**
* @swagger
* /admin/cycles/{id}/run-draw:
* post:
* summary: Manually trigger a draw for a cycle
* tags: [Admin]
* security:
* - adminKey: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Draw executed successfully
* 400:
* description: Draw failed or invalid cycle
* 403:
* description: Invalid admin key
*/
router.post('/cycles/:id/run-draw', runDrawManually);
/**
* @swagger
* /admin/payouts:
* get:
* summary: List all payouts
* tags: [Admin]
* security:
* - adminKey: []
* parameters:
* - in: query
* name: status
* schema:
* type: string
* description: Filter by status
* - in: query
* name: limit
* schema:
* type: integer
* default: 50
* responses:
* 200:
* description: List of payouts
* 403:
* description: Invalid admin key
*/
router.get('/payouts', listPayouts);
/**
* @swagger
* /admin/payouts/{id}/retry:
* post:
* summary: Retry a failed payout
* tags: [Admin]
* security:
* - adminKey: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Payout retry successful
* 400:
* description: Retry failed or invalid payout
* 403:
* description: Invalid admin key
*/
router.post('/payouts/:id/retry', retryPayout);
/**
* @swagger
* /admin/maintenance:
* get:
* summary: Get maintenance mode status
* tags: [Admin]
* security:
* - adminKey: []
* responses:
* 200:
* description: Maintenance status
* content:
* application/json:
* schema:
* type: object
* properties:
* maintenance_mode:
* type: boolean
* message:
* type: string
* 403:
* description: Invalid admin key
*/
router.get('/maintenance', getMaintenanceStatus);
/**
* @swagger
* /admin/maintenance:
* post:
* summary: Enable or disable maintenance mode
* description: When enabling, maintenance is set to "pending" and activates after current draw completes. Use immediate=true to activate immediately.
* tags: [Admin]
* security:
* - adminKey: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - enabled
* properties:
* enabled:
* type: boolean
* description: Whether to enable maintenance mode
* message:
* type: string
* description: Custom maintenance message
* immediate:
* type: boolean
* description: If true, activate immediately instead of waiting for draw to complete
* responses:
* 200:
* description: Maintenance mode updated
* content:
* application/json:
* schema:
* type: object
* properties:
* maintenance_mode:
* type: boolean
* maintenance_pending:
* type: boolean
* message:
* type: string
* 400:
* description: Invalid input
* 403:
* description: Invalid admin key
*/
router.post('/maintenance', setMaintenanceMode);
export default router;