【发布时间】:2021-02-23 21:24:36
【问题描述】:
我正在使用 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);
}
服务
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;
}
}
在我的数据库中,我所有的父部分在 ParentId 中都有 NULL。
【问题讨论】:
标签: angular typescript api backend nestjs