小编SPR*_*1NG的帖子

Prisma 查找多个请求并计入一个请求

我的类别服务中有一个分页,我必须返回 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,但这样我就失去了典型化,我也不喜欢这一点。

javascript backend prisma

7
推荐指数
1
解决办法
9957
查看次数

Nest 无法解析 X 的依赖关系。请确保索引 [1] 处的参数 HttpService 在模块上下文中可用

我在使用 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)

解决办法有哪些?

javascript node.js nestjs

2
推荐指数
1
解决办法
1200
查看次数

标签 统计

javascript ×2

backend ×1

nestjs ×1

node.js ×1

prisma ×1