Microservice using NodeJS to count votes for candidates. This microservice will allow users to:
- Register Voters
- Login as a Voter
- See Candidates List
- See Results page with votes breakdown
- Submit a vote ( upto 3 times )
1. NodeJS / NPM - https://nodejs.org/en/download/
2. A modern browser - https://www.google.co.uk/chrome/browser/desktop/
3. GIT (optional)
1. git clone https://github.com/DilwoarH/CountMeUp
2. npm install
3. npm start
4. Navigate to http://localhost:1337/init // this will initialise candidates
npm start;
Navigate to http://localhost:1337/
npm test;
1. Register Voter
POST /register
PAYLOAD:
{
"name": "Test Voter",
"email": "[email protected]",
"password": "password123"
}
2. Login with Voter details
POST /login
PAYLOAD:
{
"email": "[email protected]",
"password": "password123"
}
3. See Candidate list
GET /candidates
4. Vote for Candidate
POST /votes
PAYLOAD:
{
"candidate_id": 1
}
5. See Results
GET /results
This is work which was considered but was out of scope for the project:
- Additional Candidate Details
- Ability to Add Candidates
- Ability to Delete Candidates
- Ability to see results in percentage aswell as number of votes
- Views / UI
- Voter Details
- Admin User / Admin User Functionality (This will be needed for showing results)
PAYLOAD:
{
"name": "Test Voter",
"email": "[email protected]",
"password": "password123"
}
RESPONSE:
{
"success": true
}
PAYLOAD:
{
"name": "Test Voter",
"email": "[email protected]",
"password": "password123"
}
RESPONSE:
{
"error": "User Already Registered"
}
PAYLOAD:
{
"email": "[email protected]",
"password": "password123"
}
RESPONSE:
{
"success": true
}
PAYLOAD:
{
"email": "[email protected]",
"password": "password123zzzzzzz"
}
RESPONSE:
{
"error": "Invalid request."
}
{
"success": true
}
[
{
"candidate_id": 1,
"candidate_name": "Paul Walker",
"votes": 24
},
{
"candidate_id": 2,
"candidate_name": "Vin Diesel",
"votes": 0
},
{
"candidate_id": 3,
"candidate_name": "Michelle Rodriguez",
"votes": 0
},
{
"candidate_id": 4,
"candidate_name": "Jordana Brewster",
"votes": 0
}
]
[
{
"id": 1,
"name": "Paul Walker",
"createdAt": "2017-05-15T00:28:58.477Z",
"updatedAt": "2017-05-15T00:28:58.477Z"
},
{
"id": 2,
"name": "Vin Diesel",
"createdAt": "2017-05-15T00:28:58.477Z",
"updatedAt": "2017-05-15T00:28:58.478Z"
},
{
"id": 3,
"name": "Michelle Rodriguez",
"createdAt": "2017-05-15T00:28:58.478Z",
"updatedAt": "2017-05-15T00:28:58.478Z"
},
{
"id": 4,
"name": "Jordana Brewster",
"createdAt": "2017-05-15T00:28:58.478Z",
"updatedAt": "2017-05-15T00:28:58.478Z"
}
]
PAYLOAD:
{
"candidate_id": 1
}
RESPONSE:
{
"success": true
}
PAYLOAD:
{
"candidate_id": 1
}
RESPONSE:
{
"error": "Vote Invalid. You are out of votes."
}
PAYLOAD:
{
"candidate_id": 1122112
}
RESPONSE:
{
"error": "Vote Invalid. Candidate does not exist."
}
Express
- Express is a minimal and flexible Node.js web application framework that provides a robust set of features
for web and mobile applications.
Lodash
- Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
- Lodash’s modular methods are great for:
- Iterating arrays, objects, & strings
- Manipulating & testing values
- Creating composite functions
Sails.js
- Sails.js is a web framework that makes it easy to build custom, enterprise-grade Node.js apps. It is designed to resemble the MVC architecture from frameworks like Ruby on Rails, but with support for the more modern, data-oriented style of web app development. It's especially good for building realtime features like chat.