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

    Variable LessonSchemaConst

    LessonSchema: ZodObject<
        {
            id: ZodString;
            experience_points: ZodDefault<ZodNumber>;
            order: ZodNumber;
        },
        "strip",
        ZodTypeAny,
        { id: string; experience_points: number; order: number },
        { id: string; experience_points?: number; order: number },
    > = ...

    Lesson validation schema for individual learning units within modules

    Validation schema for individual lessons that represent discrete learning units within educational modules. Lessons are the primary content delivery mechanism in the platform, containing specific learning objectives, content, and associated exercises while supporting gamification through experience point allocation.

    The lesson schema provides unique identification for content management and tracking, experience point allocation for gamification and progress tracking, and proper ordering for sequential learning progression within modules. Default experience points encourage consistent reward structures while allowing customization for different lesson complexities.

    Gamification features include configurable experience point rewards that motivate learner engagement, progress tracking support through unique identification, and ordering systems that support both linear and adaptive learning paths based on learner performance and preferences.

    // Lessons with varying experience points
    const moduleLessons = [
    {
    id: 'basic-greetings-intro',
    experience_points: 5, // Simple introduction lesson
    order: 1
    },
    {
    id: 'greeting-vocabulary-practice',
    experience_points: 10, // Standard practice lesson
    order: 2
    },
    {
    id: 'greeting-conversation-challenge',
    experience_points: 20, // Complex conversation lesson
    order: 3
    }
    ];
    // Lesson creation with gamification
    router.post('/modules/:moduleId/lessons',
    validate({ body: LessonSchema }),
    async (req, res) => {
    const lessonData = req.body; // Validated lesson data
    const lesson = await lessonService.create(req.params.moduleId, lessonData);

    // Initialize gamification tracking
    await gamificationService.registerLesson(lesson.id, lesson.experience_points);

    res.status(201).json({ lesson });
    }
    );
    // Lesson completion tracking
    const completeLessonSchema = z.object({
    lessonId: z.string(),
    completionTime: z.number().min(0),
    score: z.number().min(0).max(100).optional()
    });

    router.post('/lessons/:lessonId/complete',
    validate({ body: completeLessonSchema }),
    async (req, res) => {
    const { completionTime, score } = req.body;
    const lesson = await lessonService.findById(req.params.lessonId);

    // Award experience points based on lesson configuration
    const experienceAwarded = await gamificationService.awardExperience(
    req.user.id,
    lesson.experience_points,
    score
    );

    res.json({ experienceAwarded, lesson });
    }
    );