Improved rest api calls

This commit is contained in:
vjrj 2018-06-19 00:18:18 +02:00
parent 5b3d86e6a5
commit 5642b106d4
4 changed files with 45 additions and 8 deletions

View file

@ -15,6 +15,7 @@ import Subscriptions from '/imports/api/Subscriptions/Subscriptions';
import jsend from 'jsend';
import { Random } from 'meteor/random';
import { subscriptionsInsert } from '/imports/api/Subscriptions/methods.js';
import { Mongo } from 'meteor/mongo';
const debug = false;
@ -275,18 +276,24 @@ if (!Meteor.settings.private.internalApiToken) {
const {
token,
mobileToken,
id,
lat,
lon,
distance
} = this.bodyParams;
let oid;
try {
check(token, String);
check(mobileToken, String);
check(id, String);
oid = new Mongo.ObjectID(id);
check(oid, Meteor.Collection.ObjectID);
check(lat, Number);
check(lon, Number);
check(distance, Number);
checkLatLonDist(distance, lat, lon);
} catch (e) {
if (debug) console.log(e);
return defaultFailParams(e);
}
@ -297,6 +304,7 @@ if (!Meteor.settings.private.internalApiToken) {
if (!user) return failMsg('User not found');
const newSubs = {};
newSubs._id = new Meteor.Collection.ObjectID(id);
newSubs.location = {};
newSubs.location.lat = lat;
newSubs.location.lon = lon;

View file

@ -1,6 +1,7 @@
/* eslint-disable consistent-return */
/* eslint-disable import/no-absolute-path */
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js';
@ -42,6 +43,7 @@ Subscriptions.deny({
Subscriptions.schema = new SimpleSchema({
_id: { type: Meteor.Collection.ObjectID, optional: true, blackbox: true },
location: Object,
'location.lat': Number,
'location.lon': Number,

View file

@ -12,6 +12,7 @@ function geo(doc) {
export function subscriptionsInsert(doc, userId, type) {
check(doc, {
_id: Match.Maybe(Meteor.Collection.ObjectID),
location: Match.ObjectIncluding({ lat: Number, lon: Number }),
distance: Number
});