Backend server for Sleep Tracker, a web app tracking sleep time and mood in order to optimize your sleep time. https://sleep-tracker-rui.herokuapp.com/
Go to file
ruihildt 31bbcb52c7 Add daily averages endpoint / move authentication 2019-08-01 21:12:20 +02:00
api Add daily averages endpoint / move authentication 2019-08-01 21:12:20 +02:00
data Add dailyAverage when providing complete session 2019-08-01 20:43:43 +02:00
services Add daily averages endpoint / move authentication 2019-08-01 21:12:20 +02:00
.eslintrc.js Add users endpoints with queries 2019-08-01 09:42:25 +02:00
.gitignore Add sessions endpoints with queries 2019-08-01 16:25:44 +02:00
LICENSE Initial commit 2019-07-29 10:47:58 +02:00
README.md Add dailyAverage when providing complete session 2019-08-01 20:43:43 +02:00
index.js Setup table migration and update schemas/endpoints 2019-07-31 20:38:48 +02:00
knexfile.js Setup table migration and update schemas/endpoints 2019-07-31 20:38:48 +02:00
package-lock.json Add package.json and project dependencies 2019-07-31 09:11:46 +02:00
package.json Update seeds with more data 2019-08-01 18:02:07 +02:00

README.md

Sleep Tracker helps Users track their sleep and mood every day. It gives Users a better idea of their sleep pattern and improve their health. After one month, Sleep Tracker will give recommendation of optimal sleep duration.

Target Audience

Sleep Tracker is intended for anyone interested in improving their sleep and health.

Features

  • Homepage view shows a graph of your nightly hours of sleep over time .
  • Ability to create a nights sleep entry. For each date set (1/1/19-1/2/19), user can scroll through a digital clock image (like when you set your alarm on your phone, or just type in) to enter what time they got in bed and what time they woke up. From this data, app will calculate their total time in bed.
  • Ability to edit or delete a sleep entry.
  • Ability to click one of four emoji buttons to rate how they felt right when they woke up, how they felt during the day, and how tired they felt when they went to bed. Behind the scenes, a score 1-4 is given for each emoji.
  • The app will calculate an average mood score for 1/2/19, and compare it to the time spent in bed. The app will then recommend after using for >1 month how much sleep you need. “Your mood score tends to be highest when you sleep 7.5 hours”

Possible further features

  • Make recommendations not only based on sleep time, but also on bed time (some reasearch will need to be done in that area)
  • Connect to third party sleep tracking services

Database Schemas

Users Schema users

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
email string required
username string required
password string required

Sleep Sessions Schema sessions

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
user_id unsigned integer foreign key referencing users.id, required
bed_time unsigned integer timestamp with date, required
wake_time unsigned integer timestamp with date, required
bed_tiredness unsigned integer
wake_mood unsigned integer
day_mood unsigned integer

Average Mood per Sleep Session Schema dailyAverages

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
session_id unsigned integer foreign key referencing sessions.id
user_id unsigned integer foreign key referencing users.id
sleep_duration unsigned integer
average_mood float

API Endpoints

  • POST /api/auth/register - add a new user

  • POST /api/auth/login - login with user/password

  • GET /api/users/:id - fetch a user

  • PUT /api/users/:id - update a user

  • DELETE /api/users/:id - delete a user

  • GET /api/users/:id/sessions - fetch list of all sessions by user id

  • POST /api/users/sessions - add a session

  • PUT /api/users/sessions/:id - update a session by id

  • DELETE /api/users/sessions/:id - delete a session by id

  • GET /api/users/:id/averages - fetch a list of last 30 daily averages by user id