|
@@ -147,20 +147,13 @@ Promise<BookmarkFolderDocument | null> {
|
|
|
return 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):
|
|
bookmarkFolderSchema.statics.updateBookmark = async function(pageId: Types.ObjectId | string, status: boolean, userId: Types.ObjectId | string):
|