@Schema({
timestamps: true,
})
export class Category extends mongoose.Document {
@Prop({
required: true,
unique: true,
})
category: string;
@Prop({
type: mongoose.Schema.Types.ObjectId,
ref: 'Category',
})
parent: mongoose.Schema.Types.ObjectId;
@Prop()
description: string;
@Prop({
unique: true,
})
position: number;
}
export const CategorySchema = SchemaFactory.createForClass(Category);
// поиск:
async getAll(): Promise<Category[]> {
const arrCat = await this.categoryModel.find({}, null, { sort: { parent: 1, }, })
.populate(
Category.name)
.exec();