Many improvements in SelectionMap
This commit is contained in:
parent
7a672bca87
commit
e3eddd6b85
13 changed files with 173 additions and 132 deletions
|
|
@ -3,6 +3,13 @@ import { check, Match } from 'meteor/check';
|
|||
import Subscriptions from './Subscriptions';
|
||||
import rateLimit from '../../modules/rate-limit';
|
||||
|
||||
function geo(doc) {
|
||||
return {
|
||||
type: 'Point',
|
||||
coordinates: [doc.location.lon, doc.location.lat]
|
||||
};
|
||||
}
|
||||
|
||||
Meteor.methods({
|
||||
'subscriptions.insert': function subscriptionsInsert(doc) {
|
||||
check(doc, {
|
||||
|
|
@ -10,10 +17,17 @@ Meteor.methods({
|
|||
distance: Number
|
||||
});
|
||||
const type = 'web';
|
||||
|
||||
try {
|
||||
return Subscriptions.insert({ owner: this.userId, type, ...doc });
|
||||
const newDoc = {
|
||||
owner: this.userId,
|
||||
type,
|
||||
geo: geo(doc),
|
||||
...doc
|
||||
};
|
||||
// console.log(newDoc);
|
||||
return Subscriptions.insert(newDoc);
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
},
|
||||
|
|
@ -25,8 +39,10 @@ Meteor.methods({
|
|||
});
|
||||
|
||||
try {
|
||||
const dup = doc;
|
||||
const subscriptionId = doc._id;
|
||||
Subscriptions.update(subscriptionId, { $set: doc });
|
||||
dup.geo = geo(doc);
|
||||
Subscriptions.update(subscriptionId, { $set: dup });
|
||||
return subscriptionId; // Return _id so we can redirect to subscription after update.
|
||||
} catch (exception) {
|
||||
throw new Meteor.Error('500', exception);
|
||||
|
|
@ -38,6 +54,7 @@ Meteor.methods({
|
|||
try {
|
||||
return Subscriptions.remove(subscriptionId);
|
||||
} catch (exception) {
|
||||
console.error(exception);
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue