Files
calendar/packages/prisma/extensions/exclude-locked-users.ts
T
Keith WilliamsandGitHub 716e66b0c3 chore: Use relative imports for @calcom/prisma inside of @calcom/prisma (#26245)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Switch @calcom/prisma to use relative imports for client and enums. This removes self-references, stabilizes builds, and improves type resolution.

- **Refactors**
  - Replaced imports from "@calcom/prisma/*" with local "./client" and "./enums" across extensions, selects, mocks, and availability check.
  - Updated safeJSONStringify parameter type from any to unknown.
  - Minor formatting cleanup in zod-utils.

<sup>Written for commit 85c0a7b75fb1291be5b848a73d1ccb5543283f49. Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-12-29 00:52:12 -03:00

53 lines
1.3 KiB
TypeScript

import { Prisma } from "../client";
export function excludeLockedUsersExtension() {
return Prisma.defineExtension({
query: {
user: {
async findUnique({ args, query }) {
return excludeLockedUsers(args, query);
},
async findFirst({ args, query }) {
return excludeLockedUsers(args, query);
},
async findMany({ args, query }) {
return excludeLockedUsers(args, query);
},
async findUniqueOrThrow({ args, query }) {
return excludeLockedUsers(args, query);
},
async findFirstOrThrow({ args, query }) {
return excludeLockedUsers(args, query);
},
},
},
});
}
function safeJSONStringify(x: unknown) {
try {
return JSON.stringify(x);
} catch {
return "";
}
}
async function excludeLockedUsers(
args:
| Prisma.UserFindUniqueArgs
| Prisma.UserFindFirstArgs
| Prisma.UserFindManyArgs
| Prisma.UserFindUniqueOrThrowArgs
| Prisma.UserFindFirstOrThrowArgs,
query: <T>(args: T) => Promise<unknown>
) {
args.where = args.where || {};
const whereString = safeJSONStringify(args.where);
const shouldIncludeLocked = whereString.includes('"locked":');
// Unless explicitly specified, we exclude locked users
if (!shouldIncludeLocked) {
args.where.locked = false;
}
return query(args);
}