feat: Implement chapter and lesson management with new services and types, and introduce Minio service.

This commit is contained in:
JakkrapartXD 2026-01-20 13:39:42 +07:00
parent 40b95ad902
commit 6bbbde062a
8 changed files with 382 additions and 6 deletions

View file

@ -0,0 +1,320 @@
// ============================================
// Multi-language Types
// ============================================
import { MultiLanguageText } from './index';
// Use MultiLanguageText from index.ts for consistency
export type MultiLangText = MultiLanguageText;
// ============================================
// Lesson Types (for nested inclusion)
// ============================================
export interface LessonAttachmentData {
id: number;
lesson_id: number;
file_name: string;
file_path: string;
file_size: number;
mime_type: string;
description: MultiLanguageText | null;
sort_order: number;
created_at: Date;
}
export interface QuizData {
id: number;
lesson_id: number;
title: MultiLanguageText;
description: MultiLanguageText | null;
passing_score: number;
time_limit: number | null;
shuffle_questions: boolean;
shuffle_choices: boolean;
show_answers_after_completion: boolean;
created_at: Date;
created_by: number;
updated_at: Date | null;
updated_by: number | null;
}
export interface LessonProgressData {
id: number;
user_id: number;
lesson_id: number;
is_completed: boolean;
completed_at: Date | null;
video_progress_seconds: number;
video_duration_seconds: number | null;
video_progress_percentage: number | null;
last_watched_at: Date | null;
created_at: Date;
updated_at: Date | null;
}
export interface LessonData {
id: number;
chapter_id: number;
title: MultiLanguageText;
content: MultiLanguageText | null;
type: 'VIDEO' | 'QUIZ';
duration_minutes: number | null;
sort_order: number;
is_sequential: boolean;
prerequisite_lesson_ids: number[] | null;
require_pass_quiz: boolean;
is_published: boolean;
created_at: Date;
updated_at: Date | null;
attachments?: LessonAttachmentData[];
quiz?: QuizData | null;
progress?: LessonProgressData[];
}
// ============================================
// Chapter Types
// ============================================
export interface ChapterData {
id: number;
course_id: number;
title: MultiLanguageText;
description: MultiLanguageText | null;
sort_order: number;
is_published: boolean;
created_at: Date;
updated_at: Date | null;
lessons?: LessonData[];
}
// ============================================
// Request Types
// ============================================
export interface ChaptersRequest {
token: string;
course_id: number;
}
export interface GetChapterRequest {
token: string;
course_id: number;
chapter_id: number;
}
export interface CreateChapterInput {
title: MultiLanguageText;
description?: MultiLanguageText;
sort_order?: number;
is_published?: boolean;
}
export interface CreateChapterRequest {
token: string;
course_id: number;
data: CreateChapterInput;
}
export interface UpdateChapterInput {
title?: MultiLanguageText;
description?: MultiLanguageText;
sort_order?: number;
is_published?: boolean;
}
export interface UpdateChapterRequest {
token: string;
course_id: number;
chapter_id: number;
data: UpdateChapterInput;
}
export interface DeleteChapterRequest {
token: string;
course_id: number;
chapter_id: number;
}
export interface ReorderChapterRequest {
token: string;
course_id: number;
chapter_ids: number[]; // Ordered array of chapter IDs
}
// ============================================
// Response Types
// ============================================
export interface ListChaptersResponse {
code: number;
message: string;
data: ChapterData[];
total: number;
}
export interface GetChapterResponse {
code: number;
message: string;
data: ChapterData;
}
export interface CreateChapterResponse {
code: number;
message: string;
data: ChapterData;
}
export interface UpdateChapterResponse {
code: number;
message: string;
data: ChapterData;
}
export interface DeleteChapterResponse {
code: number;
message: string;
}
export interface ReorderChapterResponse {
code: number;
message: string;
data: ChapterData[];
}
// ============================================
// Chapter with Full Lessons (for detailed view)
// ============================================
export interface ChapterWithLessonsResponse {
code: number;
message: string;
data: ChapterData & {
lessons: LessonData[];
};
}
// ============================================
// Lesson Request Types
// ============================================
export interface ListLessonsRequest {
token: string;
course_id: number;
chapter_id: number;
}
export interface GetLessonRequest {
token: string;
course_id: number;
chapter_id: number;
lesson_id: number;
}
export interface CreateLessonInput {
title: MultiLanguageText;
content?: MultiLanguageText;
type: 'VIDEO' | 'QUIZ';
duration_minutes?: number;
sort_order?: number;
is_sequential?: boolean;
prerequisite_lesson_ids?: number[];
require_pass_quiz?: boolean;
is_published?: boolean;
}
export interface CreateLessonRequest {
token: string;
course_id: number;
chapter_id: number;
data: CreateLessonInput;
}
export interface UpdateLessonInput {
title?: MultiLanguageText;
content?: MultiLanguageText;
type?: 'VIDEO' | 'QUIZ';
duration_minutes?: number;
sort_order?: number;
is_sequential?: boolean;
prerequisite_lesson_ids?: number[];
require_pass_quiz?: boolean;
is_published?: boolean;
}
export interface UpdateLessonRequest {
token: string;
course_id: number;
chapter_id: number;
lesson_id: number;
data: UpdateLessonInput;
}
export interface DeleteLessonRequest {
token: string;
course_id: number;
chapter_id: number;
lesson_id: number;
}
export interface ReorderLessonsRequest {
token: string;
course_id: number;
chapter_id: number;
lesson_ids: number[]; // Ordered array of lesson IDs
}
// ============================================
// Lesson Response Types
// ============================================
export interface ListLessonsResponse {
code: number;
message: string;
data: LessonData[];
total: number;
}
export interface GetLessonResponse {
code: number;
message: string;
data: LessonData;
}
export interface CreateLessonResponse {
code: number;
message: string;
data: LessonData;
}
export interface UpdateLessonResponse {
code: number;
message: string;
data: LessonData;
}
export interface DeleteLessonResponse {
code: number;
message: string;
}
export interface ReorderLessonsResponse {
code: number;
message: string;
data: LessonData[];
}
// ============================================
// Lesson with Full Details (attachments, quiz, progress)
// ============================================
export interface LessonWithDetailsResponse {
code: number;
message: string;
data: LessonData & {
attachments: LessonAttachmentData[];
quiz: QuizData | null;
progress: LessonProgressData[];
};
}