我的类别服务中有一个分页,我必须返回 obj 以及类别和数据的总数
但可能有一些参数。例如,我应该返回由特定用户创建的类别:
async findAll(
{ onlyParents }: ParamsCategoryDto,
user: ITokenPayload | undefined,
): Promise<IFilterRes> {
const categories = await this.prisma.category.findMany({
where: {
user_id: user?.id,
},
});
return {
pagination: {
total: this.prisma.category.count({
where: { // <- duplicate
user_id: user?.id,
},
}),
},
data: categories,
};
}
Run Code Online (Sandbox Code Playgroud)
我应该在两个查询中复制where 。这不太好。是否有任何选项可以在一个请求中完成此操作。
PS我可以为where做一些var,但这样我就失去了典型化,我也不喜欢这一点。
我在使用 Nestjs HttpModule 时遇到问题
错误:
Nest can't resolve dependencies of the ShopService (PrismaService, ?). Please make sure that the argument HttpService at index [1] is available in the QaModule context.
我的商店模块:
@Module({
imports: [HttpModule],
controllers: [ShopController],
providers: [ShopService, PrismaService],
})
export class ShopModule {}
Run Code Online (Sandbox Code Playgroud)
我的 Qa 模块:
@Module({
controllers: [QaController],
providers: [QaService, PrismaService, ShopService],
})
export class QaModule {}
Run Code Online (Sandbox Code Playgroud)
解决办法有哪些?