Sfoglia il codice sorgente

Populate bookmarked page from bookmark folder

https://youtrack.weseek.co.jp/issue/GW-7861
- Add folder to Bookmark schema reference to BookmarkFolder
- Add virtual bookmarks to bookmarkFolderSchema
- Populate bookmarks in findFolderAndChildren method
- Add bookmarks to BookmarkFolderItems interface
- Update return value of bookmark folder list route
Mudana-Grune 3 anni fa
parent
commit
9d678ac1cd

+ 1 - 0
packages/app/src/interfaces/bookmark-info.ts

@@ -29,4 +29,5 @@ export interface BookmarkFolderItems {
   name: string
   parent: string
   children: this[]
+  bookmarks: BookmarkedPage[]
 }

+ 11 - 3
packages/app/src/server/models/bookmark-folder.ts

@@ -40,6 +40,11 @@ bookmarkFolderSchema.virtual('children', {
   foreignField: 'parent',
 });
 
+bookmarkFolderSchema.virtual('bookmarks', {
+  ref: 'Bookmark',
+  localField: '_id',
+  foreignField: 'folder',
+});
 
 bookmarkFolderSchema.statics.createByParameters = async function(params: IBookmarkFolder): Promise<BookmarkFolderDocument> {
   const { name, owner, parent } = params;
@@ -69,10 +74,13 @@ bookmarkFolderSchema.statics.findFolderAndChildren = async function(
     userId: Types.ObjectId | string,
     parentId?: Types.ObjectId | string,
 ): Promise<BookmarkFolderItems[]> {
-  const parentFolder = await this.findById(parentId) as unknown as BookmarkFolderDocument;
-  const bookmarks = await this.find({ owner: userId, parent: parentFolder })
+
+  const parentFolder = await this.findById(parentId).populate({ path: 'bookmarks' }).exec() as unknown as BookmarkFolderDocument;
+
+  // TODO : forms the return value for the bookmark
+  const bookmarkFolders = await this.find({ owner: userId, parent: parentFolder })
     .populate({ path: 'children' }).exec() as unknown as BookmarkFolderItems[];
-  return bookmarks;
+  return bookmarkFolders;
 };
 
 bookmarkFolderSchema.statics.findChildFolderById = async function(parentFolderId: Types.ObjectId | string): Promise<BookmarkFolderDocument[]> {

+ 1 - 0
packages/app/src/server/models/bookmark.js

@@ -16,6 +16,7 @@ module.exports = function(crowi) {
   bookmarkSchema = new mongoose.Schema({
     page: { type: ObjectId, ref: 'Page', index: true },
     user: { type: ObjectId, ref: 'User', index: true },
+    folder: { type: ObjectId, ref: 'BookmarkFolder', required: false },
   }, {
     timestamps: { createdAt: true, updatedAt: false },
   });

+ 1 - 0
packages/app/src/server/routes/apiv3/bookmark-folder.ts

@@ -56,6 +56,7 @@ module.exports = (crowi) => {
         name: bookmarkFolder.name,
         parent: bookmarkFolder.parent,
         children: bookmarkFolder.children,
+        bookmarks: bookmarkFolder.bookmarks,
       }));
       return res.apiv3({ bookmarkFolderItems });
     }