2023-01-15 01:11:16 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
|
2017-10-01 12:43:15 +09:00
|
|
|
Announcements = new Mongo.Collection('announcements');
|
2017-09-28 16:57:04 +09:00
|
|
|
|
2019-06-26 17:47:27 -05:00
|
|
|
Announcements.attachSchema(
|
|
|
|
new SimpleSchema({
|
|
|
|
enabled: {
|
|
|
|
type: Boolean,
|
|
|
|
defaultValue: false,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
sort: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert) {
|
|
|
|
return new Date();
|
2019-09-05 12:29:45 -05:00
|
|
|
} else if (this.isUpsert) {
|
|
|
|
return { $setOnInsert: new Date() };
|
2019-06-26 17:47:27 -05:00
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modifiedAt: {
|
|
|
|
type: Date,
|
|
|
|
denyUpdate: false,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
|
|
|
return new Date();
|
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
}),
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2017-09-28 16:57:04 +09:00
|
|
|
|
2017-10-01 12:43:15 +09:00
|
|
|
Announcements.allow({
|
2017-09-28 16:57:04 +09:00
|
|
|
update(userId) {
|
2023-01-15 01:11:16 +01:00
|
|
|
const user = ReactiveCache.getUser(userId);
|
2017-09-28 16:57:04 +09:00
|
|
|
return user && user.isAdmin;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.startup(() => {
|
2021-10-09 15:56:16 +03:00
|
|
|
Announcements._collection.createIndex({ modifiedAt: -1 });
|
2017-10-01 12:43:15 +09:00
|
|
|
const announcements = Announcements.findOne({});
|
2019-06-26 17:47:27 -05:00
|
|
|
if (!announcements) {
|
|
|
|
Announcements.insert({ enabled: false, sort: 0 });
|
2017-09-28 16:57:04 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-26 17:47:27 -05:00
|
|
|
|
|
|
|
export default Announcements;
|