@@ -9,10 +9,11 @@ const router = express.Router()
99const { CICERO_API_KEY } = process . env
1010
1111const JURISDICTION_FILTER_MAP = {
12- federal : 'country' ,
13- state : 'administrativeArea1' ,
14- county : 'administrativeArea2' ,
15- municipality : 'locality'
12+ federal : [ 'NATIONAL_UPPER' , 'NATIONAL_LOWER' ] ,
13+ state : [ 'STATE_EXEC' , 'STATE_UPPER' , 'STATE_LOWER' ] ,
14+ county : [ 'COUNTY' ] ,
15+ local : [ 'LOCAL_EXEC' , 'LOCAL' ] ,
16+ school : [ 'SCHOOL' ]
1617}
1718const ALLOWED_JURISDICTION_FILTERS = Object . keys ( JURISDICTION_FILTER_MAP )
1819
@@ -40,27 +41,24 @@ router.get('/:zipCode', async (req, res) => {
4041 }
4142
4243 try {
44+ const params = {
45+ search_postal : zipCode ,
46+ search_country : 'US' ,
47+ order : 'district_type' , // https://cicero.azavea.com/docs/#order-by-district-type
48+ sort : 'asc' ,
49+ max : 200 ,
50+ format : 'json' ,
51+ key : CICERO_API_KEY
52+ }
53+
54+ if ( filter != null ) {
55+ params . district_type = JURISDICTION_FILTER_MAP [ filter ]
56+ }
57+
4358 const {
4459 data : { response }
4560 } = await axios . get ( 'https://cicero.azavea.com/v3.1/official' , {
46- params : {
47- search_postal : zipCode ,
48- search_country : 'US' ,
49- district_type : [
50- 'NATIONAL_UPPER' ,
51- 'NATIONAL_LOWER' ,
52- 'STATE_EXEC' ,
53- 'STATE_UPPER' ,
54- 'STATE_LOWER' ,
55- 'LOCAL_EXEC' ,
56- 'LOCAL'
57- ] ,
58- order : 'district_type' , // https://cicero.azavea.com/docs/#order-by-district-type
59- sort : 'asc' ,
60- max : 200 ,
61- format : 'json' ,
62- key : CICERO_API_KEY
63- } ,
61+ params,
6462 paramsSerializer : ( params ) =>
6563 qs . stringify ( params , { arrayFormat : 'repeat' } )
6664 } )
0 commit comments