@danmalone89 wrote:
I’m using ember-ajax to pull some data from an external API in my model. I need data from one end point (/personalprofile) to be used in two other calls (/attorney, /cpa). However, I only want to call the personalProfile once, since it has the contact Id for both the attorney and the CPA. But, I can’t for the life of my figure out how to do both in one model. Is there a way a noob like me can reasonably combine the attorney and CPA objects in one model? For now I’m just using it like I have below, but I know I have repeated code and I feel like I’m making an unnecessary 2nd call to the /personalProfile endpoint.
model (params) { return RSVP.hash ({ CPA: this.get ('ajax') .post ('/personalProfile', { data: {contactId: params.contact_id} }) // Gets the CPA's Name .then (profileResponse => { return this.get ('ajax') .post ('/CPA', { data: { CPAId: profileResponse.ProfessionalContact_CPA } }); }), attorney: this.get ('ajax') .post ('/personalProfile', { data: {contactId: params.contact_id} }) //Gets the Attorney's name .then (profileResponse => { return this.get ('ajax') .post ('/attorney', { data: { attorneyId: profileResponse.ProfessionalContact_Attorney } }); }) }); },
Posts: 1
Participants: 1