forked fromboundsalexis/election-year
- Notifications
You must be signed in to change notification settings - Fork0
Political app to keep track of your representatives
License
NotificationsYou must be signed in to change notification settings
kqarlos/election-year
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Election Year informs users about their congressional representatives and their campaign finance donation history.
- Search Functionality
- Profile Demo
- Database population
- Populating the database
varoptions={method:'GET',headers:{'X-API-Key':congressAPIKey},url:url};axios(options).then(function(response){varmembers=response.data.results[0].members;for(leti=0;i<members.length;i++){db.Senator.create({name:members[i].first_name+" "+members[i].last_name,state:members[i].state,fecId:members[i].fec_candidate_id,memberId:members[i].id,party:members[i].party,gender:members[i].gender,crpid:members[i].crp_id}).then(function(r){db.VotingRecord.create({missed_pct:members[i].missed_votes_pct,votesWParty_pct:members[i].votes_with_party_pct,votesWOParty_pct:members[i].votes_against_party_pct,SenatorId:r.dataValues.id});});}});
- This block of code took care of populating both the Seantors and Voting Record tables in our database. We used axios to make the API request to Pro Publica API. The URL asked for all senators. This gave us back a list that we iterated through to create objects to send to our data models. We took advantage of the callback functions to go from the query response, to inserting a senator to our Senator table, and into creating a voting record for that specific senator. This avoided conflicts since each function was working on return data from the function before it.
- User model
module.exports=function(sequelize,DataTypes){varUser=sequelize.define("User",{name:{type:DataTypes.STRING,allowNull:false,validate:{len:{args:3,msg:"Name must be atleast 3 characters in length"}}},location:{type:DataTypes.STRING}});User.associate=models=>{models.User.hasOne(models.Login,{onDelete:"cascade"})}returnUser;}
- This is our definition for the user model. We had a simple model with a name and a location. Both of these fields had some validations that check the data before getting inserted into the table. Before the end of our model definition we inserted an association to the Login table. This one-to-one relationship will ensure that a login object can reference a unique User object.
- Handlebars
<divclass="jumbotron"><h1class="display-4"data-id={{id}}data-location={{location}}id="info">Welcome {{name}}</h1><pclass="lead">Your Representatives From {{location}}!</p><hrclass="my-4"><divclass="container"id="manip"><divclass="senators"><h3>Senators</h3><tableid="senators"></table></div><divclass="house"><h3>House of Representatives</h3><tableid="reps"></table></div></div></div>
- Handlebars makes HTML more flexible by giving us the ability to work with objects. This handlebar takes care of displaying the user data passed on from the server-side. Not only does it display the logged-in user's name and location, it also hides user data such as user id inside the HTML. This allows for the user to feel a more personalized experience and for the developer to have easy access to commonly needed user data.
Carlos Toledo
- 💼:portfolio
Github:kqarlos
- LinkedIn:carlos-toledo415
Alexis Bounds
Ian Toy