| 12345678910111213141516171819202122232425262728293031 |
- 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);
- };
|