Skip to content

Commit

Permalink
remove email from queries
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Mar 1, 2024
1 parent 62aa5ec commit d7938c6
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,45 @@ export type UserBody = {
name?: string;
};

type BooleanObject<T> = {
[K in keyof T]?: boolean;
};

export const exclude = <T>(
fields: T,
excludes: (keyof T)[],
): BooleanObject<T> => {
const object: BooleanObject<T> = {};
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,
},
},
},
},
Expand Down

0 comments on commit d7938c6

Please sign in to comment.