All 12 Flutter REST endpoints byte-identical to the 1.6.1.1 baseline, running on Meteor 3.1 against dockerized MongoDB 7. The 3.x jump works end-to-end. - Rest.js: every endpoint action -> async; all Mongo calls -> *Async (findOneAsync/countAsync/fetchAsync/upsertAsync/removeAsync). - Helpers to async: countRealFires (accepts array|cursor, forEachAsync->for-of), firesUnion (fetchAsync), fireFromHash/findOrCreateFire (await, dropped Fibers Promise.await), subscriptionsInsert/subscriptionsRemove, upsertFalsePositive, falsePositives.insert, subscriptions.update method, countFiresInRegions. - getFires: countAsync() on a $near cursor throws on the mongodb 6 driver ($near not allowed in the aggregation countDocuments uses) -> fetch once and use array length for total. - Route order: json-routes 3.0 matches in registration order, so mobile/subscriptions/all/:token/:mobileToken is now registered BEFORE :token/:mobileToken/:subsId (else GET .../all/x/y hit the delete-only route).
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
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';
|
|
|
|
export async 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 await FalsePositives.upsertAsync({ 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': async 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 = await Fires.findOneAsync(fireId);
|
|
const owner = this.userId;
|
|
if (fire) {
|
|
await upsertFalsePositive(keyType, owner, fire);
|
|
} else {
|
|
throw new Meteor.Error('500', 'Fuego no encontrado');
|
|
}
|
|
}
|
|
});
|
|
|
|
rateLimit({
|
|
methods: [
|
|
'falsePositives.insert'
|
|
],
|
|
limit: 5,
|
|
timeRange: 1000
|
|
});
|