This project was created using Express, Node, and PostgreSQL.
Demo: https://enigmatic-waters-75582.herokuapp.com/
- NodeJS
- Express
- PostgresQL
Complete the following steps to start a new project (NEW-PROJECT-NAME):
- Clone this repository to your local machine
git clone BOILERPLATE-URL NEW-PROJECTS-NAME
cd
into the cloned repository- Make a fresh start of the git history for this project with
rm -rf .git && git init
- Install the node dependencies
npm install
- Move the example Environment file to
.env
that will be ignored by git and read by the express servermv example.env .env
- Edit the contents of the
package.json
to use NEW-PROJECT-NAME instead of"name": "express-boilerplate",
Start the application npm start
Start nodemon for the application npm run dev
Run the tests npm test
When your new project is ready for deployment, add a new Heroku application with heroku create
. This will make a new git remote called "heroku" and you can then npm run deploy
which will push to this remote's master branch.
All endpoints using the requireAuth
middleware require a hashed bearer token in the header. A user should be logged in to use this endpoint appropriately, and most of these endpoints require this authorization. The server uses jsonwebtoken and bcryptjs to parse and encrypt this token to prevent data collisions and provide some security for the users.
These endpoints manipulate the status of households, which group together family members. All require authorization.
Retrieves a list of households for a given parent. On success, returns an array of objects containing info for each household.
//GET api/households
//returns...
[
{
"id": 1,
"name": "Kamoshida Castle",
"user_id": 1
},
{
"id" : 2,
"name": "Madarame Museum",
"user_id": 1
}
];
The api creates a new household associated with the parent. It checks if the data contains a 'name' value. The new household is inserted into the database and assigned an id, then the API issues a response with a JSON object containing all households associated with the user, including the new one.
//POST api/households
//Body: {"name": "Kaneshiro Bank", "user_id":"1"}
//returns...
[
{
"id": 1,
"name": "Kamoshida Castle",
"user_id": 1
},
{
"id" : 2,
"name": "Madarame Museum",
"user_id": 1
},
{
"id" : 3,
"name": "Kaneshiro Bank",
"user_id": 1
}
];
Given a valid message body, will update the household information, responding with a list of all the households, including the updated one.
//PATCH api/households
//Body: {"id":"1", "name": "Futaba Pyramid", "user_id":"1"}
//returns...
[
{
"id": 1,
"name": "Futaba Pyramid",
"user_id": 1
},
{
"id" : 2,
"name": "Madarame Museum",
"user_id": 1
},
{
"id" : 3,
"name": "Kaneshiro Bank",
"user_id": 1
}
];
Given a valid household ID from a logged-in user, will delete the household, responding with a 204 status.
These endpoints manipulate the status of household members. All require authorization.
Provided a household id is included in the request params, it returns an array listing all members of the household, including their name, username and associated tasks.
//GET api/households/1/members/
[
{
"id": 1,
"name":"Morgana",
"username": "mona",
},
{
"id": 2,
"name":"Ryuji",
"username": "skull",
},
{
"id": 3,
"name":"Ann",
"username": "panther",
}
];
Adds a new member to the household by household ID, returning the full list of members.
//POST api/households/1/members
//Body: { "name":"Yusuke", "username":"fox", "password":"SecurePassword123!" }
//returns...
[
{
"id": 1,
"name":"Morgana",
"username": "mona",
},
{
"id": 2,
"name":"Ryuji",
"username": "skull",
},
{
"id": 3,
"name":"Ann",
"username": "panther",
},
{
"id": 4,
"name":"Yusuke",
"username": "fox",
}
];
Provided a member id and a body with valid new information, updates the member's info and responds with the member's info.
//PATCH api/households/1/members/1
//Body: { "name":"Akechi", "username":"loki" }
//returns...
[
{
"id": 1,
"name":"Akechi",
"username": "loki",
}
];
Provided a member id, deletes the member and returns a 204 status.
These endpoints manipulate the status of the tasks assigned to members.
Provided a household id is included in the request params, it retrieves an array with the tasks for a given household. A task is associated with a household id, title, member_id representing who the task is assigned to, and point value to award the member upon completing the task.
//GET api/households/1/tasks
[
{
"title": "Make coffee and curry",
"household_id": 1,
"member_id": 3,
"points": 20
},
{
"title": "Feed the plant",
"household_id": 1,
"member_id": 2,
"points": 8
},
{
"title": "Take your time",
"household_id": 1,
"member_id": 1,
"points": 8
},
];
Provided a household id is included in the request params, it creates a new task for the household, responding with a 201 success message.