|
@@ -32,6 +32,8 @@ const bookmarkFolderSchema = new Schema<BookmarkFolderDocument, BookmarkFolderMo
|
|
|
name: { type: String },
|
|
name: { type: String },
|
|
|
owner: { type: Schema.Types.ObjectId, ref: 'User', index: true },
|
|
owner: { type: Schema.Types.ObjectId, ref: 'User', index: true },
|
|
|
parent: { type: Schema.Types.ObjectId, ref: 'BookmarkFolder', required: false },
|
|
parent: { type: Schema.Types.ObjectId, ref: 'BookmarkFolder', required: false },
|
|
|
|
|
+}, {
|
|
|
|
|
+ toObject: { virtuals: true },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
bookmarkFolderSchema.virtual('children', {
|
|
bookmarkFolderSchema.virtual('children', {
|
|
@@ -40,7 +42,6 @@ bookmarkFolderSchema.virtual('children', {
|
|
|
foreignField: 'parent',
|
|
foreignField: 'parent',
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-
|
|
|
|
|
bookmarkFolderSchema.statics.createByParameters = async function(params: IBookmarkFolder): Promise<BookmarkFolderDocument> {
|
|
bookmarkFolderSchema.statics.createByParameters = async function(params: IBookmarkFolder): Promise<BookmarkFolderDocument> {
|
|
|
const { name, owner, parent } = params;
|
|
const { name, owner, parent } = params;
|
|
|
let bookmarkFolder;
|
|
let bookmarkFolder;
|
|
@@ -69,10 +70,11 @@ bookmarkFolderSchema.statics.findFolderAndChildren = async function(
|
|
|
userId: Types.ObjectId | string,
|
|
userId: Types.ObjectId | string,
|
|
|
parentId?: Types.ObjectId | string,
|
|
parentId?: Types.ObjectId | string,
|
|
|
): Promise<BookmarkFolderItems[]> {
|
|
): Promise<BookmarkFolderItems[]> {
|
|
|
|
|
+
|
|
|
const parentFolder = await this.findById(parentId) as unknown as BookmarkFolderDocument;
|
|
const parentFolder = await this.findById(parentId) as unknown as BookmarkFolderDocument;
|
|
|
- const bookmarks = await this.find({ owner: userId, parent: parentFolder })
|
|
|
|
|
|
|
+ const bookmarkFolders = await this.find({ owner: userId, parent: parentFolder })
|
|
|
.populate({ path: 'children' }).exec() as unknown as BookmarkFolderItems[];
|
|
.populate({ path: 'children' }).exec() as unknown as BookmarkFolderItems[];
|
|
|
- return bookmarks;
|
|
|
|
|
|
|
+ return bookmarkFolders;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
bookmarkFolderSchema.statics.findChildFolderById = async function(parentFolderId: Types.ObjectId | string): Promise<BookmarkFolderDocument[]> {
|
|
bookmarkFolderSchema.statics.findChildFolderById = async function(parentFolderId: Types.ObjectId | string): Promise<BookmarkFolderDocument[]> {
|
|
@@ -104,6 +106,5 @@ bookmarkFolderSchema.statics.updateBookmarkFolder = async function(bookmarkFolde
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-bookmarkFolderSchema.set('toObject', { virtuals: true });
|
|
|
|
|
|
|
|
|
|
export default getOrCreateModel<BookmarkFolderDocument, BookmarkFolderModel>('BookmarkFolder', bookmarkFolderSchema);
|
|
export default getOrCreateModel<BookmarkFolderDocument, BookmarkFolderModel>('BookmarkFolder', bookmarkFolderSchema);
|