Coder Social home page Coder Social logo

sugarwizard-backend's Introduction

This is the backend for the Sugarwizard app - an open source web app to help diabetics calculate their insulin dosage.

Setup to run locally:

Go to MongoDB and create a database, a user and a free Shared Tier Cluster (you can use any cloud provider or region). Make sure to set the network access so that your IP address has access - if in doubt set to anywhere (0.0.0.0/0)
Go to connect -> connect your application and set the .env DATABASE_URL to the connection string. Don't forget to replace <password>
Set the .env JWT_SECRET to a random string.
Run npm i then npm start and the server should be running on localhost:3000.

User model:

{
  email: { type: String, required: true },
  password: {type: String, required: true},
  insulinRatio: { type: Number, required: true},
  carbRatio: { type: Number, required: true},
  glucose_reading: { type: Array },
  time: { type : Array }
},
{ timestamps: true },

REST API with four routes (see postman collection here):

Post /api/login —> calls loginUser

{
  "email": "",
  "password": "",
}
  • Get the email and password from the request
  • Find a user with the same email
  • Compare the password with the hash for that user using bcrypt.compare
  • Create and return a JWT token with the user id as the payload

Post /api/signup ==> calls createUser:

{
  "email": "",
  "password": "",
  "insulinRatio": 1,
  "carbRatio": 1
}
  • check if there is an existing user with that email
  • hash the password with bcrypt and set the hash as the password’s value
  • create a user using the user model
  • Save the user
  • Create a token using JWT
  • Return the token

Put /api/store-data —> calls authentication middleware and updateUser

{
"glucose_reading": 1,
"time": ""
}

Get /api/profile —> calls authentication middleware and getUserById

sugarwizard-backend's People

Contributors

amberrignell avatar joshdao avatar licern avatar jessica440 avatar

Watchers

James Cloos avatar  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.