WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Variable LessonCompletionSchemaConst

    LessonCompletionSchema: ZodObject<
        {
            lesson_id: ZodString;
            completed_at: ZodString;
            score: ZodOptional<ZodNumber>;
            time_spent_seconds: ZodOptional<ZodNumber>;
        },
        "strip",
        ZodTypeAny,
        {
            lesson_id: string;
            completed_at: string;
            score?: number;
            time_spent_seconds?: number;
        },
        {
            lesson_id: string;
            completed_at: string;
            score?: number;
            time_spent_seconds?: number;
        },
    > = ...

    Lesson completion validation schema for individual learning progress tracking

    Comprehensive validation schema for recording individual lesson completion events in the language learning platform. This schema captures essential learning analytics data including lesson identification, completion timestamps, performance scores, and time investment, providing the foundation for progress tracking, gamification, and educational effectiveness measurement.

    The completion schema ensures accurate temporal tracking through ISO 8601 datetime validation with timezone support, performance measurement through optional score tracking, learning efficiency analysis through time spent recording, and proper lesson identification for progress correlation and learning path optimization.

    Educational analytics features include support for adaptive learning through performance tracking, engagement measurement through time analysis, progress visualization through completion timestamps, and learning effectiveness assessment through score correlation with time investment and lesson difficulty.

    The schema supports both real-time progress tracking for online learning and batch synchronization for offline learning scenarios, ensuring comprehensive learning analytics regardless of connectivity status or learning environment.

    // Individual lesson completion tracking
    const completionData = {
    lesson_id: 'qu-basics-lesson-01',
    completed_at: '2024-01-20T10:30:00.000Z',
    score: 85,
    time_spent_seconds: 420
    };

    const result = LessonCompletionSchema.parse(completionData);
    console.log('Valid completion:', result);
    // Lesson completion endpoint with validation
    router.post('/lessons/:lessonId/complete',
    validate({ body: LessonCompletionSchema }),
    async (req, res) => {
    const completionData = req.body; // Validated completion data
    const userId = req.user.id;

    const completion = await progressService.recordCompletion(userId, completionData);

    // Award experience points based on performance
    if (completionData.score && completionData.score >= 70) {
    await gamificationService.awardExperience(userId, completion.lesson.experience_points);
    }

    res.status(201).json({ completion });
    }
    );
    // Batch completion processing for analytics
    const completions = [
    {
    lesson_id: 'lesson-001',
    completed_at: '2024-01-20T09:00:00Z',
    score: 92,
    time_spent_seconds: 300
    },
    {
    lesson_id: 'lesson-002',
    completed_at: '2024-01-20T09:30:00Z',
    score: 78,
    time_spent_seconds: 480
    }
    ];

    completions.forEach(completion => {
    const validation = LessonCompletionSchema.safeParse(completion);
    if (validation.success) {
    console.log(`Completion for ${completion.lesson_id} is valid`);
    }
    });
    // Learning analytics with completion data
    const analyzeCompletion = (completion: LessonCompletionRequest) => {
    const efficiency = completion.score && completion.time_spent_seconds
    ? completion.score / (completion.time_spent_seconds / 60) // Score per minute
    : null;

    return {
    lessonId: completion.lesson_id,
    completedAt: new Date(completion.completed_at),
    performance: completion.score || 'Not scored',
    timeInvestment: completion.time_spent_seconds || 'Not tracked',
    efficiency: efficiency ? `${efficiency.toFixed(2)} points/min` : 'Cannot calculate'
    };
    };
    // Mobile app offline completion tracking
    const offlineCompletion = {
    lesson_id: 'mobile-lesson-03',
    completed_at: new Date().toISOString(), // Current timestamp
    score: 88,
    time_spent_seconds: 360
    };

    // Store locally for later sync
    localStorage.setItem('pendingCompletion', JSON.stringify(offlineCompletion));