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 getCategories = cache(async () => {
export type CategoryData = {
[key: string]: unknown
}
export const getCategories = cache(async (userId: string) => {
return await prisma.category.findMany({
where: { userId },
orderBy: {
name: "asc",
},
})
})
export const getCategoryByCode = cache(async (code: string) => {
export const getCategoryByCode = cache(async (userId: string, code: string) => {
return await prisma.category.findUnique({
where: { code },
where: { userId_code: { code, userId } },
})
})
export const createCategory = async (category: Prisma.CategoryCreateInput) => {
export const createCategory = async (userId: string, category: CategoryData) => {
if (!category.code) {
category.code = codeFromName(category.name as string)
}
return await prisma.category.create({
data: category,
data: {
...category,
user: {
connect: {
id: userId,
},
},
} as Prisma.CategoryCreateInput,
})
}
export const updateCategory = async (code: string, category: Prisma.CategoryUpdateInput) => {
export const updateCategory = async (userId: string, code: string, category: CategoryData) => {
return await prisma.category.update({
where: { code },
where: { userId_code: { code, userId } },
data: category,
})
}
export const deleteCategory = async (code: string) => {
export const deleteCategory = async (userId: string, code: string) => {
return await prisma.category.delete({
where: { code },
where: { userId_code: { code, userId } },
})
}