Added web and email notifications. Tests. Fire page
This commit is contained in:
parent
df05b33e82
commit
3bf21c8caf
32 changed files with 696 additions and 88 deletions
25
imports/api/Fires/Fires.js
Normal file
25
imports/api/Fires/Fires.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* eslint-disable consistent-return */
|
||||
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import firesCommonSchema from '../Common/FiresSchema';
|
||||
|
||||
const Fires = new Mongo.Collection('fires', { idGeneration: 'MONGO' });
|
||||
|
||||
Fires.allow({
|
||||
insert: () => false,
|
||||
update: () => false,
|
||||
remove: () => false
|
||||
});
|
||||
|
||||
Fires.deny({
|
||||
insert: () => true,
|
||||
update: () => true,
|
||||
remove: () => true
|
||||
});
|
||||
|
||||
Fires.schema = new SimpleSchema(firesCommonSchema);
|
||||
|
||||
Fires.attachSchema(Fires.schema);
|
||||
|
||||
export default Fires;
|
||||
22
imports/api/Fires/methods.js
Normal file
22
imports/api/Fires/methods.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* eslint-disable import/no-absolute-path */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import rateLimit from '/imports/modules/rate-limit';
|
||||
import urlEnc from '/imports/modules/url-encode';
|
||||
|
||||
Meteor.methods({
|
||||
'fire.decrypt': async function fireDecode(fireEnc) {
|
||||
check(fireEnc, String);
|
||||
const unsealed = await urlEnc.decrypt(fireEnc);
|
||||
return unsealed;
|
||||
}
|
||||
});
|
||||
|
||||
rateLimit({
|
||||
methods: [
|
||||
'fire.decode'
|
||||
],
|
||||
limit: 5,
|
||||
timeRange: 1000
|
||||
});
|
||||
37
imports/api/Fires/server/publications.js
Normal file
37
imports/api/Fires/server/publications.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* eslint-disable import/no-absolute-path */
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import urlEnc from '/imports/modules/url-encode';
|
||||
import { Promise } from 'meteor/promise';
|
||||
import FiresCollection from '../Fires';
|
||||
|
||||
function findFire(unsealed) {
|
||||
const fire = FiresCollection.find({ ourid: { type: 'Point', coordinates: [unsealed.lon, unsealed.lat] } });
|
||||
return fire;
|
||||
}
|
||||
|
||||
Meteor.publish('fireFromHash', function fireFromHash(fireEnc) {
|
||||
check(fireEnc, String);
|
||||
try {
|
||||
// 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);
|
||||
FiresCollection.schema.validate(unsealed);
|
||||
const fire = findFire(unsealed);
|
||||
if (fire.count() === 0) {
|
||||
const result = FiresCollection.upsert({ ourid: unsealed.ourid }, { $set: unsealed }, { multi: false, upsert: true });
|
||||
console.log(JSON.stringify(result));
|
||||
}
|
||||
return findFire(unsealed);
|
||||
/* console.log(`fires: ${fire.count()}`);
|
||||
* return fire; */
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw new Meteor.Error('500', e);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue