Refactored queries.

This commit is contained in:
Mike Cao 2023-07-29 22:03:34 -07:00
parent f36a689817
commit 8904b7b4ed
27 changed files with 137 additions and 144 deletions

View file

@ -5,9 +5,14 @@ import { ROLES } from 'lib/constants';
import prisma from 'lib/prisma';
import { Website, User, Role } from 'lib/types';
export async function getUser(
export interface GetUserOptions {
includePassword?: boolean;
showDeleted?: boolean;
}
async function getUser(
where: Prisma.UserWhereInput | Prisma.UserWhereUniqueInput,
options: { includePassword?: boolean; showDeleted?: boolean } = {},
options: GetUserOptions = {},
): Promise<User> {
const { includePassword = false, showDeleted = false } = options;
@ -23,6 +28,14 @@ export async function getUser(
});
}
export async function getUserById(userId: string, options: GetUserOptions = {}) {
return getUser({ id: userId }, options);
}
export async function getUserByUsername(username: string, options: GetUserOptions = {}) {
return getUser({ username }, options);
}
export async function getUsers(): Promise<User[]> {
return prisma.client.user.findMany({
take: 100,