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

@@ -2,29 +2,37 @@ import { prisma } from "@/lib/db"
import { Prisma } from "@prisma/client"
import { cache } from "react"
export const getCurrencies = cache(async () => {
export const getCurrencies = cache(async (userId: string) => {
return await prisma.currency.findMany({
where: { userId },
orderBy: {
code: "asc",
},
})
})
export const createCurrency = async (currency: Prisma.CurrencyCreateInput) => {
export const createCurrency = async (userId: string, currency: Prisma.CurrencyCreateInput) => {
return await prisma.currency.create({
data: currency,
data: {
...currency,
user: {
connect: {
id: userId,
},
},
},
})
}
export const updateCurrency = async (code: string, currency: Prisma.CurrencyUpdateInput) => {
export const updateCurrency = async (userId: string, code: string, currency: Prisma.CurrencyUpdateInput) => {
return await prisma.currency.update({
where: { code },
where: { userId_code: { code, userId } },
data: currency,
})
}
export const deleteCurrency = async (code: string) => {
export const deleteCurrency = async (userId: string, code: string) => {
return await prisma.currency.delete({
where: { code },
where: { userId_code: { code, userId } },
})
}