fix: rename data -> models

This commit is contained in:
Vasily Zubarev
2025-03-22 10:39:47 +01:00
parent ac8f848d94
commit 9ca7d9c712
50 changed files with 103 additions and 98 deletions

40
models/projects.ts Normal file
View File

@@ -0,0 +1,40 @@
import { prisma } from "@/lib/db"
import { codeFromName } from "@/lib/utils"
import { Prisma } from "@prisma/client"
import { cache } from "react"
export const getProjects = cache(async () => {
return await prisma.project.findMany({
orderBy: {
name: "asc",
},
})
})
export const getProjectByCode = cache(async (code: string) => {
return await prisma.project.findUnique({
where: { code },
})
})
export const createProject = async (project: Prisma.ProjectCreateInput) => {
if (!project.code) {
project.code = codeFromName(project.name as string)
}
return await prisma.project.create({
data: project,
})
}
export const updateProject = async (code: string, project: Prisma.ProjectUpdateInput) => {
return await prisma.project.update({
where: { code },
data: project,
})
}
export const deleteProject = async (code: string) => {
return await prisma.project.delete({
where: { code },
})
}