Authentication
Request Format
Content-Type:multipart/form-data
This endpoint requires a multipart form submission with:
- A JSON string field
courseDatacontaining the course details - An image file field
imagefor the course thumbnail
Request Fields
Course Data Schema
ThecourseData field must be a JSON string containing:
Course Content Structure
Each chapter incourseContent should have:
Request Example
Automatic Calculations
The system automatically computes:- totalLectures: Count of all lectures across all chapters
- totalDurationMinutes: Sum of all lecture durations
totalLectures: 3totalDurationMinutes: 70 (15 + 25 + 30)
Response
Response Examples
Process Flow
- Validates that a thumbnail image is provided
- Parses the JSON courseData string
- Iterates through all chapters and lectures to calculate:
- Total number of lectures
- Total duration in minutes
- Creates the course document in the database
- Uploads the thumbnail to Cloudinary
- Updates the course with the Cloudinary URL
- Saves the final course document
Error Handling
- Missing thumbnail: Returns
success: falsewith specific message - Invalid JSON: Returns 500 error
- Database errors: Returns 500 error with generic message
- Cloudinary upload failure: Returns 500 error
Notes
- Only users with the educator role can access this endpoint (enforced by
protectEducatormiddleware) - The educator’s user ID is automatically extracted from the authentication token
- Course thumbnails are stored in Cloudinary
- Courses can be created as drafts (
isPublished: false) or published immediately