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/categories.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 getCategories = cache(async () => {
return await prisma.category.findMany({
orderBy: {
name: "asc",
},
})
})
export const getCategoryByCode = cache(async (code: string) => {
return await prisma.category.findUnique({
where: { code },
})
})
export const createCategory = async (category: Prisma.CategoryCreateInput) => {
if (!category.code) {
category.code = codeFromName(category.name as string)
}
return await prisma.category.create({
data: category,
})
}
export const updateCategory = async (code: string, category: Prisma.CategoryUpdateInput) => {
return await prisma.category.update({
where: { code },
data: category,
})
}
export const deleteCategory = async (code: string) => {
return await prisma.category.delete({
where: { code },
})
}