mirror of
https://github.com/vas3k/TaxHacker.git
synced 2026-01-05 05:01:09 -06:00
28 lines
708 B
TypeScript
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,
|
|
},
|
|
})
|
|
})
|