Skip to content

Commit

Permalink
Api vform get request (#43)
Browse files Browse the repository at this point in the history
* added GET request handler for volunteer sign up page
  • Loading branch information
Waschmid authored Mar 13, 2019
1 parent e309059 commit c13a5c5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
54 changes: 46 additions & 8 deletions packages/api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,53 @@ const test = function(db, callback) {
})
}

// Console.log to show Mongodb is connected, call test function
const client = new MongoClient(uri, { useNewUrlParser: true })
client.connect((err, db) => {
client.connect((err) => {
if (err) {
console.log(err, "Connection Failed")
return
console.log(err, "Connection to db failed")
return
}
test(client, function(){
db.close()
})
console.log("Connection Seccess!\n")
})
// Console.log to show Mongodb is connected, call test function
// client.connect((err, db) => {
// if (err) {
// console.log(err, "Connection Failed")
// return
// }
// test(client, function(){
// db.close()
// })
// console.log("Connection Seccess!\n")
// })

app.get('/api/event?*', (req, res) => {
collection = client.db("events-form").collection("events")
collection.find({date: req.query.date}).toArray((err, docs) => {
if(err) {
console.log(err, "Error trying to find document")
res.send({
status: 'FAILURE'
})
return
} else if(docs.length === 0) {
console.log("Couldn't fulfill a document request")
res.send({
status: 'FAILURE'
})
return
}

let i = 0, response_data = []
docs[0].categories.forEach(category => {
response_data.push({type: category.name, servings: 0})
category.submissions.forEach(sub => {
response_data[i].servings += sub.servings
})
i++
})
res.send({
status: 'SUCCESS',
event_info: JSON.stringify(response_data)
})
})
})
1 change: 0 additions & 1 deletion packages/ui/src/Components/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export default class Item extends Component {
</Form.Group>
</div>
<br />

<Form.Group>
<Form.Checkbox
onChange={this.updateCheckbox}
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/Components/VolunteerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ export default class VolunteerForm extends Component {
}).catch(err => {
console.log(err, 'Try again.')
})
}
}

componentDidMount() {
let path = "/api/event?date=03-08-19"
Axios.get(path).then((response) => {
console.log(response.data.data)
})
}

render() {
return (
<div>
Expand Down

0 comments on commit c13a5c5

Please sign in to comment.