Donghoon Kim

major bug fix #3

const mysql = require('promise-mysql')
module.exports = mysql.createConnection({
host: "52.79.82.27",
user: "root",
password: "oss",
database: "OSS"
})
......@@ -93,7 +93,7 @@
<script>
var result_entertainment = [];
</script>
<script>
var entName = '';
var entType = '';
......@@ -197,7 +197,7 @@
//card+=tmp;
console.log(tmp);
document.getElementById("cardBody").innerHTML = tmp;
}
}
// const id = result['id'];
......@@ -211,7 +211,7 @@
// const lng = result.geometry.viewport.ea.j;
// const lat =result.geometry.viewport.la.j;
// for (var i = 0; i <result_entertainment.length; i++) {
// console.log("AAA");
// entName = result_entertainment[i][name];
......@@ -233,7 +233,7 @@
// '</div>';
// card+=tmp;
// }
document.getElementById("cardBody").innerHTML = card;
</script>
......@@ -291,4 +291,4 @@
</body>
</html>
\ No newline at end of file
</html>
......
......@@ -93,7 +93,7 @@
var result_food = []
var result_room = []
</script>
<script type="text/javascript" src="/js/getPlaceList.js"></script>
<script type="text/javascript" src="./js/getPlaceList.js"></script>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDg4CkUEEt_96n1ork1nL5t4E_SpdKrgMI&libraries=places&callback=initMap" async defer></script>
......
......@@ -19,12 +19,6 @@ function initMap() {
lng: position.coords.longitude
};
var map = new google.maps.Map(document.getElementById('map'), {
center: pos,
zoom: 17
});
infowindow = new google.maps.InfoWindow();
map.setCenter(pos);
service = new google.maps.places.PlacesService(map);
......@@ -44,20 +38,6 @@ function initMap() {
searchPlace('zoo','entertainment');
searchPlace('lodging','room');
// put data to db
for (var i = 0; i < results_food.length; i++) {
//putDataToDB(results_food[i], 'food')
console.log(results_food[i])
}
for (var i = 0; i < results_entertainment.length; i++) {
//putDataToDB(results_entertainment[i], 'entertainment')
console.log(results_entertainment[i])
}
for (var i = 0; i < results_room.length; i++) {
//putDataToDB(results_room[i], 'room')
console.log(results_room[i])
}
});
}
}
......@@ -95,7 +75,6 @@ function searchPlace(str, placeType) {
function callback_foods(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
putDataToDB(results[i], 'food')
createMarker_foods(results[i]);
}
}
......@@ -104,7 +83,6 @@ function callback_foods(results, status) {
function callback_entertainment(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
putDataToDB(results[i], 'entertainment')
createMarker_entertainment(results[i]);
}
}
......@@ -113,7 +91,6 @@ function callback_entertainment(results, status) {
function callback_rooms(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
putDataToDB(results[i], 'room')
createMarker_rooms(results[i]);
}
}
......@@ -160,81 +137,3 @@ function createMarker_rooms(place) {
infowindow.open(map, this);
});
}
function putDataToDB(result, category1) {
const id = result['id'];
const place_id =result['place_id'];
const name = result['name'];
const address = result['vicinity'];
let category_big = category1
const category_small = result.types[0];
const image = "default"
const rating = result.rating;
const lng = result.geometry.viewport.ea.j;
const lat =result.geometry.viewport.la.j;
if(rating == null) {
rating = 0;
}
const QueryCheck = () => {
if (!id || !place_id || !name || !address || !category_big || !category_small || !image || !rating || !lng || !lat) {
return Promise.reject({
message: 'Query Error'
})
}
return Promise.resolve()
}
// 2. SQL Start
const SQLStart = async (pool) => {
try {
let data = await pool.query('INSERT INTO PLACE(ID, PLACE_ID, NAME, ADDRESS, CATEGORY_BIG, CATEGORY_SMALL, IMAGE, RATING, LNG, LAT) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);', [id, place_id, name, address, category_big, category_small, image, rating, lng, lat])
return Promise.resolve(pool)
} catch(err) {
return Promise.reject(err)
}
}
// 3. Response
const Response = (rows) => {
return res.status(200).json(rows)
}
// 1. Query Check
const FindQueryCheck = () => {
if (!id) {
return Promise.reject({
message: 'Query Error'
})
}
else return pool
}
// 2. SQL Start
const FindSQLStart = (pool) => {
return pool.query('SELECT * FROM PLACE WHERE ID LIKE '+id.toString())
}
// 3. Response
const FindResponse = (rows) => {
return res.status(200).json(rows)
}
if([] == FindQueryCheck()
.then(FindSQLStart)
.then(FindResponse)
.catch(err => {
if (err) {
return res.status(500).json(err.message || err)
}
}))
{
QueryCheck()
.then(SQLStart)
.then(Response)
.catch(err => {
if (err) {
return res.status(500).json(err.message || err)
}
})
}
}
......
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;