diff --git a/public/js/main.js b/public/js/main.js index 478b40c..e67b4bc 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -19,25 +19,12 @@ Date.prototype.toJSONLocal = (function() { }; }()) -const query_nominatim = (q,f)=>{ - const ENDPOINT = '/api/place/'+q; - return axios.get(ENDPOINT).then(res=>res.data).then(res=>res.filter(f)); -} +const query_nominatim = (q,f) => axios.get('/api/place/'+q).then(res=>res.data).then(res=>res.filter(f)) +const query_flight = (q) => axios.get('/api/flight/'+q).then(res=>res.data) -const query_flight = (q)=>{ - const ENDPOINT = '/api/flight/'+q; - return axios.get(ENDPOINT).then(res=>res.data); -} +const is_restauration_type = e => ["restaurant", "cafe", "pub", "bar", "fast_food", "food_court"].indexOf(e.type)!=-1; -const is_restauration_type = (item)=>{ - const arr = ["restaurant", "cafe", "pub", "bar", "fast_food", "food_court"]; - return arr.indexOf(item.type)!=-1; -} - -const is_attraction_type = (item)=>{ - const arr = ["tourism", "leisure", "place", "amenity", "highway"]; - return arr.indexOf(item.category)!=-1; -} +const is_attraction_type = e => ["tourism", "leisure", "place", "amenity", "highway"].indexOf(e.category)!=-1; const icon_type = (item)=>{ let t = item.type @@ -111,7 +98,7 @@ const app = new Vue({ window.location.href = '/'+this.journey_id; }, add_section: function(event){ - if(this.journey_data.main===undefined) this.journey_data.main=[]; + if(this.journey_data.main==undefined) this.journey_data.main=[]; this.journey_data.main.push({map:{zoom:2}, hotel:{latlon:[0,0]},places:{restaurants:[],places:[]}}); }, next_step: function(){ @@ -242,6 +229,7 @@ const app = new Vue({ save_data: function(){ this.impexp = window.btoa(JSON.stringify(this.journey_data)); + console.log(this.journey_data) axios.post('/api/'+this.journey_id, this.journey_data).then(response => { console.log("Saved...") }).catch(error => { @@ -268,7 +256,10 @@ const app = new Vue({ }, created: function () { axios.get('/api/'+this.journey_id).then(response =>{ + console.log(response) + if(response.data=='') throw "Invalid Journey Data Received"; app.journey_data = response.data; + for(let e of app.journey_data.main){ if(e.dateRange && e.dateRange.length===2){ e.dateRange[0]= new Date(e.dateRange[0]); diff --git a/router/api.js b/router/api.js index 7c79f21..8cc7182 100644 --- a/router/api.js +++ b/router/api.js @@ -14,8 +14,9 @@ module.exports = (fastify, opts, done) => { } }).then(res=>reply.send(res.data)); }else{ - reply.send([]); + return reply.send([]); } + return reply }); fastify.get('/place/:id', async (req,reply) => { const ENDPOINT = 'https://nominatim.openstreetmap.org/'; @@ -28,31 +29,32 @@ module.exports = (fastify, opts, done) => { } }).then(res=>reply.send(res.data)); }else{ - reply.send([]); + return reply.send([]); } + return reply; }); fastify.get('/:id', async (req, reply) => { - if(req.params.id == undefined){ + if(req.params.id == undefined) return reply.code(400).send({error:"No ID query parameter"}); - } - return fastify.level.db.get(req.params.id, (err, val) => { + fastify.level.db.get(req.params.id, (err, val) => { if(err){ console.warn(err); reply.send({name:"New Journey", main:[]}); } else { + console.log(JSON.parse(val)) reply.send(JSON.parse(val)); } }); + return reply }); fastify.post('/:id', async (req, reply) => { - if(req.params.id == undefined){ + if(req.params.id == undefined) return reply.code(400).send({error:"No ID query parameter"}); - } - return fastify.level.db.put(req.params.id, JSON.stringify(req.body), (err) => { + fastify.level.db.put(req.params.id, JSON.stringify(req.body), (err) => { if(err){ console.warn(err); reply.code(500).send({error:"Error with DB"}); @@ -60,25 +62,8 @@ module.exports = (fastify, opts, done) => { reply.send({content:"ok"}); } }); + return reply }); - // fastify.delete('/:id',(req, reply) => { - // if(req.params.id == undefined){ - // reply.code(400).send({error:"No ID query parameter"}); - // } else { - // fastify.level.delete(req.params.id,(err) => { - // if(err){ - // console.warn(err); - // reply.code(500).send({error:"Error with DB"}); - // } else { - // reply.send({content:"ok"}); - // } - // }); - // } - // }); - - - - done(); }; \ No newline at end of file