As a developer, I should get all the pin data for a given user from the firebase database.
Dev Notes
Given A developer navigated to your repo
There should see a file called smashRead.js at following location src/javascripts/components/data/smashRead.js
this file should contain code to import dependensies as shown below
import pinData from './pinData';
import userData from './userData';
import boardData from './boardData';
In this function we are trying to get the object made in following format which gives all the details about the user, their board and their pins; in sql this is exactly like joining two table data together and fetching it.
Then to create this formate we are consuming chaining the .then() to finally resolve the formated data.
const getSingleUserWIthPins = (user_id) => new Promise((resolve, reject) => {
// 1. get the user who's id is user_id
userData.getUserById(user_Id)
.then((response) => {
const user = response.data;
user.id = user_id;
user.pins = [];
// 2. get all of their boards using the user_id
boardData.getUserPinsByUserID(user_id).then((boards) => {
// 3. get ALL of the pins
pinData.getPins().then((allPins) => {
// 4. add the user owned pins to user.pin[]
boards.forEach((board) => {
const pin = allPins.find((m) => m.id === board.pin_Id);
user.pins.push(pin);
});
resolve(user);
});
});
})
.catch((err) => reject(err));
});
User Story
As a developer, I should get all the pin data for a given user from the firebase database.
Dev Notes
Given A developer navigated to your repo There should see a file called smashRead.js at following location
src/javascripts/components/data/smashRead.js
this file should contain code to import dependensies as shown belowIn this function we are trying to get the object made in following format which gives all the details about the user, their board and their pins; in sql this is exactly like joining two table data together and fetching it.
example
Then to create this formate we are consuming chaining the .then() to finally resolve the formated data.