feat: Introduce dedicated instructor and student controllers for chapter and lesson management, including quiz questions.
This commit is contained in:
parent
9a7eb50d17
commit
fc3e2820cc
3 changed files with 426 additions and 18 deletions
|
|
@ -23,25 +23,30 @@ export class LessonsController {
|
|||
* @param video ไฟล์วิดีโอ (สำหรับ type=VIDEO เท่านั้น)
|
||||
* @param attachments ไฟล์แนบ (PDFs, เอกสาร, รูปภาพ)
|
||||
*/
|
||||
async createLesson(req: LessonUploadRequest, res: Response, next: NextFunction): Promise<void> {
|
||||
try {
|
||||
const token = req.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
@Post('upload')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('201', 'Lesson created successfully')
|
||||
@Response('400', 'Validation error')
|
||||
@Response('401', 'Unauthorized')
|
||||
@Response('403', 'Forbidden')
|
||||
public async createLessonWithFiles(
|
||||
@Request() request: any,
|
||||
@Path() courseId: number,
|
||||
@Path() chapterId: number,
|
||||
@FormField() title: string,
|
||||
@FormField() type: 'VIDEO' | 'QUIZ',
|
||||
@FormField() content?: string,
|
||||
@FormField() sort_order?: string,
|
||||
@UploadedFile() video?: Express.Multer.File,
|
||||
@UploadedFiles() attachments?: Express.Multer.File[]
|
||||
): Promise<CreateLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const courseId = parseInt(req.params.courseId, 10);
|
||||
const chapterId = parseInt(req.params.chapterId, 10);
|
||||
|
||||
if (isNaN(courseId) || isNaN(chapterId)) {
|
||||
throw new ValidationError('Invalid course ID or chapter ID');
|
||||
}
|
||||
|
||||
// Parse JSON fields from multipart form
|
||||
const title = JSON.parse(req.body.title || '{}');
|
||||
const content = req.body.content ? JSON.parse(req.body.content) : undefined;
|
||||
const type = req.body.type as 'VIDEO' | 'QUIZ';
|
||||
const sortOrder = req.body.sort_order ? parseInt(req.body.sort_order, 10) : undefined;
|
||||
// Parse JSON fields
|
||||
const parsedTitle: MultiLanguageText = JSON.parse(title);
|
||||
const parsedContent = content ? JSON.parse(content) : undefined;
|
||||
const sortOrder = sort_order ? parseInt(sort_order, 10) : undefined;
|
||||
|
||||
if (!parsedTitle.th || !parsedTitle.en) {
|
||||
throw new ValidationError('Title must have both Thai (th) and English (en) values');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue