Shun Miyazawa 2 лет назад
Родитель
Сommit
6f6ee77008
1 измененных файлов с 6 добавлено и 13 удалено
  1. 6 13
      apps/app/src/server/models/bookmark-folder.ts

+ 6 - 13
apps/app/src/server/models/bookmark-folder.ts

@@ -147,20 +147,13 @@ Promise<BookmarkFolderDocument | null> {
     return null;
   }
 
-  // Verify if the operator and the owner of the bookmark folder match
-  const bookmarkFolder = await this.findOne({ _id: folderId, owner: userId });
-  const isOwner = bookmarkFolder?.owner.toString() === userId.toString();
-  if (!isOwner) {
-    throw new Error('You are not the owner of the BookmarkFolder');
-  }
-
-  // Insert bookmark into bookmark folder
-  if (bookmarkFolder != null) {
-    const updatedBookmarkFolder = await bookmarkFolder.update({ $addToSet: { bookmarks: bookmarkedPage } }, { new: true, upsert: true });
-    return updatedBookmarkFolder;
-  }
+  const bookmarkFolder = await this.findByIdAndUpdate(
+    { _id: folderId, owner: userId },
+    { $addToSet: { bookmarks: bookmarkedPage } },
+    { new: true, upsert: true },
+  );
 
-  return null;
+  return bookmarkFolder;
 };
 
 bookmarkFolderSchema.statics.updateBookmark = async function(pageId: Types.ObjectId | string, status: boolean, userId: Types.ObjectId | string):