Skip to content

Database

ashimpaudel edited this page Jun 4, 2018 · 6 revisions

Three major nodes:

  1. Cuisines
  2. Users
  3. Orders

Each cuisine has an id, a unique key, created by .push() method. All the necessary details are inside this key.

When a user signs up for the first time, the user is assigned a unique key created by the same .push() method. Under each user there are few important fields to note:

  • Hosted-cuisines (Will be implemented on next release, explanation below)
  • Notifications
  • Booked-cuisines

The initial approach was to include all the id's of cuisines that a particular user has hosted under the key called Hosted-cuisines. Simply adding these id's to keep track of what a user has hosted is redundant. In fact, on our very first version, we tried to copy-by-value all the data again under a users node. However, this created a problem when user modified the hosted cuisine section. For example, let's say a user changed his mind and want to increase the number of the person he can host for that specific cuisine: We allow the user(host) to modify certain information like number of accommodation. In that case, we had to separately update the same info on cuisines node as well which created a lag between host updating the information and it being displayed on the main cuisines page. Hence, copy-by-value of the whole data was not a good design choice.

Our current approach is to use the built-in query like functionality provided by firebase: var hosted-cuisines-query = firebase.database().ref('cuisines').orderbychild('userID').equalTo(auth.userID);

hosted-cuisines-query.on('child_added', function(snap) { var hosted-cuisine = snap.val(); console.log(hosted-cuisine.cuisineName, hosted-cuisine.dormName); });

hosted-cuisines-query will contain the reference to all the cuisines that was hosted by the current user. This can be simply populated to the hosted-cuisines tab of the dashboard.

More information about querying firebase list using angularfire can be obtained here: angularfireGithub

Clone this wiki locally