Skip to content

Commit

Permalink
Adding ticket API lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed May 6, 2019
1 parent b18686d commit 5398627
Show file tree
Hide file tree
Showing 8 changed files with 5,725 additions and 3,278 deletions.
10 changes: 4 additions & 6 deletions app/screens/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default () => {
const [ticketList, setTicketList] = useState([]);

useEffect(() => {
axios.get('http://127.0.0.1:2000/api/releases').then(res => {
axios.get('/api/tickets').then(res => {
setTicketList(res.data.releases);
});
}, []);
Expand Down Expand Up @@ -126,11 +126,9 @@ export default () => {

<section>
<h2>Tickets</h2>
{ticketList
.filter(t => !t.secret)
.map(t => (
<TicketCard key={t.id} ticket={t} />
))}
{ticketList.map(t => (
<TicketCard key={t.id} ticket={t} />
))}
</section>
</div>
);
Expand Down
55 changes: 0 additions & 55 deletions bundle.js

This file was deleted.

Binary file removed c7c0bb406862d517fd982990effbf9b9.png
Binary file not shown.
37 changes: 37 additions & 0 deletions lambda/tickets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const axios = require('axios');

exports.handler = function(event, context, callback) {
axios
.get('https://api.tito.io/v3/trace-events/react-rally-2019/releases', {
headers: {
Authorization: 'Token token=' + process.env.TITO_ACCESS_TOKEN,
},
})
.then(res => {
res.data.releases = res.data.releases
? res.data.releases.filter(r => !r.secret)
: res.data.data
.filter(r => !r.attributes.secret)
.map(r => ({
title: r.attributes.title,
description: r.attributes.description,
price: r.attributes.price,
start_at: r.attributes['start-at'],
sold_out: r.attributes['sold-out'],
}));

delete res.data.data;

callback(null, {
statusCode: res.status,
headers: res.headers,
body: JSON.stringify(res.data),
});
})
.catch(err => {
callback(err, {
statusCode: 500,
body: null,
});
});
};
3 changes: 3 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
command = "npm run build"
functions = ".netlify/functions"
Loading

0 comments on commit 5398627

Please sign in to comment.