You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The database is first queried for a user using the <i>userId</i> provided in the request. If the user is not found, the response is sent with a status code of 400 (<i>Bad Request</i>) and an error message: <i>"userId missing or not valid"</i>.
468
+
461
469
It's worth noting that the <i>user</i> object also changes. The <i>id</i> of the note is stored in the <i>notes</i> field of the <i>user</i> object:
462
470
463
471
```js
@@ -483,6 +491,8 @@ Likewise, the ids of the users who created the notes can be seen when we visit t
483
491
484
492

485
493
494
+
Due to the changes we made, the tests no longer pass, but we leave fixing the tests as an optional exercise. The changes we made have also not been accounted for in the frontend, so the note creation functionality no longer works. We will fix the frontend in part 5 of the course.
495
+
486
496
### Populate
487
497
488
498
We would like our API to work in such a way, that when an HTTP GET request is made to the <i>/api/users</i> route, the user objects would also contain the contents of the user's notes and not just their id. In a relational database, this functionality would be implemented with a <i>join query</i>.
@@ -559,6 +569,4 @@ const noteSchema = new mongoose.Schema({
559
569
560
570
You can find the code for our current application in its entirety in the <i>part4-8</i> branch of [this GitHub repository](https://github.com/fullstack-hy2020/part3-notes-backend/tree/part4-8).
561
571
562
-
NOTE: At this stage, firstly, some tests will fail. We will leave fixing the tests to a non-compulsory exercise. Secondly, in the deployed notes app, the creating a note feature will stop working as user is not yet linked to the frontend.
Tietokannasta etsitään ensin käyttäjä pyynnön mukana lähetetyn <i>userId</i>:n avulla. Jos käyttäjää ei löydy, vastataan statuskoodilla 400 (<i>Bad Request</i>) ja virheviestillä <i>"userId missing or not valid"</i>.
459
+
452
460
Huomionarvoista on nyt se, että myös <i>user</i>-olio muuttuu. Sen kenttään <i>notes</i> talletetaan luodun muistiinpanon <i>id</i>:
453
461
454
462
```js
@@ -474,6 +482,8 @@ Muistiinpanon luoneen käyttäjän id tulee näkyviin muistiinpanon yhteyteen:
474
482
475
483

476
484
485
+
Tekemiemme muutosten myötä testit eivät mene enää läpi, mutta jätämme testien korjaamisen nyt vapaaehtoiseksi harjoitustehtäväksi. Tekemiämme muutoksia ei ole myöskään huomioitu frontendissä, joten muistiinpanojen luomistoiminto ei enää toimi. Korjaamme frontendin kurssin osassa 5.
486
+
477
487
### populate
478
488
479
489
Haluaisimme API:n toimivan siten, että haettaessa esim. käyttäjien tiedot polulle <i>/api/users</i> tehtävällä HTTP GET ‑pyynnöllä tulisi käyttäjien tekemien muistiinpanojen id:iden lisäksi näyttää niiden sisältö. Relaatiotietokannoilla toiminnallisuus toteutettaisiin <i>liitoskyselyn</i> avulla.
0 commit comments