Added false positives management to website

This commit is contained in:
vjrj 2018-01-29 19:23:05 +01:00
parent 379e72a9e7
commit 674c07460b
10 changed files with 192 additions and 29 deletions

View file

@ -0,0 +1,7 @@
const types = {
industry: 'Es una industria (altos hornos, incineradora, etc)',
controled: 'Es una quema controlada',
falsealarm: 'Parece una falsa alarma'
};
export default types;

View file

@ -0,0 +1,37 @@
/* eslint-disable consistent-return */
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js';
import LocationSchema from '/imports/api/Utility/LocationSchema.js';
const FalsePositives = new Mongo.Collection('falsePositives', { idGeneration: 'MONGO' });
FalsePositives.allow({
insert: () => false,
update: () => false,
remove: () => false
});
FalsePositives.deny({
insert: () => true,
update: () => true,
remove: () => true
});
FalsePositives.schema = new SimpleSchema({
geo: LocationSchema,
fireId: { type: Meteor.Collection.ObjectID, optional: true, blackbox: true },
chatId: { type: Number, optional: true }, // only in 'telegram' type
owner: String,
type: String,
when: Date,
whendateformat: String,
createdAt: defaultCreatedAt,
updatedAt: defaultUpdateAt
});
FalsePositives.attachSchema(FalsePositives.schema);
export default FalsePositives;

View file

@ -0,0 +1,53 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import moment from 'moment';
import FalsePositives from './FalsePositives';
import FalsePositiveTypes from './FalsePositiveTypes';
import Fires from '../Fires/Fires';
import rateLimit from '../../modules/rate-limit';
Meteor.methods({
'falsePositives.insert': function falsePositivesInsert(fireId, keyType) {
check(fireId, Meteor.Collection.ObjectID);
check(keyType, String);
const type = FalsePositiveTypes[keyType];
check(type, String);
if (!this.userId) {
throw new Meteor.Error('500', 'Regístrate o inicia sesión para aportar información sobre este fuego');
}
check(this.userId, String);
const fire = Fires.findOne(fireId);
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);
}
} else {
throw new Meteor.Error('500', 'Fuego no encontrado');
}
}
});
rateLimit({
methods: [
'falsePositives.insert'
],
limit: 5,
timeRange: 1000
});

View file

@ -30,13 +30,11 @@ Meteor.publish('fireFromHash', function fireFromHash(fireEnc) {
// console.log(fireEnc);
const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
const w = unsealed.when;
// console.log(w);
unsealed.when = new Date(w);
// console.log(unsealed.when);
const c = unsealed.createdAt;
unsealed.createdAt = new Date(c);
unsealed.createdAt = !c ? new Date() : new Date(c);
const u = unsealed.updatedAt;
unsealed.updatedAt = new Date(u);
unsealed.updatedAt = !u ? new Date() : new Date(u);
// console.log(unsealed);
FiresCollection.schema.validate(unsealed);
const fire = findFire(unsealed);