feat: Remove createLessonWithFiles endpoint and its associated imports and types.
This commit is contained in:
parent
af5b3ed266
commit
bb79e6aedc
1 changed files with 2 additions and 82 deletions
|
|
@ -1,8 +1,7 @@
|
|||
import { Body, FormField, Path, Post, Put, Request, Response, Route, Security, SuccessResponse, Tags, UploadedFile, UploadedFiles } from 'tsoa';
|
||||
import { Path, Post, Put, Request, Response, Route, Security, SuccessResponse, Tags, UploadedFile, UploadedFiles } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { ChaptersLessonService } from '../services/ChaptersLesson.service';
|
||||
import { MultiLanguageText } from '../types/index';
|
||||
import { UploadedFileInfo, CreateLessonInput, CreateLessonResponse, UpdateLessonResponse } from '../types/ChaptersLesson.typs';
|
||||
import { UploadedFileInfo, CreateLessonResponse, UpdateLessonResponse } from '../types/ChaptersLesson.typs';
|
||||
|
||||
const chaptersLessonService = new ChaptersLessonService();
|
||||
|
||||
|
|
@ -10,85 +9,6 @@ const chaptersLessonService = new ChaptersLessonService();
|
|||
@Tags('Lessons - File Upload')
|
||||
export class LessonsController {
|
||||
|
||||
/**
|
||||
* สร้างบทเรียนใหม่พร้อมไฟล์แนบ
|
||||
* Create a new lesson with optional video and attachments
|
||||
*
|
||||
* @param courseId Course ID
|
||||
* @param chapterId Chapter ID
|
||||
* @param title ชื่อบทเรียน (JSON string: { th: "", en: "" })
|
||||
* @param type ประเภทบทเรียน (VIDEO | QUIZ)
|
||||
* @param content เนื้อหาบทเรียน (JSON string: { th: "", en: "" })
|
||||
* @param sort_order ลำดับการแสดงผล
|
||||
* @param video ไฟล์วิดีโอ (สำหรับ type=VIDEO เท่านั้น)
|
||||
* @param attachments ไฟล์แนบ (PDFs, เอกสาร, รูปภาพ)
|
||||
*/
|
||||
@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');
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
// Transform files to UploadedFileInfo
|
||||
let videoInfo: UploadedFileInfo | undefined;
|
||||
let attachmentsInfo: UploadedFileInfo[] | undefined;
|
||||
|
||||
if (video) {
|
||||
videoInfo = {
|
||||
originalname: video.originalname,
|
||||
mimetype: video.mimetype,
|
||||
size: video.size,
|
||||
buffer: video.buffer,
|
||||
};
|
||||
}
|
||||
|
||||
if (attachments && attachments.length > 0) {
|
||||
attachmentsInfo = attachments.map(file => ({
|
||||
originalname: file.originalname,
|
||||
mimetype: file.mimetype,
|
||||
size: file.size,
|
||||
buffer: file.buffer,
|
||||
}));
|
||||
}
|
||||
|
||||
const input: CreateLessonInput = {
|
||||
token,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
title: parsedTitle,
|
||||
content: parsedContent,
|
||||
type,
|
||||
sort_order: sortOrder,
|
||||
video: videoInfo,
|
||||
attachments: attachmentsInfo,
|
||||
};
|
||||
|
||||
return await chaptersLessonService.createLesson(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* เพิ่มวิดีโอและไฟล์แนบให้บทเรียน VIDEO ที่มีอยู่แล้ว
|
||||
* Add video and attachments to an existing VIDEO type lesson
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue