global-notification-setting.js 908 B

12345678910111213141516171819202122232425262728293031
  1. module.exports = function(crowi) {
  2. var debug = require('debug')('growi:models:bookmark')
  3. , mongoose = require('mongoose')
  4. , ObjectId = mongoose.Schema.Types.ObjectId
  5. , bookmarkSchema;
  6. bookmarkSchema = new mongoose.Schema({
  7. page: { type: ObjectId, ref: 'Page', index: true },
  8. user: { type: ObjectId, ref: 'User', index: true },
  9. createdAt: { type: Date, default: Date.now() }
  10. });
  11. bookmarkSchema.index({page: 1, user: 1}, {unique: true});
  12. // bookmark チェック用
  13. bookmarkSchema.statics.findByPageIdAndUserId = function(pageId, userId) {
  14. const Bookmark = this;
  15. return new Promise(function(resolve, reject) {
  16. return Bookmark.findOne({ page: pageId, user: userId }, function(err, doc) {
  17. if (err) {
  18. return reject(err);
  19. }
  20. return resolve(doc);
  21. });
  22. });
  23. };
  24. return mongoose.model('Bookmark', bookmarkSchema);
  25. };