Skip to content

GoodTimeJournal/backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

130 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Your Life - Backend

With NodeJS, Postgres, and JWT

Setup

Let's get started

Download the repo, clone, and install into the directory of your choice

Install dependencies

Navigate into the backend folder, open your terminal, and type "NPM install"

Testing endpoints

Simply type "npm test" and the testing will begin

Start the server

Open your terminal and type "nodemon start"

Now you are ready to test your endpoints.

Endpoints

The database consists of three tables (Users, Activities, and Reflections)

To register a new user, send a post request to https://polar-plateau-24996.herokuapp.com/api/register

This register endpoint takes in four required fields:

{
    name: string
    email: string
    username: string
    password: string
}

This will return the id of the user you just created, which is auto-generated.

Now you can head over to login at https://polar-plateau-24996.herokuapp.com/api/login

{
    username: string
    password: string
}

If correct login information is entered, you should receive back an object with your username, your id, and a token.

{
    Welcome: username,
    userId: 1,
    token: eyJhbGciOiJIUzI1NiIsInR5cCI6Ikpxxxxx
}

This token is required to access all other endpoints.

You must mount this token into headers as Authorization: ${token}

After you have successfully logged in and mounted your token, you can head over to either:

https://polar-plateau-24996.herokuapp.com/activities

or

https://polar-plateau-24996.herokuapp.com/reflections

This get request will return a list of activities or reflections that belong to the user you are logged in as.

To post, activities takes in 5 fields, all required:

{
	name: string,
	fk: integer, foreign key field relates the userid who owns the activity
	enjoymentRating: integer,
	energyLevel: integer,
	engagement: integer
}

Reflections takes in 6 required fields:

{
	week: string,
	fk:  integer, foreign key field relates the userid who owns the activity
	journalEntry: text,
	insights: text,
	trends: text,
	surprises: text
}

Both activities and reflections auto-generate an id and a timestamp of creation date.

If you navigate to either activites or reflections endpoint with an id at the end (https://polar-plateau-24996.herokuapp.com/reflections/1), this will fetch you the reflection or activity matching that id. You can also post an update(put) to these endpoints.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •