Files
calendar/packages/prisma/extensions/exclude-locked-users.ts
T
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Keith Williams
6defa1cd7d refactor: replace @prisma/client/runtime imports with public API (#23087)
- Replace PrismaClientKnownRequestError and other error classes with Prisma namespace equivalents
- Remove internal DefaultArgs and InternalArgs type imports from Prisma extensions
- Ensure all error handling uses stable public API exports
- Maintain compatibility with future Prisma versions by avoiding runtime dependencies

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-08-29 03:09:52 +01:00

53 lines
1.3 KiB
TypeScript

import { Prisma } from "@prisma/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: any) {
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);
}