- Clone the repository from
https://github.com/ajaytitus1386/richpanel-task-backend
using your preferred method. - Next, navigate to the root of the project and install the dependencies:
npm install
- Then, run the server on port 4000:
npm start
Or better yet just use the deployed API at https://richpanel-task-backend.herokuapp.com/
Also check out the frontend web app at https://github.com/ajaytitus1386/richpanel-task-frontend
- Node.JS with Express and MongoDB for database management
- Use a combination of a MongoDB Atlas Cluster and a Stripe API Account to manage subscriptions
- Handles authentication using JSON Web Token
- Method: POST
- Description: Register a new user in the database, encrypts the password before saving the document and then signs a JSON Web Token
- Body Data: Username, email and password
- Response: Returns a valid JWT
- Method: POST
- Description: Locates a stored user in the database by its email and matches it by the hashed password and signs a JWT
- Body Data: Email and password
- Response: Returns a valid JWT
- Method: GET
- Description: Verifies a recieved JWT
- Headers Token: token : JWT
- Response: Returns a user model
- Method: GET
- Description: Fetches all plans in the database
- Response: Returns a list of Plans
- Method: GET
- Description: Fetches a specific plan by its ID in the database
- Response: Returns one Plan
- Method: POST
- Description: Adds a new subscription for a given user to a given plan
- Body Data: See subscription model
- Method: GET
- Description: Adds a new subscription for a given user to a given plan
- Query Param: User ID in request query
- Response: Returns a single subscription
- Method: PATCH
- Description: Updates the isActive field of specified subscription to FALSE
- Method: POST
- Description: Creates a new customer and subscription payment
- Body Data: Email, Payment method id, Price ID (of product via STRIPE API)
- Response: Returns a subscription ID and a Client Secret to complete the subscription payment on frontend
- Method: POST
- Description: Cancels an Active subscription via the Stripe API
- Body Data: Subscription ID