From cc291a0c875db7f75b7ff56b7d03e3268da08c34 Mon Sep 17 00:00:00 2001 From: Pulkit Sethi Date: Sun, 30 Oct 2022 15:28:33 -0500 Subject: [PATCH] Convert to TS partial --- public/javascripts/whereispulkit.js | 18 ------------------ routes.js => routes.ts | 16 +++++++--------- 2 files changed, 7 insertions(+), 27 deletions(-) rename routes.js => routes.ts (95%) diff --git a/public/javascripts/whereispulkit.js b/public/javascripts/whereispulkit.js index f8738c0..7803e76 100644 --- a/public/javascripts/whereispulkit.js +++ b/public/javascripts/whereispulkit.js @@ -66,24 +66,6 @@ location.hash = zoom + ',' + latlng.lat + ',' + latlng.lng; }); - //Socket - let socket = io.connect(window.location.protocol + "//" + window.location.host); - - //SOCKET.IO - Listening to position updates - socket.on('position-update', (data) => { - //console.log(data); - //console.log('RECEIVED NEW POSITION: ' + data.lat + ', ' + data.long); - //Cacheing last known position locally to be used by other functions - current_position.lat = data.lat; - current_position.long = data.long; - - //Updating marker - updatePosition(data.lat, data.long); - - //Update City - updateCity(data.lat, data.long); - }); - }; const updateMap = () => { diff --git a/routes.js b/routes.ts similarity index 95% rename from routes.js rename to routes.ts index 8da9186..1a3c338 100644 --- a/routes.js +++ b/routes.ts @@ -8,7 +8,7 @@ const got = import('got'); //Setup Application Level Cache const myCache = new NodeCache({ stdTTL: 100, checkperiod: 120 }); -const convertLocationToGeoJsonLineString = (locations) => { +const convertLocationToGeoJsonLineString = (locations: any[]) => { //Converting locations into geoJSON multistring let coordinates = []; @@ -24,8 +24,8 @@ const convertLocationToGeoJsonLineString = (locations) => { return geoJSONLocations; } -const cacheLocations = (ttl, callback) => { - Location.find().sort({timestamp: 1}).exec(function(err, locations){ +const cacheLocations = (ttl: number, callback?: (err: any, geoJson: any) => void) => { + Location.find().sort({timestamp: 1}).exec(function(err: any, locations: any[]){ if(err){ console.log("Error getting LOCATIONS"); } @@ -39,16 +39,14 @@ const cacheLocations = (ttl, callback) => { console.log("CACHING: Locations"); } - //Callback - if (callback && typeof(callback) === "function") { - // execute the callback, passing parameters as necessary + if (callback) { callback(err, geoJSONLocations); } }); } -const cacheCheckins = (ttl, limit, callback) => { +const cacheCheckins = (ttl: number, limit?: number, callback?: () => void) => { //Variables let localLimit = 250; const afterTimestamp = 1370034000; //Epoch Seconds @@ -95,7 +93,7 @@ const cacheCheckins = (ttl, limit, callback) => { }); } -const cachePhotos = (ttl, callback) => { +const cachePhotos = (ttl: number, callback?: () => void) => { //Variables const flickr_api_url = 'https://secure.flickr.com/services/rest'; const method = 'flickr.photosets.getPhotos'; @@ -132,7 +130,7 @@ const cachePhotos = (ttl, callback) => { }); } -myCache.on( "expired", (key, value) => { +myCache.on( "expired", (key: string, value: any) => { console.log('EXPIRED - CHACHE: ' + key); if(key === 'locations'){