📚 Emadrasati API Documentation

Complete API Reference for School/Madrasa Management System

Base URL: http://localhost:5000/api

🔐 Authentication APIs

POST /auth/signup Public
Student Registration - Register a new student account. Students are automatically verified.
Request Body:
{
  "name": "string (required)",
  "phone": "string (required, min 10 digits)",
  "email": "string (required, valid email)",
  "password": "string (required, min 6 characters)"
}
Response:
{
  "success": true,
  "message": "Student registered successfully",
  "data": { ... }
}
POST /auth/teacher/signup Public
Teacher Self Registration - Teachers can register themselves. Requires admin verification before login.
Request Body:
{
  "name": "string (required)",
  "phone": "string (required, min 10 digits)",
  "email": "string (required, valid email)",
  "password": "string (required, min 6 characters)",
  "teacherRole": "head_teacher | subject_teacher | class_teacher | assistant_teacher | regular_teacher | trainee_teacher (optional, default: regular_teacher)",
  "subjects": ["string"] (required, at least 1),
  "classes": ["string"] (required, at least 1),
  "qualification": "string (required)",
  "experience": "number (optional)",
  "joiningDate": "ISO datetime string (required)",
  "address": "string (optional)",
  "nid": "string (optional)"
}
POST /auth/login Public
User Login - Login for all user types (student, teacher, mentor, vendor, department_head)
Request Body:
{
  "email": "string (required)",
  "password": "string (required)"
}
Response:
{
  "success": true,
  "message": "login successfully",
  "data": {
    "accessToken": "jwt_token",
    "refreshToken": "jwt_token"
  }
}
POST /auth/first-time-password-change Teacher Only
First Time Password Change - For teachers with isNew=true. Changes password and sets isNew to false.
Headers:
Authorization Bearer {token}
JWT token from login
Request Body:
{
  "newPassword": "string (required, min 6 characters)"
}
POST /auth/change-password Authenticated
Change Password - Change password for authenticated users
Request Body:
{
  "currentPassword": "string (required)",
  "newPassword": "string (required, min 6 characters)"
}

👨‍💼 Admin APIs

POST /admin/super-admin/login Public
Super Admin Login - Login for super admin only
POST /admin/admin/login Public
Admin Login - Login for admin users
POST /admin/teacher/login Public
Teacher Login - Login for teachers. Returns isNew status.
Response:
{
  "success": true,
  "message": "Teacher logged in successfully",
  "data": {
    "accessToken": "jwt_token",
    "refreshToken": "jwt_token",
    "isNew": true/false
  }
}
POST /admin/create-admin Super Admin Only
Create Admin - Super admin can create new admin users
Request Body:
{
  "name": "string (required)",
  "phone": "string (required)",
  "email": "string (required)",
  "password": "string (required)"
}
POST /admin/create-teacher Super Admin / Admin / Head Teacher
Create Teacher - Admin or Head Teacher can create teachers. Teachers are auto-verified and isNew=true. Head Teachers can only create non-Head Teacher roles.
Request Body:
{
  "name": "string (required)",
  "phone": "string (required)",
  "email": "string (required)",
  "password": "string (required)",
  "teacherRole": "head_teacher | subject_teacher | class_teacher | assistant_teacher | regular_teacher | trainee_teacher (optional)",
  "subjects": ["string"] (optional, default: []),
  "classes": ["string"] (optional, default: []),
  "qualification": "string (required)",
  "experience": "number (optional)",
  "joiningDate": "ISO datetime string (required)",
  "address": "string (optional)",
  "nid": "string (optional)",
  "salary": "number (optional)",
  "supervisorId": "string (optional, required for trainee_teacher)",
  "trainingStartDate": "ISO datetime string (optional, auto-set for trainee_teacher)",
  "trainingEndDate": "ISO datetime string (optional)"
}
Response:
{
  "success": true,
  "message": "Teacher created successfully",
  "data": {
    "_id": "...",
    "name": "...",
    "createdBy": "userId",
    ...
  }
}
PATCH /admin/verify/:id Super Admin Only
Verify User - Verify mentor, vendor, or teacher accounts
GET /admin/unverified-users Super Admin Only
Get Unverified Users - Get list of unverified mentors, vendors, and teachers
GET /admin/trainee-teachers Super Admin / Admin
Get Trainee Teachers - Get list of all trainee teachers with supervisor information
Response:
{
  "success": true,
  "message": "Trainee teachers fetched successfully",
  "data": [
    {
      "_id": "...",
      "name": "...",
      "teacherRole": "trainee_teacher",
      "trainingStatus": "in_progress",
      "trainingStartDate": "...",
      "supervisorId": { "name": "...", "email": "..." },
      ...
    }
  ]
}
PATCH /admin/promote-trainee/:id Super Admin / Admin
Promote Trainee Teacher - Promote a trainee teacher to regular teacher. Training status must be "in_progress".
URL Parameters:
id string
Trainee teacher ID
Response:
{
  "success": true,
  "message": "Trainee teacher promoted to regular teacher successfully",
  "data": {
    "_id": "...",
    "teacherRole": "regular_teacher",
    "trainingStatus": "completed",
    "trainingEndDate": "...",
    ...
  }
}

👩‍🏫 Teacher APIs

GET /teacher/all Super Admin / Admin / Head Teacher
Get All Teachers - Get list of all teachers. Includes creator information in createdBy field.
GET /teacher/verified Super Admin / Admin / Head Teacher
Get Verified Teachers - Get list of verified teachers only
GET /teacher/role/:role Super Admin / Admin
Get Teachers by Role - Filter teachers by role (head_teacher, subject_teacher, class_teacher, assistant_teacher, regular_teacher, trainee_teacher)
URL Parameters:
role string
Teacher role: head_teacher, subject_teacher, class_teacher, assistant_teacher, regular_teacher, trainee_teacher
GET /teacher/subject/:subject Super Admin / Admin
Get Teachers by Subject - Get teachers who teach a specific subject
GET /teacher/class/:class Super Admin / Admin
Get Teachers by Class - Get teachers assigned to a specific class
GET /teacher/profile/me Teacher Only
Get Own Profile - Teacher can view their own profile
PATCH /teacher/:id Super Admin / Admin / Teacher
Update Teacher - Update teacher information. Teachers can update their own profile.
Request Body (all fields optional):
{
  "name": "string",
  "phone": "string",
  "teacherRole": "string",
  "subjects": ["string"],
  "classes": ["string"],
  "qualification": "string",
  "experience": "number",
  "address": "string",
  "photo": "string"
}

👤 User APIs

GET /user/my-profile Authenticated
Get My Profile - Get own profile for any authenticated user

🔑 Authentication

How to use authenticated endpoints:
  1. Login using appropriate login endpoint
  2. Copy the accessToken from response
  3. Add header: Authorization: Bearer {accessToken}
  4. Include this header in all authenticated requests

📋 Teacher Roles

Available Teacher Roles:
  • head_teacher - প্রধান শিক্ষক
  • subject_teacher - বিষয় শিক্ষক
  • class_teacher - শ্রেণি শিক্ষক
  • assistant_teacher - সহকারী শিক্ষক
  • regular_teacher - সাধারণ শিক্ষক (default)
  • trainee_teacher - প্রশিক্ষণরত শিক্ষক
📝 Trainee Teacher Flow:
  1. Admin creates trainee teacher with teacherRole: "trainee_teacher"
  2. Optionally assign supervisorId (must be a verified teacher, not trainee)
  3. trainingStartDate is auto-set, trainingStatus: "in_progress"
  4. Trainee teacher works under supervision
  5. Admin promotes trainee via PATCH /admin/promote-trainee/:id
  6. Trainee becomes regular_teacher, trainingStatus: "completed"