BREAKING: postgres + saas

This commit is contained in:
Vasily Zubarev
2025-04-03 13:07:54 +02:00
parent 54a892ddb0
commit f523b1f8ba
136 changed files with 3971 additions and 1563 deletions

View File

@@ -3,38 +3,50 @@ import { codeFromName } from "@/lib/utils"
import { Prisma } from "@prisma/client"
import { cache } from "react"
export const getProjects = cache(async () => {
export type ProjectData = {
[key: string]: unknown
}
export const getProjects = cache(async (userId: string) => {
return await prisma.project.findMany({
where: { userId },
orderBy: {
name: "asc",
},
})
})
export const getProjectByCode = cache(async (code: string) => {
export const getProjectByCode = cache(async (userId: string, code: string) => {
return await prisma.project.findUnique({
where: { code },
where: { userId_code: { code, userId } },
})
})
export const createProject = async (project: Prisma.ProjectCreateInput) => {
export const createProject = async (userId: string, project: ProjectData) => {
if (!project.code) {
project.code = codeFromName(project.name as string)
}
return await prisma.project.create({
data: project,
data: {
...project,
user: {
connect: {
id: userId,
},
},
} as Prisma.ProjectCreateInput,
})
}
export const updateProject = async (code: string, project: Prisma.ProjectUpdateInput) => {
export const updateProject = async (userId: string, code: string, project: ProjectData) => {
return await prisma.project.update({
where: { code },
where: { userId_code: { code, userId } },
data: project,
})
}
export const deleteProject = async (code: string) => {
export const deleteProject = async (userId: string, code: string) => {
return await prisma.project.delete({
where: { code },
where: { userId_code: { code, userId } },
})
}