Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muzakkirhossainminhaz/course-review-with-auth
Course Review App: TypeScript, Express.js, MongoDB. Features robust authentication, authorization, and user management. Utilizes a specific tech stack, with error handling, validation, and endpoints for seamless course, category, and review management.
https://github.com/muzakkirhossainminhaz/course-review-with-auth
authentication authorization backend-api crud crud-application crud-operation express express-js expressjs mongodb mongoose node node-js nodejs ts typescript
Last synced: 4 days ago
JSON representation
Course Review App: TypeScript, Express.js, MongoDB. Features robust authentication, authorization, and user management. Utilizes a specific tech stack, with error handling, validation, and endpoints for seamless course, category, and review management.
- Host: GitHub
- URL: https://github.com/muzakkirhossainminhaz/course-review-with-auth
- Owner: MuzakkirHossainMinhaz
- License: mit
- Created: 2023-12-30T10:31:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-16T12:37:30.000Z (about 1 year ago)
- Last Synced: 2024-11-28T07:13:23.811Z (2 months ago)
- Topics: authentication, authorization, backend-api, crud, crud-application, crud-operation, express, express-js, expressjs, mongodb, mongoose, node, node-js, nodejs, ts, typescript
- Language: TypeScript
- Homepage: https://course-review-with-auth-three.vercel.app
- Size: 91.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# course-review-with-auth
This project is a Course Review Application built using TypeScript, Express.js, and MongoDB with Authentication/Authorization. It provides a platform to manage courses, categories, and reviews with robust authentication, authorization, and user related information. The application follows a specific technology stack and includes error handling, validation, and various endpoints for creating, updating, and retrieving data.
**API Documentation** [Course Review with Auth](https://documenter.getpostman.com/view/27686738/2s9YsDjaKo) [using [Postman](https://app.postman.com)].
## Table of Contents
- [Technology Stack](#technology-stack)
- [Models](#models)
- [Course Model](#course-model)
- [Category Model](#category-model)
- [Review Model](#review-model)
- [Folder Structure](#folder-structure)
- [Dependencies](#dependencies)
- [Error Handling](#error-handling)
- [Endpoints](#endpoints)
- [How to Run the Project](#how-to-run-the-project)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [How to Contribute](#how-to-contribute)
- [About the Author](#about-the-author)
- [Acknowledgements](#acknowledgements)
- [License](#license)## Technology Stack
- **Programming Language:** TypeScript
- **Web Framework:** Express.js
- **Object Data Modeling (ODM):** Mongoose for MongoDB
- **Validation Library:** Zod
- **Authentication:** JSON Web Tokens
- **Authorization:** JSON Web Tokens
- **Password Hashing:** Bcrypt
- **Deployment:** Vercel## Models
### User Model
> - **\_id (Object ID):** A unique identifier generated by MongoDB.
> - **username (String):** A unique username of the user.
> - **email (String):** A unique email address of the user.
> - **password (String):** The password of the user.
> - **role (String):** The role of the user. e.g., user, admin. Defaults to user.### Course Model
> - **\_id (Object ID):** A distinctive identifier generated by MongoDB.
> - **title (String):** A unique title of the course.
> - **instructor (String):** The instructor of the course.
> - **categoryId (Object ID):** A reference to the category collection.
> - **price (Number):** The price of the course.
> - **tags (Array of Object):** An array of objects with "name" (string) and "isDeleted" (boolean) properties.
> - **startDate (String):** The start date of the course.
> - **endDate (String):** The end date of the course.
> - **language (String):** The language in which the course is conducted.
> - **provider (String):** The provider of the course.
> - **durationInWeeks (Integer):** The overall duration of the course in weeks.
> - **details (Object):**
> - **level (string):** e.g., Beginner, Intermediate, Advanced.
> - **description (string):** Detailed description of the course.
> - **createdBy (Object ID):** A reference to the user collection.### Category Model
> - **\_id (Object ID):** A distinctive identifier generated by MongoDB.
> - **name (String):** A _unique_ name of the category.
> - **createdBy (Object ID):** A reference to the user collection.### Review Model
> - **\_id (Object ID):** A distinctive identifier generated by MongoDB.
> - **courseId (Object ID):** A reference to the course collection.
> - **rating (Number):** Rating, which falls within the range of 1 to 5.
> - **review (String):** The comment or review text provided by the user.
> - **createdBy (Object ID):** A reference to the user collection.## Folder Structure
- **src/**: Contains all the source code files.
- **dist/**: Contains all the compiled and minified source code files.## Dependencies
- **bcrypt:** 5.1.1
- **cors:** 2.8.5
- **dotenv:** 16.3.1
- **express:** 4.18.2
- **http-status**: 1.7.3
- **jsonwebtoken:** 9.0.2
- **mongoose:** 8.0.3
- **zod:** 3.22.4## Error Handling
The application implements proper error handling throughout, using a global error handling middleware. It provides appropriate error responses with status codes and error messages. The error response object includes information about the error type, a concise error message, detailed error information, and a stack trace for debugging purposes.
## Endpoints
1. User Registration - POST `/api/auth/register`
- send a request in _JSON_ format with the mentioned fields in the request body
- returns created user with success message2. User Login - POST `/api/auth/login`
- send a request in _JSON_ format in the request body shown below
```json
{
"username": "username",
"password": "password"
}
```
- returns logged in user with success message and **jwt token**
- token payload includes user information such as `_id`, `email`, `role`, `iat` and `exp`.3. Change Password - PUT `/api/auth/change-password`
- send a request in _JSON_ format in the request body shown below
```json
{
"currentPassword": "currentPassword",
"newPassword": "newPassword"
}
```
- returns success message
- the user is required to be logged in
- the user must have a valid JWT token and cannot use current or last previous two passwords4. Create a Course (Only Admin) - POST `/api/courses`
```
Request Headers:
- Authorization:
```- send a request in _JSON_ format with the mentioned fields in the request body
- returns created course with success message5. Get Paginated and Filtered Courses - GET `/api/courses`
> Query Parameters
>
> - `page`: (Optional) Specifies the page number for paginated results. Default is 1.
> - `limit`: (Optional) Sets the number of items per page. Default is 10.
> - `sortBy`: (Optional) Specifies the field by which the results should be sorted. Applicable values are: `title`, `price`, `startDate`, `endDate`, `language`, `durationInWeeks`, `provider`, `level`.
> - `sortOrder`: (Optional) Determines the sorting order, either `asc` (ascending) or `desc` (descending).
> - `minPrice`, `maxPrice`: (Optional) Filters results by a price range.
> - `tags`: (Optional) Filters results by the name of a specific tag.
> - `startDate`, `endDate`: (Optional) Filters results by a date range.
> - `language`: (Optional) Filters results by the language of the course.
> - `provider`: (Optional) Filters results by the course provider.
> - `durationInWeeks`: (Optional) Filters results by the duration of the course in weeks.
> - `level`: (Optional) Filters results by the difficulty level of the course.6. Create a Category (Only Admin) - POST `/api/categories`
```
Request Headers:
- Authorization:
```- send a request in _JSON_ format with the mentioned fields in the request body
- returns created category with success message7. Get All Categories - GET `/api/categories`
- returns all categories with success message
8. Create a Review (Only User) - POST `/api/reviews`
```
Request Headers:
- Authorization:
```- send a request in _JSON_ format with the mentioned fields in the request body
- returns created review with success message9. Update a Course (Only Admin) - PUT `/api/courses/:courseId`
- it supports partial update with dynamic upadate
- send a request in _JSON_ format with the mentioned fields in the request body
- returns updated course with success message10. Get a Course by ID with Reviews - GET `/api/courses/:courseId/reviews`
- returns the course with its reviews and success message
11. Get the Best Course by Average Rating - GET `/api/course/best`
- returns the best course with success message and the average rating with total number of reviews## How to Run the Project
### Prerequisites
- **TypeScript** v5 or later
- **Node.js** v20 or later
- **MongoDB** v5.0 or later
- **Mongoose** v7.0 or later### Installation
1. Clone the repository
```bash
git clone https://github.com/MuzakkirHossainMinhaz/course-review-with-auth.git
```2. Navigate to the project directory
```bash
cd course-review-with-auth
```3. Install dependencies
```bash
`npm install` or `npm i`
```4. Setup Environment Variables
```bash
// create a `.env` file in the root directory and add the following variablesPORT=5000 or as_your_wish
NODE_ENV=DEVELOPMENT
DATABASE_URL=your_mongodb_url
BCRYPT_SALT_ROUNDS=10 or as_your_wish
JWT_ACCESS_SECRET=your_jwt_access_secret
JWT_ACCESS_EXPIRES_IN=1d or as_your_wish
```5. Start the server
```bash
npm run start:dev
```6. Open your browser and navigate to http://localhost:5000
## How to Contribute
We welcome contributions! If you want to contribute to this project, please follow these steps:
1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Make your changes and commit them.
4. Push your changes to your fork.
5. Submit a pull request to the `main` branch of the original repository.## About the Author
- [github.com/MuzakkirHossainMinhaz](github.com/MuzakkirHossainMinhaz)
- [linkedin.com/in/muzakkir-hossain-minhaz](linkedin.com/in/muzakkir-hossain-minhaz)## Acknowledgements
- [TypeScript](https://www.typescriptlang.org/)
- [Node.js](https://nodejs.org/en/)
- [Express](https://expressjs.com/)
- [Mongoose](https://mongoosejs.com/)
- [Zod](https://github.com/colinhacks/zod)## License
This project is licensed under the MIT License. See the [LICENSE](/LICENSE.md) file for details.