New rest methods (subs-union, falsePositive) for mobile
This commit is contained in:
parent
d4be8c7c46
commit
9556bf4e60
3 changed files with 85 additions and 23 deletions
|
|
@ -6,6 +6,29 @@ import FalsePositiveTypes from './FalsePositiveTypes';
|
||||||
import Fires from '../Fires/Fires';
|
import Fires from '../Fires/Fires';
|
||||||
import rateLimit from '../../modules/rate-limit';
|
import rateLimit from '../../modules/rate-limit';
|
||||||
|
|
||||||
|
export function upsertFalsePositive(keyType, owner, fire) {
|
||||||
|
const fireType = fire.type;
|
||||||
|
if (fireType === 'vecinal') {
|
||||||
|
throw new Meteor.Error('500', 'No se puede marcar este tipo de fuego');
|
||||||
|
}
|
||||||
|
const date = new Date();
|
||||||
|
const formated = moment(date).format('YYYYMMDD');
|
||||||
|
try {
|
||||||
|
const set = {
|
||||||
|
owner,
|
||||||
|
type: keyType,
|
||||||
|
when: date,
|
||||||
|
whendateformat: formated,
|
||||||
|
fireId: fire._id,
|
||||||
|
geo: fire.ourid
|
||||||
|
};
|
||||||
|
return FalsePositives.upsert({ geo: fire.ourid, owner }, { $set: set }, { multi: false, upsert: true });
|
||||||
|
} catch (exception) {
|
||||||
|
console.log(exception);
|
||||||
|
throw new Meteor.Error('500', exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
'falsePositives.insert': function falsePositivesInsert(fireId, keyType) {
|
'falsePositives.insert': function falsePositivesInsert(fireId, keyType) {
|
||||||
check(fireId, Meteor.Collection.ObjectID);
|
check(fireId, Meteor.Collection.ObjectID);
|
||||||
|
|
@ -17,27 +40,9 @@ Meteor.methods({
|
||||||
}
|
}
|
||||||
check(this.userId, String);
|
check(this.userId, String);
|
||||||
const fire = Fires.findOne(fireId);
|
const fire = Fires.findOne(fireId);
|
||||||
|
const owner = this.userId;
|
||||||
if (fire) {
|
if (fire) {
|
||||||
const fireType = fire.type;
|
upsertFalsePositive(keyType, owner, fire);
|
||||||
if (fireType === 'vecinal') {
|
|
||||||
throw new Meteor.Error('500', 'No se puede marcar este tipo de fuego');
|
|
||||||
}
|
|
||||||
const date = new Date();
|
|
||||||
const formated = moment(date).format('YYYYMMDD');
|
|
||||||
try {
|
|
||||||
const set = {
|
|
||||||
owner: this.userId,
|
|
||||||
type: keyType,
|
|
||||||
when: date,
|
|
||||||
whendateformat: formated,
|
|
||||||
fireId,
|
|
||||||
geo: fire.ourid
|
|
||||||
};
|
|
||||||
return FalsePositives.upsert({ geo: fire.ourid, owner: this.userId }, { $set: set }, { multi: false, upsert: true });
|
|
||||||
} catch (exception) {
|
|
||||||
console.log(exception);
|
|
||||||
throw new Meteor.Error('500', exception);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new Meteor.Error('500', 'Fuego no encontrado');
|
throw new Meteor.Error('500', 'Fuego no encontrado');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ function logUrl(fireEnc, params) {
|
||||||
ravenLogger.log(message);
|
ravenLogger.log(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Meteor.publish('fireFromHash', function fireFromHash(fireEnc, params) {
|
export function fireFromHash(fireEnc, params) {
|
||||||
check(fireEnc, String);
|
check(fireEnc, String);
|
||||||
check(params, Object);
|
check(params, Object);
|
||||||
try {
|
try {
|
||||||
|
|
@ -163,11 +163,17 @@ Meteor.publish('fireFromHash', function fireFromHash(fireEnc, params) {
|
||||||
FiresCollection.schema.validate(unsealedFix);
|
FiresCollection.schema.validate(unsealedFix);
|
||||||
return findOrCreateFire(unsealedFix);
|
return findOrCreateFire(unsealedFix);
|
||||||
/* console.log(`fires: ${fire.count()}`);
|
/* console.log(`fires: ${fire.count()}`);
|
||||||
* return fire; */
|
* return fire; */
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
logUrl(fireEnc, params);
|
logUrl(fireEnc, params);
|
||||||
|
|
||||||
return this.ready();
|
return this.ready();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Meteor.publish('fireFromHash', function fireFromHashFunc(fireEnc, params) {
|
||||||
|
check(fireEnc, String);
|
||||||
|
check(params, Object);
|
||||||
|
return fireFromHash(fireEnc, params);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
|
||||||
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
||||||
import { countRealFires } from '/imports/api/ActiveFires/server/countFires';
|
import { countRealFires } from '/imports/api/ActiveFires/server/countFires';
|
||||||
import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
||||||
|
import { fireFromHash } from '/imports/api/Fires/server/publications.js';
|
||||||
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||||
import Industries from '/imports/api/Industries/Industries';
|
import Industries from '/imports/api/Industries/Industries';
|
||||||
import Subscriptions from '/imports/api/Subscriptions/Subscriptions';
|
import Subscriptions from '/imports/api/Subscriptions/Subscriptions';
|
||||||
|
|
@ -16,7 +17,7 @@ import jsend from 'jsend';
|
||||||
import { Random } from 'meteor/random';
|
import { Random } from 'meteor/random';
|
||||||
import { subscriptionsInsert } from '/imports/api/Subscriptions/methods.js';
|
import { subscriptionsInsert } from '/imports/api/Subscriptions/methods.js';
|
||||||
import { Mongo } from 'meteor/mongo';
|
import { Mongo } from 'meteor/mongo';
|
||||||
|
import { upsertFalsePositive } from '/imports/api/FalsePositives/methods.js';
|
||||||
const debug = false;
|
const debug = false;
|
||||||
|
|
||||||
const uptime = new Date();
|
const uptime = new Date();
|
||||||
|
|
@ -394,4 +395,54 @@ if (!Meteor.settings.private.internalApiToken) {
|
||||||
return jsend.success({ count: toRemove });
|
return jsend.success({ count: toRemove });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apiV1.addRoute('status/subs-public-union/:token', { authRequired: false }, {
|
||||||
|
get: function get() {
|
||||||
|
const { token } = this.urlParams;
|
||||||
|
try {
|
||||||
|
check(token, String);
|
||||||
|
} catch (e) {
|
||||||
|
return defaultFailParams(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const failed = checkAuthToken(token);
|
||||||
|
if (failed) return failed;
|
||||||
|
|
||||||
|
const currentUnion = SiteSettings.findOne({ name: 'subs-public-union' });
|
||||||
|
const userSubsBounds = SiteSettings.findOne({ name: 'subs-public-union-bounds' });
|
||||||
|
|
||||||
|
return jsend.success({ union: currentUnion, bounds: userSubsBounds });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
apiV1.addRoute('mobile/falsepositive', { authRequired: false }, {
|
||||||
|
post: function post() {
|
||||||
|
const {
|
||||||
|
token,
|
||||||
|
mobileToken,
|
||||||
|
sealed,
|
||||||
|
type
|
||||||
|
} = this.bodyParams;
|
||||||
|
try {
|
||||||
|
check(token, String);
|
||||||
|
check(mobileToken, String);
|
||||||
|
check(sealed, String);
|
||||||
|
check(type, String);
|
||||||
|
} catch (e) {
|
||||||
|
if (debug) console.log(e);
|
||||||
|
return defaultFailParams(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const failed = checkAuthToken(token);
|
||||||
|
if (failed) return failed;
|
||||||
|
|
||||||
|
const user = Meteor.users.findOne({ fireBaseToken: mobileToken });
|
||||||
|
if (!user) return failMsg('User not found');
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
const fire = fireFromHash(sealed, {});
|
||||||
|
const result = upsertFalsePositive(type, user._id, fire);
|
||||||
|
return jsend.success({ upsert: result });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue