/backendwaterplants

Backend for WaterMyPlants App. Built with Node, Express, Postgres, Knex, bcrpyt, JWT, Heroku Scheduler, SendGrid API, OpenWeather API

Primary LanguageTypeScript

I built this app to help people remember to water their plants at the right time. The site checks local weather to update watering schedule when it rains and sends email notifications to users to water.

Built with Typescript, React, Redux, Node, Express, Postgres, Knex, bcrpyt, JWT, Styled Components, Heroku Scheduler, SendGrid API, OpenWeather API *

WaterMyPlants API

API Endpoints

🔐 Protected Endpoints: These endpoints require the request to include an access token in the authorization header.

🔐 List Plants

Lists all plants from all users.

GET /api/plants/all
If client does not include a token
Status: 401 Unauthorized
If client includes a valid token
Status: 200 OK
[
    {
        "id": 3,
        "nickname": "Home Depot Ferns",
        "water_freq": "7",
        "img": "https://secure.img1-fg.wfcdn.com/im/11444145/resize-h800%5Ecompr-r85/1062/106296684/Palm+Plant+in+Basket.jpg",
        "baseDate": "1627663332161",
        "user_id": 6,
        "species_id": 3,
        "species": "Ficus"
    },
    {
        "id": 4,
        "nickname": "Costco Succulent",
        "water_freq": "7",
        "img": "https://target.scene7.com/is/image/Target/GUEST_380ea518-1fe9-4611-b172-c068ea5a77b9?wid=488&hei=488&fmt=pjpeg",
        "baseDate": "1627663329393",
        "user_id": 6,
        "species_id": 4,
        "species": "corn plant"
    },
    {
        "id": 7,
        "nickname": "Tall Corn Plant",
        "water_freq": "7",
        "img": "https://assets.pbimgs.com/pbimgs/rk/images/dp/wcm/202109/2657/img90z.jpg",
        "baseDate": "1627663336110",
        "user_id": 6,
        "species_id": 7,
        "species": "Corn Plant"
    },
    {
        "id": 10,
        "nickname": "Mini tree from neighbor ",
        "water_freq": "7",
        "img": "https://www.gardeningknowhow.com/wp-content/uploads/2021/01/succulent-bonsai.jpg",
        "baseDate": "1627663327765",
        "user_id": 6,
        "species_id": 10,
        "species": "Unknown"
    }
]

🔐 Get plants by user

Provides a list of all plants from one user

GET /api/plants/

Response

If client does not include a token
Status: 401 Unauthorized
{ 
"message": "Please Sign In to access this page" 
}
Status: 200 OK
[
    {
        "id": 18,
        "nickname": "Mini tree from neighbor ",
        "water_freq": "7",
        "img": "https://www.gardeningknowhow.com/wp-content/uploads/2021/01/succulent-bonsai.jpg",
        "baseDate": "1627663327765",
        "user_id": 6,
        "species_id": 10,
        "species": "Unknown"
    },
    {
        "id": 4,
        "nickname": "Costco Succulent",
        "water_freq": "7",
        "img": "https://target.scene7.com/is/image/Target/GUEST_380ea518-1fe9-4611-b172-c068ea5a77b9?wid=488&hei=488&fmt=pjpeg",
        "baseDate": "1627663329393",
        "user_id": 6,
        "species_id": 4,
        "species": "corn plant"
    }

🔐 Create a plant for the authenticated user

Creates a plant for the authenticated user.

POST /api/plants

Input

Name Type Description
nickname string Required. The plants name
water_freq number Required. How often to water
species string The plant species
img string The URL of the item's image.
baseDate number Required. Unix Timestamp of creation time or last water time. This is used to calculated next watering
Example
{
    "nickname": "Rose Bush",
    "species": "Roses",
    "water_freq": 3,
    "img": "https://img.totallandscapecare.com/files/base/randallreilly/all/image/2018/02/tlc.shutterstock_137343065.png?auto=format&fit=max&w=1440",
    "baseDate": 1627845209358
}

Response

Status: 201 Created
{
    "id": 56,
    "nickname": "Rose Bush",
    "water_freq": "3",
    "img": "https://img.totallandscapecare.com/files/base/randallreilly/all/image/2018/02/tlc.shutterstock_137343065.png?auto=format&fit=max&w=1440",
    "baseDate": "1627845347543",
    "user_id": 6,
    "species_id": 49,
    "species": "Roses"
}

🔐 Update an item

Update an item from the menu by overwriting the entire entity. You must send the entire resource in the request.

PUT /api/plants/:id

Input

Name Type Description
nickname string Required. The plants name
water_freq number Required. How often to water
species string The plant species
img string The URL of the item's image.
baseDate number Required. Unix Timestamp of creation or last water date

If you only need to update some of the item properties, use the PATCH /api/menu/items/:id endpoint.

Example

Take the following item as an example:

{
  "nickname": "Mini tree from neighbor ",
  "species": "Unknown",
  "water_freq": 6,
  "id": 18,
  "img": "https://www.gardeningknowhow.com/wp-content/uploads/2021/01/succulent-bonsai.jpg",
  "baseDate": "1627663327765"
}

Response

If item is not found
Status: 404 Not found
{ 
"message": "We couldn't find that plant, check the id and try again"
}
If item is found
Status: 200 OK
{
    "id": 18,
    "nickname": "Mini tree from neighbor ",
    "water_freq": "6",
    "img": "https://www.gardeningknowhow.com/wp-content/uploads/2021/01/succulent-bonsai.jpg",
    "baseDate": "1627663327765",
    "user_id": 6,
    "species_id": 10,
    "species": "Unknown"
}

🔐 Remove a plant

Remove a plant.

DELETE /api/plants/:id

Response

If item is not found
Status: 404 Not found
{ 
"message": "We couldn't find that plant, check the id and try again"
}
If item is found
Status: 204 No Content
{ 
"message": "plant with id: ':id' was deleted"
}