mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
41 lines
969 B
TypeScript
41 lines
969 B
TypeScript
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 },
|
|
})
|
|
}
|