Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

916 B
Raw Blame
"use server";

import { prisma } from "@/lib/prisma";
import * as z from "zod/v4";
import { notificationTypes } from "../zod/schemas/workspaces";
import { authActionClient } from "./safe-action";

const schema = z.object({
  workspaceId: z.string(),
  type: notificationTypes,
  value: z.boolean(),
});

// Update the notification preference for a user in a workspace
export const updateWorkspaceNotificationPreference = authActionClient
  .inputSchema(schema)
  .action(async ({ ctx, parsedInput }) => {
    const { user, workspace } = ctx;
    const { type, value } = parsedInput;

    await prisma.projectUsers.update({
      where: {
        userId_projectId: {
          userId: user.id,
          projectId: workspace.id,
        },
      },
      data: {
        notificationPreference: {
          update: {
            [type]: value,
          },
        },
      },
    });

    return { ok: true };
  });