A Node.js-based API for managing schools, classrooms, and students. It includes user authentication, role-based access control, and CRUD operations.
-
Authentication and Authorization:
Role-based access control (superAdmin
for managing schools). -
CRUD Operations:
Create, Read, Update, and Delete schools, classrooms, and students. -
Validation:
Input validation usingJoi
. -
Database:
MongoDB for data persistence.
Ensure you have the following installed on your system:
-
Node.js (v16 or higher)
Download Node.js -
npm (comes with Node.js) or yarn
-
MongoDB (Local or Cloud)
Download MongoDB or use MongoDB Atlas. -
A code editor like Visual Studio Code.
Follow the steps below to set up and run the project locally:
git clone https://github.com/chaitanya-dharpale0209/soarinc.git
cd soar
npm install
Create a .env file in the project root directory and add the following environment variables:
PORT=5000
MONGO_URI=<Your MongoDB Connection String>
JWT_SECRET=<Your JWT Secret>
Replace with the connection string for your MongoDB database (local or Atlas). Replace with a secret key for signing JSON Web Tokens.
If you’re running MongoDB locally, start it using the command:
mongod
Run the following command to start the server:
node server.js
The server will start on http://localhost:5000.
Use Postman or any API client to test the endpoints. Below are some of the main routes:
Authentication Routes POST /api/auth/login: Authenticate a user. School Routes (Protected, superAdmin role required) POST /api/schools: Create a new school. GET /api/schools/getallschools: Get all schools. PUT /api/schools/updateschool/:id: Update school details. DELETE /api/schools/deleteschool/:id: Delete a school. Note: Set the Authorization header to Bearer for protected routes.
https://documenter.getpostman.com/view/24612054/2sAYJ1kh9i
- Purpose: Manages authentication and role-based access control.
- Fields:
name
(String, required)email
(String, required, unique)password
(String, required)role
(String, enum:superAdmin
,schoolAdmin
)schoolId
(ObjectId, referencesSchool
)
- Purpose: Stores school information.
- Fields:
name
(String, required)address
(String, required)contactNumber
(String, required)
- Purpose: Tracks student enrollment and transfers.
- Fields:
name
(String, required)email
(String, required, unique)schoolId
(ObjectId, referencesSchool
)status
(String, enum:enrolled
,transferred
)transferToSchoolId
(ObjectId, referencesSchool
)
- Purpose: Manages classrooms and resources.
- Fields:
name
(String, required)capacity
(Number, required)resources
(Array of Strings, required)schoolId
(ObjectId, referencesSchool
)
- StudentValidator: Validates student data.
- SchoolValidator: Validates school data.
- ClassroomValidator: Validates classroom data.
Users | | Manages v Schools | | Contains v Classrooms | | Contains v Students
Users Collection
Field | Type | Required | Notes |
---|---|---|---|
name |
String | Yes | |
email |
String | Yes | Must be unique. |
password |
String | Yes | |
role |
String | Yes | Enum: superAdmin , schoolAdmin . |
schoolId |
ObjectId | No | References the School collection. |
Field | Type | Required | Notes |
---|---|---|---|
name |
String | Yes | Name of the school. |
address |
String | Yes | Full address of the school. |
contactNumber |
String | Yes | Phone number for contacting the school. |
Field | Type | Required | Notes |
---|---|---|---|
name |
String | Yes | Name or identifier for the classroom. |
capacity |
Number | Yes | Maximum number of students. |
resources |
Array[String] | Yes | List of resources (e.g., projector). |
schoolId |
ObjectId | Yes | References the School collection. |
Field | Type | Required | Notes |
---|---|---|---|
name |
String | Yes | Name of the student. |
email |
String | Yes | Must be unique. |
schoolId |
ObjectId | Yes | References the School collection. |
status |
String | Yes | Enum: enrolled , transferred . |
transferToSchoolId |
ObjectId | No | References the School collection. |