mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
BREAKING: postgres + saas
This commit is contained in:
35
models/users.ts
Normal file
35
models/users.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { prisma } from "@/lib/db"
|
||||
import { Prisma } from "@prisma/client"
|
||||
import { cache } from "react"
|
||||
|
||||
export const SELF_HOSTED_USER = {
|
||||
email: "taxhacker@localhost",
|
||||
name: "Self-Hosted Mode",
|
||||
}
|
||||
|
||||
export const getSelfHostedUser = cache(async () => {
|
||||
return await prisma.user.findFirst({
|
||||
where: { email: SELF_HOSTED_USER.email },
|
||||
})
|
||||
})
|
||||
|
||||
export const createSelfHostedUser = cache(async () => {
|
||||
return await prisma.user.upsert({
|
||||
where: { email: SELF_HOSTED_USER.email },
|
||||
update: SELF_HOSTED_USER,
|
||||
create: SELF_HOSTED_USER,
|
||||
})
|
||||
})
|
||||
|
||||
export const getUserByEmail = cache(async (email: string) => {
|
||||
return await prisma.user.findUnique({
|
||||
where: { email },
|
||||
})
|
||||
})
|
||||
|
||||
export function updateUser(userId: string, data: Prisma.UserUpdateInput) {
|
||||
return prisma.user.update({
|
||||
where: { id: userId },
|
||||
data,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user