Angular 如何仅返回所有父节?

Angular 如何仅返回所有父节?,angular,typescript,api,backend,nestjs,Angular,Typescript,Api,Backend,Nestjs,我正在为我的后端使用Nestjs,我正在尝试创建一个只返回所有父节的api调用,但不确定如何执行,因此如果我能得到任何帮助或建议,我将不胜感激 实体 @PrimaryGeneratedColumn({ type: "int", name: "Id", }) id: number; @Column("nvarchar", { nullable: false,

我正在为我的后端使用Nestjs,我正在尝试创建一个只返回所有父节的api调用,但不确定如何执行,因此如果我能得到任何帮助或建议,我将不胜感激

实体

    @PrimaryGeneratedColumn({
        type: "int",
        name: "Id",
    })
    id: number;

    @Column("nvarchar", {
        nullable: false,
        unique: true,
        name: "Name"
    })
    name: string;

    @Column("nvarchar", {
        nullable: false,
        name: "ParentId"
    })
    parentId: number;
控制器

    @Get('/parentSection')
    async getSectionHelp(@Req() req, @Param() params):Promise<HelpEntity[]>{
        return this.helpService.getHelpbySection(req.user, params.id);
    }
@Get(“/parentSection”)
异步getSectionHelp(@Req()Req,@Param()params):承诺{
返回此.helpService.getHelpbySection(req.user,params.id);
}
服务

  constructor(@InjectRepository(HelpEntity) private readonly helpRepo: Repository<HelpEntity>,

    async getHelpbySection(gmid: string, id: number) : Promise<any>{
        let check = await this.checkIfAdmin(gmid);
        if (!check) {
            throw new HttpException('Unauthorized', 401);
        } else {
            const res = await this.helpRepo.find()
            if (!res) {
                throw new NotFoundException(`This ID: ${id} is not found`)
            }
            return res;
        }
    }
constructor(@InjectRepository(HelpEntity)私有只读helpRepo:Repository,

异步getHelpbySection(gmid:string,id:number):Promise

您只需在find函数中指定它:

 import {IsNull} from "typeorm";
 ...
 ...
 async getHelpbySection(gmid: string, id: number) : Promise<any>{
    let check = await this.checkIfAdmin(gmid);
    if (!check) {
        throw new HttpException('Unauthorized', 401);
    } else {
        const res = await this.helpRepo.find({parentId: IsNull()})
        if (!res) {
            throw new NotFoundException(`This ID: ${id} is not found`)
        }
        return res;
    }
}
从“typeorm”导入{IsNull};
...
...
异步getHelpbySection(gmid:string,id:number):承诺{
让check=等待这个。checkIfAdmin(gmid);
如果(!检查){
抛出新的HttpException('Unauthorized',401);
}否则{
const res=wait this.helpRepo.find({parentId:IsNull()})
如果(!res){
抛出新的NotFoundException(`This ID:${ID}未找到`)
}
返回res;
}
}

啊,这很有效。非常感谢你,Youba..我真的很感激你。你好,Youba..你能帮我解决这个问题吗?如果你能帮我,我将不胜感激。谢谢你,不客气,我刚刚做了,你现在可以查看了