|
|
@@ -4,14 +4,17 @@ import {
|
|
|
} from 'mongoose';
|
|
|
|
|
|
import { IBookmarkFolder, BookmarkFolderItems } from '~/interfaces/bookmark-info';
|
|
|
-
|
|
|
+import { IPageHasId } from '~/interfaces/page';
|
|
|
+import { IUserHasId } from '~/interfaces/user';
|
|
|
|
|
|
import loggerFactory from '../../utils/logger';
|
|
|
import { getOrCreateModel } from '../util/mongoose-utils';
|
|
|
|
|
|
import { InvalidParentBookmarkFolderError } from './errors';
|
|
|
|
|
|
+
|
|
|
const logger = loggerFactory('growi:models:bookmark-folder');
|
|
|
+const Bookmark = require('./bookmark');
|
|
|
|
|
|
export interface BookmarkFolderDocument extends Document {
|
|
|
_id: Types.ObjectId
|
|
|
@@ -112,5 +115,12 @@ bookmarkFolderSchema.statics.updateBookmarkFolder = async function(bookmarkFolde
|
|
|
|
|
|
};
|
|
|
|
|
|
+bookmarkFolderSchema.statics.insertOrUpdateBookmarkedPage = async function(page: IPageHasId, user: IUserHasId, bookmarkFolderId: string):
|
|
|
+Promise<BookmarkFolderDocument> {
|
|
|
+ const bookmarkedPage = await Bookmark.findOneAndUpdate({ page, user }, { new: true, upsert: true });
|
|
|
+ const bookmarkFolder = await this.findByIdAndUpdate(bookmarkFolderId, { $set: { bookmarks: bookmarkedPage } }, { new: true, upsert: true });
|
|
|
+ return bookmarkFolder;
|
|
|
+};
|
|
|
+
|
|
|
|
|
|
export default getOrCreateModel<BookmarkFolderDocument, BookmarkFolderModel>('BookmarkFolder', bookmarkFolderSchema);
|