This round is to test your Debugging capabilities, Code optimization skills and Code quality in a real world application.
This repo uses express js and mongooose to create a backend server and performs DB(MongoDB) operations.
Please carefully read the instructions mentioned below.
- DON'T CLONE THIS REPO and DON'T MAKE PULL REQUESTS TO THIS REPO. FORK this repo to your own GitHub account then clone it. Fork button is the top right corner of the page. The forked URL should look something like this: https://github.com/${YOUR_GITHUB_USERNAME}/node
- You should not use any external library for pagination.
- You should not use JS for paginating the data, pagination has to be done on DB directly.
- Create a new
.env
file by copying the.env.example
file. Runcp .env.example .env
- Install the dependencies by running
yarn
ornpm i
. - Run
npm run test
oryarn test
to run the test cases. All test cases should pass in your final submit otherwise the task is considered as incomplete. npm run seed
oryarn seed
creates 100 users and 1-5 posts per user. Use this seeder to populate the database.- Work on
src/controllers/user.controller.js@getUsersWithPostCount
TODO section only.
[GET] http://localhost:3000/users
should return all the users with their post count. This API should have server side pagination implemented.
The response from this API should be similar to the below mentioned response format.
{
"data": {
"users": [
{
"_id": "624bccc95debe2a2672738a0",
"name": "Jacklyn",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a1",
"name": "Jefferey",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a2",
"name": "Mateo",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a3",
"name": "Lyric",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a4",
"name": "Shannon",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a5",
"name": "Evelyn",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a6",
"name": "Brad",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a7",
"name": "Leslie",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a8",
"name": "Laron",
"posts": 2
},
{
"_id": "624bccc95debe2a2672738a9",
"name": "Lizeth",
"posts": 2
}
],
"pagination": {
"totalDocs": 100,
"limit": 10,
"page": 1,
"totalPages": 10,
"pagingCounter": 1,
"hasPrevPage": false,
"hasNextPage": true,
"prevPage": null,
"nextPage": 2
}
}
}