|
|
@@ -10,6 +10,7 @@ import { IPageHasId } from '~/interfaces/page';
|
|
|
import loggerFactory from '../../utils/logger';
|
|
|
import { getOrCreateModel } from '../util/mongoose-utils';
|
|
|
|
|
|
+import bookmark from './bookmark';
|
|
|
import { InvalidParentBookmarkFolderError } from './errors';
|
|
|
|
|
|
|
|
|
@@ -32,6 +33,7 @@ export interface BookmarkFolderModel extends Model<BookmarkFolderDocument>{
|
|
|
deleteFolderAndChildren(bookmarkFolderId: Types.ObjectId | string): Promise<{deletedCount: number}>
|
|
|
updateBookmarkFolder(bookmarkFolderId: string, name: string, parent: string): Promise<BookmarkFolderDocument>
|
|
|
insertOrUpdateBookmarkedPage(pageId: IPageHasId, userId: Types.ObjectId | string, folderId: string): Promise<BookmarkFolderDocument>
|
|
|
+ getAllAncestors(folderId: string): Promise<BookmarkFolderItems[]>
|
|
|
}
|
|
|
|
|
|
const bookmarkFolderSchema = new Schema<BookmarkFolderDocument, BookmarkFolderModel>({
|
|
|
@@ -170,5 +172,17 @@ Promise<BookmarkFolderDocument> {
|
|
|
return bookmarkFolder;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
+bookmarkFolderSchema.statics.getAllAncestors = async function(folderId: string): Promise<string[]> {
|
|
|
+ const getParent = async(folderId) => {
|
|
|
+ let currentParent : string[] = [];
|
|
|
+ const parentFolder = await this.findById(folderId);
|
|
|
+ if (parentFolder && parentFolder.parent != null) {
|
|
|
+ currentParent.push(parentFolder.id);
|
|
|
+ currentParent = currentParent.concat(await getParent(parentFolder.parent));
|
|
|
+ }
|
|
|
+ return currentParent;
|
|
|
+ };
|
|
|
+ const parents = await getParent(folderId);
|
|
|
+ return parents;
|
|
|
+};
|
|
|
export default getOrCreateModel<BookmarkFolderDocument, BookmarkFolderModel>('BookmarkFolder', bookmarkFolderSchema);
|