Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Convert to TS partial #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions public/javascripts/whereispulkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
16 changes: 7 additions & 9 deletions routes.js → routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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");
}
Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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'){
Expand Down