A comprehensive Node.js backend API for managing corporate training programs with trainee progress tracking, module management, and MCQ assessments.
- Backend: Node.js with Express
- Database: PostgreSQL
- ORM: Prisma
- Authentication: JWT (JSON Web Tokens)
- File Upload: Multer
http://localhost:5000/api
All protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
Register a new trainee account.
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "Password123!",
"companyName": "Acme Corp"
}
Response:
{
"message": "Signup successful",
"user": {
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
}
Login to get JWT token.
Request Body:
{
"email": "john@example.com",
"password": "Password123!"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "TRAINEE",
"companyId": 1
}
}
Register a new admin account.
Request Body:
{
"name": "Admin User",
"email": "admin@example.com",
"password": "AdminPassword123!"
}
Response:
{
"message": "Admin signup successful",
"user": {
"id": 1,
"name": "Admin User",
"email": "admin@example.com",
"role": "ADMIN"
}
}
Admin login to get JWT token.
Request Body:
{
"email": "admin@example.com",
"password": "AdminPassword123!"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"name": "Admin User",
"email": "admin@example.com",
"role": "ADMIN"
}
}
Get trainee dashboard with overall progress.
Headers: Authorization: Bearer <token>
Response:
{
"overallProgress": 75,
"modulesCompleted": 3,
"averageScore": 85,
"totalTimeSpent": 1800,
"currentModule": {
"moduleId": 4,
"moduleName": "Module 4",
"videoDuration": 600
},
"moduleProgress": [
{
"moduleId": 1,
"moduleName": "Module 1",
"timeSpentOnVideo": 300,
"marksObtained": 90,
"pass": true,
"completed": true,
"videoDuration": 600
}
]
}
List all assigned modules with unlock status.
Headers: Authorization: Bearer <token>
Response:
[
{
"moduleId": 1,
"moduleName": "Module 1",
"completed": true,
"timeSpentOnVideo": 300,
"marksObtained": 90,
"pass": true,
"videoDuration": 600,
"unlocked": true
},
{
"moduleId": 2,
"moduleName": "Module 2",
"completed": false,
"timeSpentOnVideo": 0,
"marksObtained": 0,
"pass": false,
"videoDuration": 450,
"unlocked": true
}
]
Get specific module details with video and MCQs.
Headers: Authorization: Bearer <token>
Response:
{
"id": 1,
"name": "Module 1",
"companyId": 1,
"video": {
"id": 1,
"url": "video1.mp4",
"duration": 600
},
"mcqs": [
{
"id": 1,
"question": "What is Node.js?",
"options": ["A runtime", "A database", "A browser", "A language"],
"answer": "A runtime",
"explanation": "Node.js is a JavaScript runtime."
}
],
"unlocked": true,
"completed": false,
"pass": false,
"score": null
}
Mark module video as completed.
Headers: Authorization: Bearer <token>
Response:
{
"message": "Module marked as completed"
}
Submit MCQ answers and get results.
Headers: Authorization: Bearer <token>
Request Body:
{
"answers": [
{
"questionId": 1,
"selectedOption": "A runtime"
},
{
"questionId": 2,
"selectedOption": "JavaScript"
}
]
}
Response:
{
"message": "MCQ submitted",
"score": 2,
"pass": true
}
Get all trainees.
Headers: Authorization: Bearer <token>
Response:
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "TRAINEE",
"companyId": 1,
"isVerified": true,
"company": {
"id": 1,
"name": "Acme Corp"
}
}
]
Create new trainee.
Headers: Authorization: Bearer <token>
Request Body:
{
"name": "Jane Doe",
"email": "jane@example.com",
"password": "Password123!",
"companyId": 1
}
Get all companies.
Headers: Authorization: Bearer <token>
Response:
[
{
"id": 1,
"name": "Acme Corp",
"logo": "logo.png"
}
]
Create company with logo.
Headers: Authorization: Bearer <token>
Request Body: multipart/form-data
name
: "Acme Corp"logo
: [file upload]
Get all modules across companies.
Headers: Authorization: Bearer <token>
Response:
[
{
"id": 1,
"name": "Module 1",
"companyId": 1,
"company": {
"id": 1,
"name": "Acme Corp"
},
"video": {
"id": 1,
"duration": 600
},
"_count": {
"mcqs": 5
}
}
]
Add module to company.
Headers: Authorization: Bearer <token>
Request Body:
{
"name": "New Module"
}
Add video to module.
Headers: Authorization: Bearer <token>
Request Body: multipart/form-data
video
: [file upload]duration
: "600"
Add MCQs to module.
Headers: Authorization: Bearer <token>
Request Body:
{
"mcqs": [
{
"question": "What is Node.js?",
"options": ["A runtime", "A database", "A browser", "A language"],
"answer": "A runtime",
"explanation": "Node.js is a JavaScript runtime."
}
]
}
Get detailed trainee progress.
Headers: Authorization: Bearer <token>
Response:
{
"overallProgress": 75,
"modulesCompleted": 3,
"averageScore": 85,
"totalTimeSpent": 1800,
"moduleProgress": [
{
"moduleId": 1,
"moduleName": "Module 1",
"score": 90,
"videoDuration": 600,
"timeSpent": 300,
"pass": true
}
]
}
-
User Registration/Login
- Call
/api/auth/signup
or/api/auth/login
- Receive JWT token in response
- Call
-
Store Token
- Save token in localStorage or secure storage
- Include in all subsequent requests
-
API Requests
- Add
Authorization: Bearer <token>
header - Token expires after 7 days
- Add
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "TRAINEE",
"companyId": 1,
"isVerified": true
}
{
"id": 1,
"name": "Acme Corp",
"logo": "logo.png"
}
{
"id": 1,
"name": "Module 1",
"companyId": 1,
"video": {
"id": 1,
"url": "video1.mp4",
"duration": 600
},
"mcqs": [...]
}
{
"id": 1,
"question": "What is Node.js?",
"options": ["A runtime", "A database", "A browser", "A language"],
"answer": "A runtime",
"explanation": "Node.js is a JavaScript runtime."
}
- Modules are unlocked only after passing previous ones
- Check
unlocked
field in module list - Show appropriate UI for locked/unlocked modules
- Real-time progress updates
- Time spent tracking
- Score calculation and pass/fail status
- Company logos:
multipart/form-data
- Videos:
multipart/form-data
- Supported formats: Images (JPG, PNG), Videos (MP4, AVI)
All endpoints return consistent error format:
{
"message": "Error description"
}
Common HTTP status codes:
200
: Success201
: Created400
: Bad Request401
: Unauthorized403
: Forbidden404
: Not Found500
: Server Error
Use the provided Postman collection (TrainingPortalBackend.postman_collection.json
) for API testing and development.
For API questions or issues:
- Check error responses for specific details
- Verify authentication headers
- Ensure proper request body format
- Contact backend team for assistance
Ready for Frontend Integration! π