functions/functions code/format-review-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.dealership == params.params["dealerId"]) { 
                out.push({
                    id: e.id,
                    name: e.name,
                    dealership: e.dealership,
                    review: e.review,
                    purchase: e.purchase,
                    purchase_date: e.purchase_date,
                    car_make: e.car_make,
                    car_model: e.car_model,
                    car_year: e.car_year
                })
            }
        })
        return {entries: out};
    }
    else {
        return {"error": {"status": 404, body: "No dealerId param supplied"}};
    }
}
function main ( params ) { if ( false ) { return params . params ; } if ( params . params [ "dealerId" ] ) { let out = [ ] ; params . docs . forEach ( function ( e ) { if ( e . dealership == params . params [ "dealerId" ] ) { out . push ( { id : e . id , name : e . name , dealership : e . dealership , review : e . review , purchase : e . purchase , purchase_date : e . purchase_date , car_make : e . car_make , car_model : e . car_model , car_year : e . car_year } ) } } ) return { entries : out } ; } else { return { "error" : { "status" : 404 , body : "No dealerId param supplied" } } ; } }
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 .
//dealership specified //review is for requested dealership //no dealership specified