Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Political app to keep track of your representatives

License

NotificationsYou must be signed in to change notification settings

kqarlos/election-year

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


LanguagesTop LanguageCode SizeRepo SizeTotal LinesMySQL2 VersionExpress VersionExpress-Handlebars VersionChart.js VersionSequelize VersionLast CommitIssuesFollowers

Description

Election Year informs users about their congressional representatives and their campaign finance donation history.

Table of Contents

Installation

Live Site

Usage

  1. Search Functionality

Site

  1. Profile Demo

Site

  1. Database population

Site

Code Snippets

  1. 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.
  1. 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.
  1. 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.

Credits

Authors

Built With


HMTLCSSJavascriptBootstrapNodeExpressMySQLHandlebars

License


MIT license

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript75.2%
  • Handlebars23.0%
  • CSS1.8%

[8]ページ先頭

©2009-2025 Movatter.jp