@defikitdotnet/education-module-ai
Version:
AI Education Module using Agent Framework
188 lines (187 loc) • 5.88 kB
TypeScript
import { Course } from "../models/Course";
import { CourseRepository } from "../repositories/CourseRepository";
import { SectionRepository } from "../repositories/SectionRepository";
import { LectureRepository } from "../repositories/LectureRepository";
import { QuizRepository } from "../repositories/QuizRepository";
import { QuizQuestionRepository } from "../repositories/QuizQuestionRepository";
import { CategoryRepository } from "../repositories/CategoryRepository";
import { Section } from "../models/Section";
import { Lecture } from "../models/Lecture";
import { Quiz } from "../models/Quiz";
import { QuizQuestion } from "../models/QuizQuestion";
import { EnrollmentRepository } from "../repositories/EnrollmentRepository";
import { DatabaseAdapter } from "../database/DatabaseAdapter";
export type CourseLevel = "beginner" | "intermediate" | "advanced";
/**
* DTO for course creation
*/
export interface CreateCourseDTO {
teacherId: string;
title: string;
description?: string;
thumbnail?: string;
level: CourseLevel;
visibility?: "private" | "public";
categories?: string[];
}
export interface UpdateQuizQuestionDTO {
id?: string;
question: string;
options: string[];
correctAnswer: string;
explanation?: string;
}
export interface UpdateQuizDTO {
id?: string;
title: string;
description?: string;
questions: UpdateQuizQuestionDTO[];
}
export interface UpdateLectureDTO {
id?: string;
title: string;
content: string;
type: "text" | "video" | "h5p";
orderIndex: number;
}
export interface UpdateSectionDTO {
id?: string;
title: string;
description?: string;
orderIndex: number;
lectures: UpdateLectureDTO[];
quiz?: UpdateQuizDTO | null;
}
export interface UpdateCoursePayloadDTO {
title: string;
description?: string;
thumbnail?: string;
level: "beginner" | "intermediate" | "advanced";
visibility: "private" | "public";
categories?: string[];
sections: UpdateSectionDTO[];
}
/**
* DTO for course listing with section counts
* Re-defined properties instead of extending Course to fix type mismatch
*/
export interface CourseWithDetails {
id: string;
teacherId: string;
title: string;
description: string;
thumbnail: string;
level: CourseLevel;
visibility: "private" | "public";
categories: string[];
createdAt: Date;
updatedAt?: Date;
sectionCount: number;
lectureCount: number;
categoryNames?: string[];
}
/**
* DTO for detailed course with sections and lectures
* Re-defined properties instead of extending Course to fix type mismatch
*/
export interface CourseDetail {
id: string;
teacherId: string;
title: string;
description: string;
thumbnail: string;
level: CourseLevel;
visibility: "private" | "public";
categories: string[];
createdAt: Date;
updatedAt?: Date;
sections: (Omit<Section, "courseId" | "createdAt" | "updatedAt"> & {
lectures: Lecture[];
quiz?: Quiz & {
questions: QuizQuestion[];
};
})[];
categoryNames?: string[];
}
export interface CourseDetails {
course: Course;
sections: Section[];
lectures: Lecture[];
totalLectures: number;
}
/**
* Service class for handling course-related business logic
*/
export declare class CourseService {
private courseRepository;
private sectionRepository;
private lectureRepository;
private quizRepository;
private quizQuestionRepository;
private categoryRepository;
private enrollmentRepository;
private dbAdapter;
constructor(courseRepository: CourseRepository, sectionRepository: SectionRepository, lectureRepository: LectureRepository, quizRepository: QuizRepository, quizQuestionRepository: QuizQuestionRepository, categoryRepository: CategoryRepository, enrollmentRepository: EnrollmentRepository, dbAdapter: DatabaseAdapter);
/**
* Create a new course
*/
createCourse(courseData: CreateCourseDTO): Promise<Course>;
private parseCategories;
/**
* Create content for a course
*/
createContent(courseId: string, contentData: any): Promise<any>;
/**
* Get all courses for a teacher
*/
getCoursesByTeacherId(teacherId: string): Promise<CourseWithDetails[]>;
/**
* Get a course by ID with all sections, lectures, and quizzes
*/
getCourseDetail(courseId: string): Promise<CourseDetail | null>;
/**
* Update a course
*/
updateCourse(courseId: string, data: UpdateCoursePayloadDTO): Promise<CourseDetail | null>;
private updateLecturesForSection;
private updateQuizForSection;
private updateQuestionsForQuiz;
/**
* Delete a course
*/
deleteCourse(courseId: string): Promise<boolean>;
/**
* Get public courses
*/
getPublicCourses(): Promise<CourseWithDetails[]>;
/**
* Get courses by teacher ID
*/
getCoursesByTeacher(teacherId: string): Promise<CourseWithDetails[]>;
/**
* Get courses by category
*/
getCoursesByCategory(categoryId: string): Promise<CourseWithDetails[]>;
/**
* Fetch a course with all its sections and lectures
*/
getCourseDetails(courseId: string): Promise<CourseDetails | null>;
/**
* Fetch all enrolled courses for a student with progress information
*/
getEnrolledCoursesWithProgress(studentId: string): Promise<any[]>;
/**
* Mark a lecture as completed and update course progress
*/
markLectureCompleted(studentId: string, courseId: string, lectureId: string): Promise<{
success: boolean;
progress: number;
isCompleted: boolean;
}>;
/**
* Get the total number of lectures in a course
*/
getTotalLectureCount(courseId: string): Promise<{
totalLectures: number;
}>;
}