diff --git a/lib/user.ts b/lib/user.ts index c045cf2..aa9e78d 100644 --- a/lib/user.ts +++ b/lib/user.ts @@ -7,17 +7,45 @@ export type UserBody = { name?: string; }; +type BooleanObject = { + [K in keyof T]?: boolean; +}; + +export const exclude = ( + fields: T, + excludes: (keyof T)[], +): BooleanObject => { + const object: BooleanObject = {}; + const keys = Object.keys(fields!).filter( + (key) => !excludes.includes(key as keyof T), + ) as (keyof T)[]; + + for (let key of keys) { + object[key] = true; + } + + return object; +}; + +const select = exclude(prisma.user.fields, ["email"]); + export async function getUser(email: string) { return await prisma.user.findUnique({ where: { email, }, include: { - target: true, + target: { + select, + }, party: { include: { - players: true, - winner: true, + players: { + select, + }, + winner: { + select, + }, }, }, },