176 lines
5.6 KiB
JavaScript
176 lines
5.6 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const guestController = require('../controllers/guest.controller');
|
|
const guestMiddleware = require('../middleware/guest.middleware');
|
|
const { guestSessionLimiter } = require('../middleware/rateLimiter');
|
|
|
|
/**
|
|
* @swagger
|
|
* /guest/start-session:
|
|
* post:
|
|
* summary: Start a new guest session
|
|
* description: Creates a temporary guest session allowing users to try quizzes without registration
|
|
* tags: [Guest]
|
|
* security: []
|
|
* responses:
|
|
* 201:
|
|
* description: Guest session created successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* message:
|
|
* type: string
|
|
* example: Guest session created successfully
|
|
* guestSession:
|
|
* $ref: '#/components/schemas/GuestSession'
|
|
* token:
|
|
* type: string
|
|
* description: Guest session token for subsequent requests
|
|
* example: 550e8400-e29b-41d4-a716-446655440000
|
|
* settings:
|
|
* type: object
|
|
* properties:
|
|
* maxQuizzes:
|
|
* type: integer
|
|
* example: 3
|
|
* expiryHours:
|
|
* type: integer
|
|
* example: 24
|
|
* 500:
|
|
* description: Server error
|
|
*
|
|
* /guest/session/{guestId}:
|
|
* get:
|
|
* summary: Get guest session details
|
|
* tags: [Guest]
|
|
* security: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: guestId
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* format: uuid
|
|
* description: Guest session ID
|
|
* responses:
|
|
* 200:
|
|
* description: Guest session retrieved successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/GuestSession'
|
|
* 404:
|
|
* $ref: '#/components/responses/NotFoundError'
|
|
*
|
|
* /guest/quiz-limit:
|
|
* get:
|
|
* summary: Check guest quiz limit and remaining quizzes
|
|
* tags: [Guest]
|
|
* security: []
|
|
* parameters:
|
|
* - in: header
|
|
* name: x-guest-token
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* format: uuid
|
|
* description: Guest session token
|
|
* responses:
|
|
* 200:
|
|
* description: Quiz limit information retrieved
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* maxQuizzes:
|
|
* type: integer
|
|
* example: 3
|
|
* quizzesCompleted:
|
|
* type: integer
|
|
* example: 1
|
|
* remainingQuizzes:
|
|
* type: integer
|
|
* example: 2
|
|
* limitReached:
|
|
* type: boolean
|
|
* example: false
|
|
* 401:
|
|
* $ref: '#/components/responses/UnauthorizedError'
|
|
* 404:
|
|
* description: Guest session not found or expired
|
|
*
|
|
* /guest/convert:
|
|
* post:
|
|
* summary: Convert guest session to registered user account
|
|
* description: Converts guest progress to a new user account, preserving quiz history
|
|
* tags: [Guest]
|
|
* security: []
|
|
* parameters:
|
|
* - in: header
|
|
* name: x-guest-token
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* format: uuid
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* required:
|
|
* - username
|
|
* - email
|
|
* - password
|
|
* properties:
|
|
* username:
|
|
* type: string
|
|
* minLength: 3
|
|
* maxLength: 50
|
|
* example: johndoe
|
|
* email:
|
|
* type: string
|
|
* format: email
|
|
* example: john@example.com
|
|
* password:
|
|
* type: string
|
|
* minLength: 6
|
|
* example: password123
|
|
* responses:
|
|
* 201:
|
|
* description: Guest converted to user successfully
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* message:
|
|
* type: string
|
|
* example: Guest account converted successfully
|
|
* user:
|
|
* $ref: '#/components/schemas/User'
|
|
* token:
|
|
* type: string
|
|
* description: JWT authentication token
|
|
* sessionsTransferred:
|
|
* type: integer
|
|
* example: 2
|
|
* 400:
|
|
* $ref: '#/components/responses/ValidationError'
|
|
* 401:
|
|
* $ref: '#/components/responses/UnauthorizedError'
|
|
* 404:
|
|
* description: Guest session not found or expired
|
|
* 409:
|
|
* description: Username or email already exists
|
|
*/
|
|
router.post('/start-session', guestSessionLimiter, guestController.startGuestSession);
|
|
router.get('/session/:guestId', guestController.getGuestSession);
|
|
router.get('/quiz-limit', guestMiddleware.verifyGuestToken, guestController.checkQuizLimit);
|
|
router.post('/convert', guestSessionLimiter, guestMiddleware.verifyGuestToken, guestController.convertGuestToUser);
|
|
|
|
module.exports = router;
|