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
39
imports/api/Notifications/Notifications.js
Normal file
39
imports/api/Notifications/Notifications.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* eslint-disable consistent-return */
|
||||
/* eslint-disable import/no-absolute-path */
|
||||
|
||||
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 Notifications = new Mongo.Collection('notifications', { idGeneration: 'MONGO' });
|
||||
|
||||
Notifications.allow({
|
||||
insert: () => false,
|
||||
update: () => false,
|
||||
remove: () => false
|
||||
});
|
||||
|
||||
Notifications.deny({
|
||||
insert: () => true,
|
||||
update: () => true,
|
||||
remove: () => true
|
||||
});
|
||||
|
||||
Notifications.schema = new SimpleSchema({
|
||||
userId: String,
|
||||
content: String,
|
||||
geo: LocationSchema,
|
||||
type: String,
|
||||
webNotified: { type: Boolean, optional: true },
|
||||
webNotifiedAt: { type: Date, optional: true },
|
||||
emailNotified: { type: Boolean, optional: true },
|
||||
emailNotifiedAt: { type: Date, optional: true },
|
||||
when: Date,
|
||||
createdAt: defaultCreatedAt,
|
||||
updatedAt: defaultUpdateAt
|
||||
});
|
||||
|
||||
Notifications.attachSchema(Notifications.schema);
|
||||
|
||||
export default Notifications;
|
||||
25
imports/api/Notifications/methods.js
Normal file
25
imports/api/Notifications/methods.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import Notifications from './Notifications';
|
||||
import rateLimit from '../../modules/rate-limit';
|
||||
|
||||
Meteor.methods({
|
||||
'notifications.sent': function notificationsUpdate(notifId) {
|
||||
check(notifId, Meteor.Collection.ObjectID);
|
||||
|
||||
try {
|
||||
Notifications.update(notifId, { $set: { webNotified: true, webNotifiedAt: new Date() } });
|
||||
return notifId;
|
||||
} catch (exception) {
|
||||
throw new Meteor.Error('500', exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rateLimit({
|
||||
methods: [
|
||||
'notifications.sent'
|
||||
],
|
||||
limit: 5,
|
||||
timeRange: 1000
|
||||
});
|
||||
10
imports/api/Notifications/server/publications.js
Normal file
10
imports/api/Notifications/server/publications.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* eslint-disable prefer-arrow-callback */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import Notifications from '../Notifications';
|
||||
|
||||
Meteor.publish('mynotifications', function notifications() {
|
||||
const notif = Notifications.find({ userId: this.userId, type: 'web', webNotified: null });
|
||||
console.log(`Notifications for user ${this.userId}: ${notif.count()}`);
|
||||
return notif;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue