function getPlaces (req , res) { console.log("getPlaces ..."); console.log(JSON.stringify(req.headers)); ACS.Places.search({ } , function (e) { if (e.success) { console.log("Successful!"); res.send(e.places); } else { res.send(500 , { error: e.message }); } } , req , res); }
function list (req , res) { console.log("lat: " + req.query.lat * 1 + ", lon: " + req.query.lon * 1); ACS.Places.query({ //page: 1 , //per_page: 10 , where: { lnglat: { '$nearSphere': [req.query.lon * 1 , req.query.lat * 1] , '$maxDistance': req.query.d * 1 / 6371 } , type: "office" } //,sel: JSON.stringify({all: ["id", "name", "address", "city", "postal_code", "latitude", "longitude", "photo", "photo.id", "photo.urls", "urls", "photo.urls.original"]}) ,sel: JSON.stringify({all: ["id", "name", "address", "city", "postal_code", "latitude", "longitude"]}) } , function (e) { if (e.success) { //sort by distance to user location var latlon = new LatLon(req.query.lat, req.query.lon); console.log(JSON.stringify(latlon)); var sortedPlaces = _.sortBy(e.places, function(place) { var distance = latlon.distanceTo(new LatLon(place.latitude, place.longitude)); console.log("distance from user to " + place.name + " = " + distance + "km"); place.distance = distance; return distance * 1; }); console.log("sorted Offices: " + JSON.stringify(sortedPlaces)); res.send(JSON.stringify(sortedPlaces)); } else { console.log(JSON.stringify(e)); res.send(500, { message: e.message, status: "ERROR" }); } }); }
function mixParticipants(req, res) { //find all events for a specific date and time and location //mix the participants //close the boarding gate for that event //send out emails and/or icals to the participants var _ = require("underscore"); console.log("mixParticipants ..."); ACS.Places.query({ type : "canteen" }, function(e) { if (e.success) { //iterate all canteens for (var i = 0; i < e.places.length; i++) { ACS.Events.query({ id : e.places[i].id }, function(e2) { if (e2.success) { var participants = []; var participantArrays = _.map(e2.events, function(evt) { return evt.custom_fields.participants; }); //console.log("participantArrays = " + JSON.stringify(participantArrays)); for (var j = 0; j < participantArrays.length; j++) { for (var k = 0; k < participantArrays[j].length; k++) { participants.push(participantArrays[j][k]); } } //mix participants and distribute them over the // existing events. remove all other events //get random array of participants: participants = _.shuffle(participants); //re-distribute randomized participants over events for (var l = 0; l < e2.events.length; l++) { var event = e2.events[l]; var custom_fields = event.custom_fields; custom_fields.participants = []; for (var m = 0; m < 4; m++) { if (participants.length > 0) { var participant = participants.shift(); custom_fields.participants.push(participant); if (m == 0) { custom_fields.participant_0 = participant; } else if (m == 1) { custom_fields.participant_1 = participant; } else if (m == 2) { custom_fields.participant_2 = participant; } else { custom_fields.participant_3 = participant; } } } //get rid of empty events if (custom_fields.participants.length == 0) { delete e2.events[l]; } else { ACS.Events.update({ event_id : event.id, session_id : global.adminUserSession, custom_fields : custom_fields }, function(e2) { console.log(JSON.stringify(e2)); res.send({ status : "OK" }); }); } } res.send(participants); } }, req, res); } } }, req, res); }