feat: Remove createLessonWithFiles endpoint and its associated imports and types.

This commit is contained in:
JakkrapartXD 2026-01-22 10:22:53 +07:00
parent af5b3ed266
commit bb79e6aedc

View file

@ -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