- Nodejs. node
12
and above is recommended. - MongoDB
- Redis
- Elasticsearch
I deliberately left some environment variable set in .env.example
- First clone this repo
- run
npm install
. - run
npm run build
- Copy
.env.example
into.env
file. (cp .env.eaxmple .env
) - run
npm start
to start the server.
To use docker:
- Clone this repo
- Run
cd stackoverflow
- Run the following command
$ docker-compose up
To view the docs via the browser, visit localhost:8000/api/v1/docs. Unfortunately it still needs some work to be consistent. I'll provide a brief description and usage techniques of all existing endpoints.
-
/api/v1/users/signup
-POST
: creates a new user account.firstName
-string
,required
lastName
-string
,required
email
-string
,required
password
-string
,required
-
returns
:
{
"apiVersion": "1.0",
"status": "success",
"message": "new user created",
"data": {
"kind": "User",
"items": [
{
"active": true,
"role": "user",
"isVerified": false,
"firstName": "Jon",
"lastName": "Doe",
"email": "jon@example.com",
"password": null,
"createdAt": "2020-05-21T22:26:27.218Z",
"updatedAt": "2020-05-21T22:26:27.218Z",
"id": "5ec70013a55d093ea62d5da0"
}
]
}
}
-
/api/v1/users/signin
-POST
: authenticates a user -
Payload:
email
-string
,required
password
-string
,required
-
returns
:
{
"apiVersion": "1.0",
"status": "success",
"message": "user now logged in",
"data": {
"kind": "User",
"items": [
{
"id": "5ec70013a55d093ea62d5da0",
"email": "jon@example.com",
"isVerified": false,
"fullName": "Jon Doe",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1ZWM3MDAxM2E1NWQwOTNlYTYyZDVkYTAiLCJzdWIiOiI1ZWM3MDAxM2E1NWQwOTNlYTYyZDVkYTAiLCJyb2xlIjoidXNlciIsImlhdCI6MTU5MDEwMDMzMiwiZXhwIjoxNTkwMTAxMjMyLCJqdGkiOiIxNWMwMzg0YS01Yzc1LTRiMDAtYjZjZC1kM2IxNGQxM2Y5MGEifQ.E1ijvom5syRttHC4Owgi2tHmKGCDN2xCObdKypSGciE",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1ZWM3MDAxM2E1NWQwOTNlYTYyZDVkYTAiLCJzdWIiOiI1ZWM3MDAxM2E1NWQwOTNlYTYyZDVkYTAiLCJyb2xlIjoidXNlciIsImlhdCI6MTU5MDEwMDMzMiwiZXhwIjoxNTkxMzA5OTMyLCJqdGkiOiIxNWMwMzg0YS01Yzc1LTRiMDAtYjZjZC1kM2IxNGQxM2Y5MGEifQ.UpAqM4-hya2DnqsoZ-qQ2XU0ITfUY5OnNv9TYdM2S7o"
}
]
}
}
-
/api/v1/questions
-POST
: creates a new question record. AuthorizationBearer token
must be specified in the header. -
Payload:
title
-string
,required
body
-string
,required
tags
-array
,required
-
returns
: The created question object
/api/v1/questions/{questionID}
-GET
: fetches the question with specified ID, report 404 error if document is not found!
-
/api/v1/questions/{questionID}/upvote
-POST
: upvotes a question. AuthorizationBearer token
must be specified in the header. -
Payload:
nil
-
/api/v1/questions/{questionID}/downvote
-POST
: downvotes a question. AuthorizationBearer token
must be specified in the header. -
Payload:
nil
/api/v1/answers
-POST
: creates a new answer to a question. AuthorizationBearer token
must be specified in the header.- Payload:
text
-string
,required
question
-string
,required
/api/v1/search
-GET
: performs efficient text search.- Query String:
query
index
- [OPTIONAL]
Visit http://localhost:8000/seed
To run test npm test
should run all test suites. However if you wish to run specific test to can use pattern matching to run all tests that matches the provided pattern.
npm test -- -t=auth
would run all test cases that have auth
in it's describe
function.
- Authorisation (RBAC)
- Complete Documentation
- User Subscribe to question
- Clean up code and add more tests
- Add more code comments and doc blocks