|
@@ -1,31 +1,101 @@
|
|
|
module.exports = function(crowi) {
|
|
module.exports = function(crowi) {
|
|
|
- var debug = require('debug')('growi:models:bookmark')
|
|
|
|
|
- , mongoose = require('mongoose')
|
|
|
|
|
- , ObjectId = mongoose.Schema.Types.ObjectId
|
|
|
|
|
- , bookmarkSchema;
|
|
|
|
|
-
|
|
|
|
|
- bookmarkSchema = new mongoose.Schema({
|
|
|
|
|
- page: { type: ObjectId, ref: 'Page', index: true },
|
|
|
|
|
- user: { type: ObjectId, ref: 'User', index: true },
|
|
|
|
|
- createdAt: { type: Date, default: Date.now() }
|
|
|
|
|
|
|
+ const debug = require('debug')('growi:models:global-notification-setting');
|
|
|
|
|
+ const mongoose = require('mongoose');
|
|
|
|
|
+ const Notification = this;
|
|
|
|
|
+
|
|
|
|
|
+ let notificationSchema;
|
|
|
|
|
+
|
|
|
|
|
+ notificationSchema = new mongoose.Schema({
|
|
|
|
|
+ isEnabled: { type: Boolean, required: true, default: false },
|
|
|
|
|
+ triggerPath: { type: String, required: true },
|
|
|
|
|
+ triggerEvents: { type: [String] },
|
|
|
|
|
+ toEmail: { type: String, required: true },
|
|
|
});
|
|
});
|
|
|
- bookmarkSchema.index({page: 1, user: 1}, {unique: true});
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * create new notification setting
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.create = () => {
|
|
|
|
|
+ // save
|
|
|
|
|
+ // return Notification
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * enable notification setting
|
|
|
|
|
+ * @param {string} id
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.enable = id => {
|
|
|
|
|
+ // save
|
|
|
|
|
+ // return Notification
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * disable notification setting
|
|
|
|
|
+ * @param {string} id
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.disable = id => {
|
|
|
|
|
+ // save
|
|
|
|
|
+ // return Notification
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // bookmark チェック用
|
|
|
|
|
- bookmarkSchema.statics.findByPageIdAndUserId = function(pageId, userId) {
|
|
|
|
|
- const Bookmark = this;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * delete notification setting
|
|
|
|
|
+ * @param {string} id
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.delete = id => {
|
|
|
|
|
+ // delete notification setting
|
|
|
|
|
+ // remove
|
|
|
|
|
+ // return;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
|
|
- return Bookmark.findOne({ page: pageId, user: userId }, function(err, doc) {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- return reject(err);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * update notification setting
|
|
|
|
|
+ * @param {string} id
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.update = id => {
|
|
|
|
|
+ // save
|
|
|
|
|
+ // return Notification
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- return resolve(doc);
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * find a notification setting by id
|
|
|
|
|
+ * @param {string} id
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.findSettingById = id => {
|
|
|
|
|
+ // findOne
|
|
|
|
|
+ // return Notification
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- return mongoose.model('Bookmark', bookmarkSchema);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * find a list of notification settings by path and a list of events
|
|
|
|
|
+ * @param {string} path
|
|
|
|
|
+ * @param {string} event
|
|
|
|
|
+ */
|
|
|
|
|
+ notificationSchema.statics.findSettingByPathAndEvent = (path, event) => {
|
|
|
|
|
+ // find
|
|
|
|
|
+ // return [Notification]
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // classify a list of notification settings into enabled and disabled
|
|
|
|
|
+ notificationSchema.mothods.classify = settings => {
|
|
|
|
|
+ // return {enabled: [Notification], disabled: [Notification]}
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // returns only enabled notification settings
|
|
|
|
|
+ notificationSchema.mothods.getEnabeldSettings = settings => {
|
|
|
|
|
+ // return [Notification]
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // sort a list of notifications by path from short to long
|
|
|
|
|
+ notificationSchema.mothods.sortByPath = settings => {
|
|
|
|
|
+ // return [Notification]
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return mongoose.model('GlobalNotificationSetting', notificationSchema);
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// const notifications = await findSettingByPathAndEvent(path, event);
|
|
|
|
|
+// notifications.forEach(notification => {
|
|
|
|
|
+// notification.send(); //??????????
|
|
|
|
|
+// });
|