StackOverflow Application

Adhikansh Mittal
Code To Express
Published in
2 min readSep 26, 2019

As in last blog we come to know How to make the login and Signup API and create the user session. And also learn how to create a route a Public route or a Private route. (Please refer this: https://medium.com/code-to-express/login-and-signup-page-4a65fec162f1). Now In this blog I am going to explain about the Mongoose models as well as routes which we required in our application.

So we go step by step

  1. Create a user
  2. Post a Question
  3. Post an Answer to the existing question
  4. Clap on the answer(upvote)
  5. Authentication and Role-based Access to the Stack Holders

For creating the user we already signup but here are also going to make a profile of the user and mongoose model for which is shown below

Here in this model, I mentioned different data types like String, Date.now() which are direct to understand but there is one more data type which is Schema.Types.ObjectId This data type is nothing but just referring to the Object of other models. So when a mongoose document saves in the database the value contained by this attribute will same as the Object Id of the document saved in other mongoose model.

Now I am going to make the model for the Question

Here we created answer array so there can be more than one answer to a single question. The same thing done with the upvotes where more than one user can give upvotes but the same user can not give more than one upvote.

Now for Creating the question we create routes

So here we make different routes which are written below:

routes for profile

Now I am going to make routes for the Questions

So here we make different routes which are shown below:

routes for questions with description

Here the routes I mentioned are necessary routes apart from this you can add your own routes also.

If you face any problem in creating public or private routes then Please read my Login and Signup blog.

Happy coding

--

--