Files
TaxHacker/models/settings.ts
2025-04-09 12:45:56 +02:00

28 lines
708 B
TypeScript

import { prisma } from "@/lib/db"
import { cache } from "react"
export type SettingsMap = Record<string, string>
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 (userId: string, code: string, value: string | undefined) => {
return await prisma.setting.upsert({
where: { userId_code: { code, userId } },
update: { value },
create: {
code,
value,
name: code,
userId,
},
})
})