0

I am a beginner in angular / node and I have a question that maybe can be simple (I believe) ...

I was following the "Tour of Heroes" tutorial and started to wonder if it would be possible to have a type of "Contract"

Contract would receive the data of the api Hero (id, name ...) and also data of another api "Company" (id, name, location ...) and then join everything in a called api "Contract".

Then in that case I could list "Contract ID" or "contract number", and see the information (which company, which hero, that kind of thing)

Is it possible to do this with node, angular and mysql? if it is ... Could you show me some example or tutorial to follow?

Thank you!

1 Answer 1

1

That is possible and easy, you just need a few things set up:

  1. Your db needs a contract table (assuming you want a many to many relationship between heroes and companies) where you set foreign keys to the hero_id and the company_id.
  2. You need a new endpoint in your server that receives the contractId as a parameter and then you can do a request to your mysql db that uses your contract table to join the company to the hero, i.e.

    SELECT * FROM hero AS h JOIN contract AS cont ON h.id = cont.hero_id JOIN company AS comp ON comp.id = cont.company_id WHERE cont.id = ? ;

(replace the ? with the contract id you receive from the endpoint, ideally using prepared statements for mysql or a similar solution like the one mysqljs provides)

Angular will just need to call the new endpoint with a contractId parameter and you should receive the data if it exists.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.