first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
113
packages/database/prisma/queries/users.ts
Normal file
113
packages/database/prisma/queries/users.ts
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
import type { z } from "zod";
|
||||
import { db } from "../client";
|
||||
import type { UserUncheckedUpdateInputSchema } from "../zod";
|
||||
|
||||
export async function getUsers({
|
||||
limit,
|
||||
offset,
|
||||
query,
|
||||
}: {
|
||||
limit: number;
|
||||
offset: number;
|
||||
query?: string;
|
||||
}) {
|
||||
return await db.user.findMany({
|
||||
where: query
|
||||
? {
|
||||
name: {
|
||||
contains: query,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
take: limit,
|
||||
skip: offset,
|
||||
});
|
||||
}
|
||||
|
||||
export async function countAllUsers() {
|
||||
return await db.user.count();
|
||||
}
|
||||
|
||||
export async function getUserById(id: string) {
|
||||
return await db.user.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUserByEmail(email: string) {
|
||||
return await db.user.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createUser({
|
||||
email,
|
||||
name,
|
||||
role,
|
||||
emailVerified,
|
||||
onboardingComplete,
|
||||
}: {
|
||||
email: string;
|
||||
name: string;
|
||||
role: "admin" | "user";
|
||||
emailVerified: boolean;
|
||||
onboardingComplete: boolean;
|
||||
}) {
|
||||
return await db.user.create({
|
||||
data: {
|
||||
email,
|
||||
name,
|
||||
role,
|
||||
emailVerified,
|
||||
onboardingComplete,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAccountById(id: string) {
|
||||
return await db.account.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createUserAccount({
|
||||
userId,
|
||||
providerId,
|
||||
accountId,
|
||||
hashedPassword,
|
||||
}: {
|
||||
userId: string;
|
||||
providerId: string;
|
||||
accountId: string;
|
||||
hashedPassword?: string;
|
||||
}) {
|
||||
return await db.account.create({
|
||||
data: {
|
||||
userId,
|
||||
accountId,
|
||||
providerId,
|
||||
password: hashedPassword,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateUser(
|
||||
user: z.infer<typeof UserUncheckedUpdateInputSchema> & { id: string },
|
||||
) {
|
||||
return await db.user.update({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
data: user,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue