diff --git a/packages/runtime/src/enhancements/node/policy/handler.ts b/packages/runtime/src/enhancements/node/policy/handler.ts index f42dad01f..8d3d496be 100644 --- a/packages/runtime/src/enhancements/node/policy/handler.ts +++ b/packages/runtime/src/enhancements/node/policy/handler.ts @@ -35,7 +35,7 @@ type PostWriteCheckRecord = { preValue?: any; }; -type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFirstOrThrow' | 'findMany'; +type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFirstOrThrow' | 'findMany' | 'count'; /** * Prisma proxy handler for injecting access policy check. @@ -144,6 +144,10 @@ export class PolicyProxyHandler implements Pr this.logger.info(`[policy] \`${actionName}\` ${this.model}:\n${formatObject(_args)}`); } + if (actionName === 'count') { + _args.select = true; + } + const result = await this.modelClient[actionName](_args); return this.policyUtils.postProcessForRead(result, this.model, origArgs); } @@ -1650,16 +1654,7 @@ export class PolicyProxyHandler implements Pr } count(args: any) { - return createDeferredPromise(() => { - // inject policy conditions - args = args ? this.policyUtils.safeClone(args) : {}; - this.policyUtils.injectAuthGuardAsWhere(this.prisma, args, this.model, 'read'); - - if (this.shouldLogQuery) { - this.logger.info(`[policy] \`count\` ${this.model}:\n${formatObject(args)}`); - } - return this.modelClient.count(args); - }); + return createDeferredPromise(() => this.doFind(args, 'count', () => [])); } //#endregion