Skip to content

Commit

Permalink
Link SelectedCountins and chapters in model.
Browse files Browse the repository at this point in the history
This also required updating the code that assigns requests to regions to
look at a counties chapters region code, and eagerly loading that
information from the database.

Issue #277: Add County, Chapter Code and Chapter Name
  • Loading branch information
Frank Duncan committed Feb 21, 2019
1 parent 03c5c7d commit 909ddd3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ db.activeRegion.belongsToMany(
}
);

db.SelectedCounties.belongsTo(db.chapter, {foreignKey:'chapter_code', targetKey:'code'});

db.sequelize.sync(options);

// TODO: This is a temporary kludge. These shouldn't really be part
Expand Down
5 changes: 4 additions & 1 deletion models/selectedCounties.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

module.exports = function(sequelize, DataTypes) {
return sequelize.define('SelectedCounties', {
region: DataTypes.TEXT,
chapter_code: {
field: 'chapter',
type: DataTypes.TEXT
},
state: DataTypes.TEXT,
county: DataTypes.TEXT
})
Expand Down
2 changes: 1 addition & 1 deletion views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.saveRequest = function(req, res) {
return utils.findCountyFromAddress(address, zip_for_lookup);
}).then( function(county_id){
if (county_id){
region_code = county_id.region;
region_code = county_id.chapter.region;
}
else {
region_code = 'XXXX';
Expand Down
2 changes: 1 addition & 1 deletion views/sms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ exports.respond = function(req, res) {
return save_utils.findCountyFromAddress(address, zip);
}).then( function(county_id){
if (county_id){
region_code = county_id.region;
region_code = county_id.chapter.region;
}
else {
region_code = 'XXXX';
Expand Down
1 change: 1 addition & 0 deletions views/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ module.exports = {

requestData.stateFromZip = address['state'];
return db.SelectedCounties.findOne({
include: [ db.chapter ],
where: {
// Use the PostgreSQL "ILIKE" (case-insensitive LIKE)
// operator so that internal inconsistencies in the
Expand Down

0 comments on commit 909ddd3

Please sign in to comment.