This repository contains a microservice that handles the admission database for a college. It provides functionality to store and retrieve student information using a MongoDB database with the help of Mongoose.
- Store student information in the admission database.
- Retrieve student information from the database.
- Secure storage of sensitive data.
- Timestamps for creation and last update of student documents.
- Enumerations for faculty and Nepal states.
Before installing and running this microservice, ensure that you have the following prerequisites:
- Node.js (v12 or higher)
- MongoDB
To get started with the admission database microservice, follow these steps:
- Clone this repository to your local machine.
git clone https://github.com/rahuldahal/admission.git
- Install the dependencies by navigating to the cloned repository directory and running the following command:
cd admission
npm install
- Set up the environment variables. Create a
.env
file in the root directory and provide the necessary values for the following variables:
MONGODB_URI=<your-mongodb-connection-uri>
- Start the microservice by running the following command:
npm start
The microservice should now be up and running on the specified port (default: 3000) and connected to the MongoDB database.
Once the microservice is running, you can interact with it by sending HTTP requests to the provided API endpoints. See the API Endpoints section for more details.
The following API endpoints are available for interacting with the admission database microservice:
- Endpoint:
/students
- Method: POST
- Request Body:
{
"dateOfBirth": "1990-01-01",
"mobileNo": 1234567890,
"faculty": "BIM",
"semester": 3,
"firstName": "John",
"lastName": "Doe",
"address": "123 Street",
"city": "Kathmandu",
"state": "Bagmati",
"postalCode": 44600,
"guardianName": "Jane Doe",
"guardianContact": 9876543210
}
- Response:
{
"_id": "6072f01234567890abcdef12",
"dateOfBirth": "1990-01-01",
"mobileNo": 1234567890,
"faculty": "BIM",
"semester": 3,
"firstName": "John",
"lastName": "Doe",
"address": "123 Street",
"city": "Kathmandu",
"state": "Bagmati",
"postalCode": 44600,
"guardianName": "Jane Doe",
"guardianContact": 9876543210,
"createdAt": "2021-04-11T12:34:56.789Z",
"updatedAt": "
2021-04-11T12:34:56.789Z"
}
- Endpoint:
/students
- Method: GET
- Response:
[
{
"_id": "6072f01234567890abcdef12",
"dateOfBirth": "1990-01-01",
"mobileNo": 1234567890,
"faculty": "BIM",
"semester": 3,
"firstName": "John",
"lastName": "Doe",
"address": "123 Street",
"city": "Kathmandu",
"state": "Bagmati",
"postalCode": 44600,
"guardianName": "Jane Doe",
"guardianContact": 9876543210,
"createdAt": "2021-04-11T12:34:56.789Z",
"updatedAt": "2021-04-11T12:34:56.789Z"
},
{
"_id": "6072f01234567890abcdef34",
"dateOfBirth": "1991-02-03",
"mobileNo": 9876543210,
"faculty": "BCA",
"semester": 4,
"firstName": "Jane",
"lastName": "Smith",
"address": "456 Avenue",
"city": "Pokhara",
"state": "Gandaki",
"postalCode": 33700,
"guardianName": "John Smith",
"guardianContact": 1234567890,
"createdAt": "2021-04-12T09:08:07.654Z",
"updatedAt": "2021-04-12T09:08:07.654Z"
}
]
- Endpoint:
/students/{studentId}
- Method: GET
- Response:
{
"_id": "6072f01234567890abcdef12",
"dateOfBirth": "1990-01-01",
"mobileNo": 1234567890,
"faculty": "BIM",
"semester": 3,
"firstName": "John",
"lastName": "Doe",
"address": "123 Street",
"city": "Kathmandu",
"state": "Bagmati",
"postalCode": 44600,
"guardianName": "Jane Doe",
"guardianContact": 9876543210,
"createdAt": "2021-04-11T12:34:56.789Z",
"updatedAt": "2021-04-11T12:34:56.789Z"
}
- Endpoint:
/students/{studentId}
- Method: PATCH
- Request Body:
{
"semester": 4,
"city": "Biratnagar"
}
- Response:
{
"_id": "6072f01234567890abcdef12",
"dateOfBirth": "1990-01-01",
"mobileNo": 1234567890,
"faculty": "BIM",
"semester": 4,
"firstName": "John",
"lastName": "Doe
",
"address": "123 Street",
"city": "Biratnagar",
"state": "Bagmati",
"postalCode": 44600,
"guardianName": "Jane Doe",
"guardianContact": 9876543210,
"createdAt": "2021-04-11T12:34:56.789Z",
"updatedAt": "2021-05-22T08:30:45.678Z"
}
- Endpoint:
/students/{studentId}
- Method: DELETE
- Response:
{
"message": "Student deleted successfully."
}
This microservice includes API tests using Jest and Supertest. To run the tests, follow these steps:
-
Make sure the microservice is running.
-
Open a terminal and navigate to the cloned repository directory.
-
Run the following command to execute the tests:
npm test
The tests will be executed, and the results will be displayed in the terminal.
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.