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 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({
|
||||
'falsePositives.insert': function falsePositivesInsert(fireId, keyType) {
|
||||
check(fireId, Meteor.Collection.ObjectID);
|
||||
|
|
@ -17,27 +40,9 @@ Meteor.methods({
|
|||
}
|
||||
check(this.userId, String);
|
||||
const fire = Fires.findOne(fireId);
|
||||
const owner = this.userId;
|
||||
if (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: 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);
|
||||
}
|
||||
upsertFalsePositive(keyType, owner, fire);
|
||||
} else {
|
||||
throw new Meteor.Error('500', 'Fuego no encontrado');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ function logUrl(fireEnc, params) {
|
|||
ravenLogger.log(message);
|
||||
}
|
||||
|
||||
Meteor.publish('fireFromHash', function fireFromHash(fireEnc, params) {
|
||||
export function fireFromHash(fireEnc, params) {
|
||||
check(fireEnc, String);
|
||||
check(params, Object);
|
||||
try {
|
||||
|
|
@ -163,11 +163,17 @@ Meteor.publish('fireFromHash', function fireFromHash(fireEnc, params) {
|
|||
FiresCollection.schema.validate(unsealedFix);
|
||||
return findOrCreateFire(unsealedFix);
|
||||
/* console.log(`fires: ${fire.count()}`);
|
||||
* return fire; */
|
||||
* return fire; */
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
logUrl(fireEnc, params);
|
||||
|
||||
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 { countRealFires } from '/imports/api/ActiveFires/server/countFires';
|
||||
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 Industries from '/imports/api/Industries/Industries';
|
||||
import Subscriptions from '/imports/api/Subscriptions/Subscriptions';
|
||||
|
|
@ -16,7 +17,7 @@ import jsend from 'jsend';
|
|||
import { Random } from 'meteor/random';
|
||||
import { subscriptionsInsert } from '/imports/api/Subscriptions/methods.js';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
|
||||
import { upsertFalsePositive } from '/imports/api/FalsePositives/methods.js';
|
||||
const debug = false;
|
||||
|
||||
const uptime = new Date();
|
||||
|
|
@ -394,4 +395,54 @@ if (!Meteor.settings.private.internalApiToken) {
|
|||
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