summaryrefslogtreecommitdiffstats
path: root/models/announcements.js
blob: 2cb1e1b750a6a7228455c47b0918bd6bd7bb4191 (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
Announcements = new Mongo.Collection('announcements');

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

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

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