mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
fix: rename data -> models
This commit is contained in:
40
models/categories.ts
Normal file
40
models/categories.ts
Normal 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 },
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user