Giter Club home page Giter Club logo

leila100 / nutrition-tracker-be Goto Github PK

View Code? Open in Web Editor NEW

This project forked from labspt3-nutrition-tracker/nutrition-tracker-be

0.0 1.0 0.0 1.76 MB

This API covers all key use cases related to the HelloMelon. The API uses GraphQL which is a query language for APIs and it gives users the ability to query exactly what is needed and nothing more.

Home Page: https://nutrition-tracker-be.herokuapp.com/

License: MIT License

JavaScript 100.00%

nutrition-tracker-be's Introduction

HelloMelon Backend ReadMe and Documentation

Table of Contents

HelloMelon API

This API covers all key use cases related to the HelloMelon. The API uses Graph QL which is a query language for APIs and it gives users the ability to query exactly what is needed and nothing more.

As of now, using HelloMelonr API can only be used in conjunction with Google's Oauth2 API as it is used to check for a verified and active Token upon logging in for the front end.

Whether you use this project, have learned something from it, or just like it, please consider supporting it by donating to Lambda School's Perpetual Access Funds. This fund is used to provide student who have financial needs be able to continue their journey in Lambda School

Every dollar you donate to the Fund will be used to help someone create a new life for themselves. We hope you'll join us in helping students who need it most.

note: click on the image below to donate:

button

Authors

Covered Use Cases

  • Creating, Updating, Reading
    • users
  • Full CRUD functionality for
    • foods
    • foodEntries
    • messages
    • exerciseEntries
    • weightentries
  • Create, Read, and Delete
    • coaches
    • billing
  • Read functionality for
    • mealCategories

Using the API for the front end requires a check using Google's Oauth2 Client API. This would check against the user info and would result in an active token to be used in the headers

Technologies

Project is created with:

  • Apollo Server version: 2.5.0
  • dotenv version: 8.0.0
  • google-auth-library version: 4.0.0
  • graphql version: 14.3.0
  • graphql-merge-resolvers version: 1.1.10
  • knex version: 0.17.6
  • pg version: 7.11.0
  • sqlite3 version: 4.0.8
  • strip version: 7.1.0

Setup

To run this project, install it locally using yarn:

$ cd nutrition-tracker-BE/
$ yarn install
$ yarn start

Or to use an already existing API to get started:

HelloMelon

User Model

The following are the data that can be returned in User Model Queries:

  • id
  • firstName
  • lastName
  • email
  • userType
  • calorieGoal
  • weight
  • foodEntries - uses foodEntries model
  • exerciseEntries - uses exerciseEntries model
  • stripe_id
  • trainees

Note: There are 3 userType: basic, premium, coach

User - Queries

getCurrentUser: this query requires an object in the HTTP header with the following key value pairs.

{ "authorization": "THE_GOOGLE_TOKEN_GENERATED"}

The following is an example of a getCurrentUser query:

getCurrentUser query

getUsers: this query returns every user from the API

The following is an example of a getUsers query:

getUsers query

getUserBy: this query uses two arguments to check the API for a user that has that specific param - value match.

1) param: a column from the User model
2) value: a String value

The following is an example of a getUserBy query:

getUserBy query

getUserById: this query uses a userId argument to query a user with that specific id.

The following is an example of a getUserById query:

getUserById query

getFoodEntriesByUserId: this query uses a userId argument to query all the food that belongs to that specific userId.

The following is an example of a getFoodEntriesByUserId query:

Note: This query uses the FoodEntries Model which will be mentioned in a further section

getFoodEntriesByUserId query

getExerciseEntriesByUserId: this query uses a userId argument to query all the exercise activities that belongs to that specific userId.

The following is an example of a getExerciseEntriesByUserId query:

Note: This query uses the ExerciseEntries Model which will be mentioned in a further section

getExerciseEntriesByUserId query

User - Mutations

addUser: this mutation inserts a user into users table in the API

Note: It uses the following arguments wrapped in an input object with all being mandatory except for the weight

  firstName: String!
  lastName: String!
  email: String!
  userType: String!
  calorieGoal: Int!
  weight: Int

The following is an example of a addUser mutation:

getExerciseEntriesByUserId mutation

updateUser: this mutation edits an existing user entry in the API. Like the addUser, it requires the same mandatory arguments. Only weight is optional

It differs in that it has two main argument:

1) id
2) input object - The same input from addUser

The following is an example of an updateUser mutation:

getExerciseEntriesByUserId mutation

deleteUser: this mutation deletes a user from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteUser mutation:

getExerciseEntriesByUserId mutation

Food Model

The following are the data that can be returned in Food Model Queries:

  • id
  • foodName
  • caloriesPerServ
  • fats
  • carbs
  • proteins
  • edamam_id
  • foodEntries - uses foodEntries model

Food - Queries

getFoods: this query gets all the existing Foods in the database

The following is an example of a getFoods query:

getFoods query

getFoodById: this query gets a Food object using it's id

The following is an example of a getFoodById query:

getFoodbyId query

Food - Mutations

addFood: this mutation inserts a food object into the foods table

Note: It uses the following arguments wrapped in an input object with all being mandatory except for edamam_id

  foodName: String!
  caloriesPerServ: Int!
  fats: Float!
  carbs: Float!
  proteins: Float!
  edamam_id: String

The following is an example of an addFood mutation

addFood mutation

updateFood: this mutation edits an existing food object entry using two arguments. Like addFood, it uses the same mandatory arguments.

It differs in that it has two main argument:

1) id
2) input object - The same input from addFood

The following is an example of an updateFood mutation

updateFood mutation

deleteFood: this mutation deletes a food object from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteFood mutation:

deleteFood mutation

Meal Category Model

Due to executive decisions, we've decided remove update, edit, and delete of meal categories in order to simplify meals into 4 categories.

1) id: 1, mealCategoryName: Breakfast  
2) id: 2, mealCategoryName: Lunch
3) id: 3, mealCategoryName: Snack
4) id: 4, mealCategoryName: Dinner

The following are the data that can be returned in Meal Category Model Queries:

  • id
  • mealCategoryName
  • foodEntries -uses foodEntry Model

Meal Category - Queries

getMealCategories: this query gets all of the existing mealCateogries in the API

The following is an example of a getMealCategories query:

getMealCategories query

getMealCategoryBy: this query uses two arguments to check the API for a mealCategory that has that specific param - value match.

1) param: a column from the User model
2) value: a String value

The following is an example of a getMealCategoryBy query:

getMealCategoryBy query

getMealCategoryById: this query uses an meal category's id as an argument to query a meal category with that specific id.

The following is an example of a getMealCategoryById query:

getMealCategoryById query

Food Entry Model

The following are the data that can be returned in FoodEntry Model Queries:

  • id
  • date
  • food_id - can return food model data
  • user_id - can return user model data
  • servingQty
  • meal_category_id - can return meal category model data

Food Entry - Queries

getFoodEntries: this query is used to get all the foodEntries in the API

The following is an example of a getFoodEntries query:

getFoodentries query

getFoodEntriesById: this query uses the foodEntries' id and gets a Food entry object using it's id

The following is an example of a getFoodEntriesById query:

getFoodEntriesById query

Food Entry - Mutations

addFoodEntry: this mutation inserts a food entry object into the foodEntries table

Note: It uses the following arguments wrapped in an input object with all being mandatory

  date: Date!
  food_id: ID!
  user_id: ID!
  servingQty: Int!
  meal_category_id: ID!

The following is an example of an addFoodEntry mutation

addFoodEntry mutation

updateFoodEntry: this mutation edits an existing food entry object entry using two arguments. Like addFoodEntry, it uses the same mandatory arguments in input.

It differs in that it has two main argument:

1) id
2) input object - The same input from addFoodEntry

The following is an example of an updateFoodEntry mutation

updateFoodEntry mutation

deleteFoodEntry: this mutation deletes a food entry object from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteFoodEntry mutation:

deleteFoodEntry mutation

Exercise Entry Model

The following are the data that can be returned in Exercise Model Queries:

  • id
  • exerciseEntryDate
  • exerciseName
  • caloriesBurned
  • exercise_entry_user_id - uses the User Model

Exercise Entry - Queries

getExerciseEntries: this query returns every exercise entries from the API

The following is an example of a getExerciseEntries query:

getExerciseEntries query

getExerciseEntryBy: this query uses two arguments to check the API for an exercise entry that has that specific param - value match.

1) param: a column from the exercise entry model
2) value: a String value

The following is an example of a getExerciseEntryBy query:

getExerciseEntryBy query

getExerciseEntryById: this query uses an exercise entry id argument to query an exercise entry with that specific id.

The following is an example of a getExerciseEntryById query:

getExerciseEntryById query

Exercise Entry - Mutations

addExerciseEntry: this mutation inserts an exercise entry object into the exerciseEntries table

Note: It uses the following arguments wrapped in an input object with all being mandatory

exerciseEntryDate: Date!
exerciseName: String!
caloriesBurned: Int!
exercise_entry_user_id: ID!

The following is an example of an addExerciseEntry mutation

addExerciseEntry mutation

updateExerciseEntry: this mutation edits an existing exercise entry object entry using two arguments. Like addExerciseEntry, it uses the same mandatory arguments in input.

It differs in that it has two main argument:

1) id
2) input object - The same input from addExerciseEntry

The following is an example of an updateExerciseEntry mutation

updateExerciseEntry mutation

deleteExerciseEntry: this mutation deletes an exercise entry object from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteExerciseEntry mutation:

deleteExerciseEntry mutation

Weight Entry Model

The following are the data that can be returned in weightEntry Model Queries:

  • id
  • date
  • weight
  • user_id - This uses the user model data

Weight Entry - Queries

getWeightEntries: this query returns every weight entries from the API

The following is an example of a getWeightEntries query:

getWeightEntries

getWeightEntriesByUserId: this query uses a userId as an argument in order to get all the weight entries made by that user.

The following is an example of a getWeightEntriesByUserId query:

getWeightEntriesByUserId query

Weight Entry - Mutations

addWeightEntry: this mutation inserts an exercise entry object into the weightEntries table

Note: It uses the following arguments wrapped in an input object with all being mandatory

  date: Date!
  weight: Float!
  user_id: ID!

The following is an example of an addWeightEntry mutation

addWeightEntry mutation

updateWeightEntry: this mutation edits an existing weight entry object entry using two arguments. Like addWeightEntry, it uses the same mandatory arguments in input.

It differs in that it has two main argument:

  1) id
  2) input object - The same input from addWeightEntry

The following is an example of an updateWeightEntry mutation

updateWeightEntry mutation

deleteWeightEntry: this mutation deletes an weight entry object from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteWeightEntry mutation:

deleteWeightEntry mutation

Coaches Model

The following are the data that can be returned in Exercise Model Queries:

Note: The coaches model uses the User model for both its coach and trainee data. It's a purely relational table.

  • id
  • foodName
  • caloriesPerServ
  • fats
  • carbs
  • proteins
  • edamam_id
  • foodEntries - uses foodEntries model

Coaches - Queries

getTrainees: this query uses a coach_id as an argument in order to get a list of that coach's trainees.

The following is an example of a getTrainees query:

getTrainees query

getCoaches: this query uses a trainee_id as an argument in order to get a list of that trainee's coach(es).

The following is an example of a getCoaches query:

getCoaches query

Coaches - Mutations

Note: As the coaches table is a relational table, it's arguments are coach_id and trainee_id only. The result of both the addTrainees and deleteTrainees are the same data coming off a user model.

addTrainees: this mutation uses coach_id and trainee_id in that order in order to add a trainee to the coach's list of trainees.

The following is an example of an addTrainees mutation:

addTrainees mutation

deleteTrainees: this mutation uses coach_id and trainee_id in that order in order to delete that trainee from the coach's list of trainees.

The following is an example of an deleteTrainees mutation:

deleteTrainees mutation

Messages Model

The following are the data that can be returned in Messages Model Queries:

  • id: ID!
  • created_at: Date!
  • type: String!
  • text: String!
  • read: Boolean!
  • sender: User!
  • recipient: User!

Messages - Queries

getMessagesBy: this query uses two arguments to query message(s) based on the param (the table columns), and the value: the value of the column. It returns objects that matches the param: value

The following is an example of an getMessagesBy query:

getMessagesBy query

Messages - Mutations

addMessage: this mutation inserts an message object into the messages table

Note: It uses the following arguments wrapped in an input object with all being mandatory

  type: String!
  text: String!
  read: Boolean!
  sender: ID!
  recipient: ID!

The following is an example of an addMessage mutation

addMessage mutation

updateMessage: this mutation edits an existing message entry object entry using two arguments. Like addMessage, it uses the same mandatory arguments in input.

It differs in that it has two main argument:

  1) id
  2) input object - The same input from addMessage mutation

The following is an example of an updateMessage mutation

updateMessage mutation

deleteMessage: this mutation deletes an message object from the API

It contains only the id argument and requires no output as it returns a 1 for successful deletion and 0 for unsuccessful deletions.

The following is an example of a deleteMessage mutation:

deleteMessage mutation

Billing Model

The following are the data that can be returned in a Billing Model Queries:

  • id: ID!
  • date: Date!
  • user_id: User!
  • amount_paid: Int!

Billing - Queries

getBillingHistory: this query uses the user_id as an arguments to query the billing history of a user. It returns an object with all the payments a user has made.

The following is an example of a getBillingHistory query:

getBillingHistory query

getRecentBilling: this query uses the user_id as an argument to query the most recent payment a user has made. It returns an object just the most recent payment. If a user has not upgraded, it returns null.

The following is an example of a getRecentBilling query:

getRecentBilling query

Billing - Mutations

createSubscription: this mutation uses three argument: source, email, and amount. The source is a String that stripe sends back as a temporary made up number for charging a card, the email is a user's email, and the amount is 700 (premium) or 1000 (coach) depending on the user type.

The following is an example of a createSubscription mutation:

createSubscription mutation

updateUserType: This mutation updates a user's userType to a basic user if the date from the last payment is greater than 30 days. It returns a value of 1 as a response.

The following is an example of a updateUserType mutation:

updateUserType mutation

License

You can check the full license here

This project is licensed under the terms of the MIT license

nutrition-tracker-be's People

Contributors

david-chua avatar leila100 avatar abravebee avatar landoooooo avatar koennecker avatar jrizza88 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.