0

I have the following structure: Volunteers VolunteerTrips Trips

Volunteer links to VolunteerTrips via volunteerId. Trips links to VolunteerTrips via tripId. I have the relations set up so I can get the trips list from volunteers and vice versa. What I'd like now is a remote method that concatenates those trips into a list.

For example, /Volunteers/tripList with a value of 1 (volunteerId) would return "belize peru". So the remote method would call /Volunteers/1/trips, loop through that list, and build a string of the tripName property then return it.

Looking at the documentation I see adding to volunteers.js something like this:

module.exports = function(Volunteers) {
    Volunteers.tripList = function(volunteerId, cb) {
      cb(null, "belize madagascar");
    }

    Volunteers.remoteMethod(
        'tripList', 
        {
          accepts: {arg: 'volunteerId', type: 'string'},
          returns: {arg: 'tripList', type: 'string'}
        }
    );
};

However, I'm stuck at how to make an additional call to get the trips, then loop through and build my string. Can someone help me?

1 Answers1

0

Have you taken a look at my example: https://github.com/strongloop/loopback-example-app-logic? Give it a shot and let me know if you run into anymore issues.

superkhau
  • 2,781
  • 18
  • 9