summaryrefslogtreecommitdiffstats
path: root/models/notices.js
blob: d62f6797e42daccb18e1cc717cc3af10d23c84c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Notices = new Mongo.Collection('notices');

Notices.attachSchema(new SimpleSchema({
  enabled: {
    type: Boolean,
    defaultValue: false,
  },
  title: {
    type: String,
    optional: true,
  },
  body: {
    type: String,
    optional: true,
  },
  sort: {
    type: Number,
    decimal: true,
  },
}));

Notices.allow({
  update(userId) {
    const user = Users.findOne(userId);
    return user && user.isAdmin;
  },
});

if (Meteor.isServer) {
  Meteor.startup(() => {
    const notices = Notices.findOne({});
    if(!notices){
      Notices.insert({enabled: false, sort: 0});
    }
  });
}