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,22 +3,25 @@ import { cache } from "react"
export type SettingsMap = Record<string, string>
export const getSettings = cache(async (): Promise<SettingsMap> => {
const settings = await prisma.setting.findMany()
export const getSettings = cache(async (userId: string): Promise<SettingsMap> => {
const settings = await prisma.setting.findMany({
where: { userId },
})
return settings.reduce((acc, setting) => {
acc[setting.code] = setting.value || ""
return acc
}, {} as SettingsMap)
})
export const updateSettings = cache(async (code: string, value?: any) => {
export const updateSettings = cache(async (userId: string, code: string, value: any) => {
return await prisma.setting.upsert({
where: { code },
where: { userId_code: { code, userId } },
update: { value },
create: {
code,
value,
name: code,
userId,
},
})
})