From aced217a7d21031f04f73d104be3c0cd23ddfa21 Mon Sep 17 00:00:00 2001 From: vjrj Date: Mon, 4 Dec 2017 16:19:10 +0100 Subject: [PATCH] Improvements in fireMaps. User subs area --- imports/api/FireAlerts/FireAlerts.js | 51 +++++++++++++++++++ imports/api/FireAlerts/server/publications.js | 6 +++ imports/api/Subscriptions/Subscriptions.js | 50 ++++++++++++++++++ .../api/Subscriptions/server/publications.js | 21 ++++++++ 4 files changed, 128 insertions(+) create mode 100644 imports/api/FireAlerts/FireAlerts.js create mode 100644 imports/api/FireAlerts/server/publications.js create mode 100644 imports/api/Subscriptions/Subscriptions.js create mode 100644 imports/api/Subscriptions/server/publications.js diff --git a/imports/api/FireAlerts/FireAlerts.js b/imports/api/FireAlerts/FireAlerts.js new file mode 100644 index 0000000..4eb499b --- /dev/null +++ b/imports/api/FireAlerts/FireAlerts.js @@ -0,0 +1,51 @@ +/* eslint-disable consistent-return */ + +import { Mongo } from 'meteor/mongo'; +import SimpleSchema from 'simpl-schema'; + +const FireAlerts = new Mongo.Collection('avisosfuego'); + +FireAlerts.allow({ + insert: () => false, + update: () => false, + remove: () => false, +}); + +FireAlerts.deny({ + insert: () => true, + update: () => true, + remove: () => true, +}); + +/* Sample: + * "_id" : ObjectId("5a059c4879095a1adba47507"), + * "chatId" : null, + * "location" : { + * "lat" : 40.2324096, + * "lon" : -3.3514863, + * "text" : null + * }, + * "aviso" : ISODate("2017-11-10T12:32:08.973Z"), + * "dateformat" : "20171110", + * "geo" : { + * "type" : "Point", + * "coordinates" : [ + * -3.3514863, + * 40.2324096 + * ] + * } + * } + * */ + + +FireAlerts.schema = new SimpleSchema({ + location: Object, + 'location.lat': SimpleSchema.Integer, + 'location.lon': SimpleSchema.Integer, + aviso: Date, + } +); + +FireAlerts.attachSchema(FireAlerts.schema); + +export default FireAlerts; diff --git a/imports/api/FireAlerts/server/publications.js b/imports/api/FireAlerts/server/publications.js new file mode 100644 index 0000000..987f8f2 --- /dev/null +++ b/imports/api/FireAlerts/server/publications.js @@ -0,0 +1,6 @@ +import { Meteor } from 'meteor/meteor'; +import FireAlerts from '../FireAlerts'; + +Meteor.publish('fireAlerts', function fireAlerts() { + return FireAlerts.find(); +}); diff --git a/imports/api/Subscriptions/Subscriptions.js b/imports/api/Subscriptions/Subscriptions.js new file mode 100644 index 0000000..ec6b5cf --- /dev/null +++ b/imports/api/Subscriptions/Subscriptions.js @@ -0,0 +1,50 @@ +/* eslint-disable consistent-return */ + +import { Mongo } from 'meteor/mongo'; +import SimpleSchema from 'simpl-schema'; + +const Subscriptions = new Mongo.Collection('subscriptions'); + +Subscriptions.allow({ + insert: () => false, + update: () => false, + remove: () => false, +}); + +Subscriptions.deny({ + insert: () => true, + update: () => true, + remove: () => true, +}); + + +/* Sample: + * { + * "_id" : ObjectId("5a0bfb5a79095a1adba47513"), + * "chatId" : -253600015, + * "location" : { + * "lat" : 40.234503, + * "lon" : -3.350386 + * }, + * "geo" : { + * "type" : "Point", + * "coordinates" : [ + * -3.350386, + * 40.234503 + * ] + * }, + * "distance" : 40 + * } + * */ + +Subscriptions.schema = new SimpleSchema({ + location: Object, + 'location.lat': SimpleSchema.Integer, + 'location.lon': SimpleSchema.Integer, + distance: Number, + } +); + +Subscriptions.attachSchema(Subscriptions.schema); + +export default Subscriptions; diff --git a/imports/api/Subscriptions/server/publications.js b/imports/api/Subscriptions/server/publications.js new file mode 100644 index 0000000..00ea7c1 --- /dev/null +++ b/imports/api/Subscriptions/server/publications.js @@ -0,0 +1,21 @@ +import { Meteor } from 'meteor/meteor'; +import Subscriptions from '../Subscriptions'; + +Meteor.publishTransformed('userSubsToFires', function() { + + // https://en.wikipedia.org/wiki/Location_obfuscation + // https://en.wikipedia.org/wiki/Decimal_degrees#Precision + return Subscriptions.find().serverTransform(function(doc) { + var location = doc.location; + /* doc.lat = location.lat; + * doc.lon = location.lon;*/ + if (location) { + doc.lat = Math.round(location.lat * 10) / 10; + doc.lon = Math.round(location.lon * 10) / 10; + } + delete doc.chatId; + delete doc.geo; + delete doc.location; + return doc; + }); +});