Skip to content

Latest commit

 

History

History
169 lines (141 loc) · 4.66 KB

README.md

File metadata and controls

169 lines (141 loc) · 4.66 KB

Planted

Overview:

The Planted project purpose is to assist users by collecting data from a variety of sensors ex. humidity, temperature, sunlight, and soil moister. This in hopes of helping users to keep their plants alive and thriving. Sensors send data to the server and the React Native app visualizes the data

Github Links:

Planted Github | Hardware Side | Front End

Watch demo:

Screenshots:


We took it to school!

Github Link:

Planted Github

Team Members & Roles:

Technologies used:

  • React Native
  • React
  • Redux
  • D3
  • Node
  • GraphQL
  • PostgreSQL
  • Javascript
  • Heroku
  • Python

Code snippets:

Router:

router.post('/register', async (req, res) => {
    let userInfo = await readBody(req).then(data => JSON.parse(data))
    let { avatar, username, email, password } = userInfo
    let hash = await bcrypt.hash(password, 10);
    await db.query(`
            INSERT INTO users (
                username, email, passw, avatar
            )
            VALUES (
                    '${username}',
                    '${email}',
                    '${hash}',
                    '${avatar}'
            );`)
        .catch(err => console.log(err))
    let user = await findUserByEmail(db, email);
    let token = createToken(user);
    res.end(token);
})

router.post('/graphql', async (req, res) => {
    let { authorization: token } = req.headers;
    try {
        let payload = jwt.verify(token, signature);
        let userid = payload.userid;
        let query = await readBody(req)
        let results = await getResults(query, userid);
        res.send(results)
    } catch (err) {
        console.log("POST GRAPHQL - ERROR ####", err)
        res.status(401).end('Unauthorized')
    }
})

module.exports = router;

Examples of fetching data with graphql

fetch('https://planted-dc.herokuapp.com/graphql', {
	headers: {
	"authorization": token,
},
	method: 'POST',
	body: `
	query {
	  currentUser {
        user {
            username
            avatar
        }
        plantData {
            temp
            sun
            moist
            humidity
            created
        }
	  }
    }`
})
.then( res => res.json() ).then(console.log)

#############

fetch('https://planted-dc.herokuapp.com/graphql', {
	headers: {
	"authorization": token,
},
	method: 'POST',
	body: `
    query { 
        currentUser { 
            getPlantDataFor(hours: 3) { 
                temp 
                sun 
                moist 
                humidity 
                created
            } 
        } 
    }`
})
.then( res => res.json() ).then(console.log)

###############

fetch('https://planted-dc.herokuapp.com/graphql', {
	headers: {
	"authorization": token,
},
	method: 'POST',
	body: `
    mutation {
        addPlantData(input: {temp: 70 sun: 300 moist: 24 humidity: 3.2  }) {
            userid
        } 
    }
`
})
.then( res => res.json() ).then(console.log)