functions/functions code/format-entries.js
/**
  *
  * main() will be run when you invoke this action
  *
  * @param Cloud Functions actions accept a single parameter, which must be a JSON object.
  *
  * @return The output of this action, which must be a JSON object.
  *
  */
main() will be run when you invoke this action
@param Cloud Functions actions accept a single parameter, which must be a JSON object.

@return The output of this action, which must be a JSON object.
main () will be run when you invoke this action @param Cloud Functions actions accept a single parameter which must be a JSON object . @return The output of this action which must be a JSON object .
function main(params) {
    if (false) {
        return params.params;
    }
    if (params.params["dealerId"]) {
        let out = []
        params.docs.forEach(function(e) {
            if (e.id == params.params["dealerId"]) { 
                out.push({
                    id: e.id,
                    city: e.city,
                    state: e.state,
                    st: e.st,
                    address: e.address,
                    zip: e.zip,
                    lat: e.lat,
                    long: e.long,
                    short_name: e.short_name,
                    full_name: e.full_name
                })
                return;
            }
        })
        return {entries: out};
    }
    else if (params.params["state"]) {
        let out = [];
        params.docs.forEach(function(e) {
            if (e.st === params.params["state"].toUpperCase()) { 
                out.push({
                    id: e.id,
                    city: e.city,
                    state: e.state,
                    st: e.st,
                    address: e.address,
                    zip: e.zip,
                    lat: e.lat,
                    long: e.long,
                    short_name: e.short_name,
                    full_name: e.full_name
                })
            }
        })
        return {entries: out};
    }
    else {
        return {
            entries: params.docs.map((row) => {
                return {
                    id: row.id,
                    city: row.city,
                    state: row.state,
                    st: row.st,
                    address: row.address,
                    zip: row.zip,
                    lat: row.lat,
                    long: row.long,
                    short_name: row.short_name,
                    full_name: row.full_name
                }
            })
        }
    }
}
function main ( params ) { if ( false ) { return params . params ; } if ( params . params [ "dealerId" ] ) { let out = [ ] params . docs . forEach ( function ( e ) { if ( e . id == params . params [ "dealerId" ] ) { out . push ( { id : e . id , city : e . city , state : e . state , st : e . st , address : e . address , zip : e . zip , lat : e . lat , long : e . long , short_name : e . short_name , full_name : e . full_name } ) return ; } } ) return { entries : out } ; } else if ( params . params [ "state" ] ) { let out = [ ] ; params . docs . forEach ( function ( e ) { if ( e . st === params . params [ "state" ] . toUpperCase ( ) ) { out . push ( { id : e . id , city : e . city , state : e . state , st : e . st , address : e . address , zip : e . zip , lat : e . lat , long : e . long , short_name : e . short_name , full_name : e . full_name } ) } } ) return { entries : out } ; } else { return { entries : params . docs . map ( ( row ) => { return { id : row . id , city : row . city , state : row . state , st : row . st , address : row . address , zip : row . zip , lat : row . lat , long : row . long , short_name : row . short_name , full_name : row . full_name } } ) } } }
main() will be run when you invoke this action
 @param Cloud Functions actions accept a single parameter, which must be a JSON object.
main () will be run when you invoke this action @param Cloud Functions actions accept a single parameter which must be a JSON object .
//dealer id spefified //include state //state specified //include state //no state specified