this repo has no description
1"use server";
2
3import { eq } from "drizzle-orm";
4import { setting } from "@/db/schema";
5import { getUserId } from "@/lib/auth";
6import { db } from "@/lib/db";
7
8export async function createSetting(userId: string) {
9 const [res] = await db.insert(setting).values({ userId: userId }).returning();
10 return res;
11}
12
13export async function updateSetting(notify: boolean) {
14 const userId = await getUserId();
15 if (!userId) return null;
16
17 const [res] = await db
18 .update(setting)
19 .set({ notify })
20 .where(eq(setting.userId, userId))
21 .returning();
22
23 return res;
24}
25
26export async function getSetting(userId?: string) {
27 if (!userId) {
28 userId = (await getUserId()) || undefined;
29 if (!userId) return null;
30 }
31
32 return await db.query.setting.findFirst({
33 where: eq(setting.userId, userId),
34 });
35}