import { Injectable } from "@nestjs/common" ; import { MongooseService , ResultList , TreeNode } from "nestx-common" ; import { CategoryModel } from "./../interfaces" ; import { Model } from "mongoose" ; import { InjectModel } from "@nestjs/mongoose" ; @ Injectable ( ) export class CategoryService extends MongooseService < CategoryModel > { defaultQueryFields = [ "name" , "slug" , "order" , "parent" , "description" ] ; constructor ( @ InjectModel ( "Category" ) protected readonly model ) { super ( model ) ; } async searchCategoryTree ( keyword ? , value ? , limit = 10 ) { return super . searchTree ( this . model , keyword , value , "" , limit ) ; } async querySearch ( keyword , page , size , sort ) { return super . query ( page , size , { } , { keyword , field : "name" } , this . defaultQueryFields , sort ) ; } async getCategory ( id ) { const instance = await this . model . findById ( id ) . select ( this . defaultQueryFields ) . exec ( ) ; return instance ; } }