Просмотр исходного кода

global-notification-model frame

sou 7 лет назад
Родитель
Сommit
ece4962d0e
1 измененных файлов с 31 добавлено и 0 удалено
  1. 31 0
      lib/models/global-notification-setting.js

+ 31 - 0
lib/models/global-notification-setting.js

@@ -0,0 +1,31 @@
+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() }
+  });
+  bookmarkSchema.index({page: 1, user: 1}, {unique: true});
+
+
+  // bookmark チェック用
+  bookmarkSchema.statics.findByPageIdAndUserId = function(pageId, userId) {
+    const Bookmark = this;
+
+    return new Promise(function(resolve, reject) {
+      return Bookmark.findOne({ page: pageId, user: userId }, function(err, doc) {
+        if (err) {
+          return reject(err);
+        }
+
+        return resolve(doc);
+      });
+    });
+  };
+
+  return mongoose.model('Bookmark', bookmarkSchema);
+};