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.

986 B
Raw Blame
"use server";

import { verifyFolderAccess } from "@/lib/folder/permissions";
import { prisma } from "@/lib/prisma";
import * as z from "zod/v4";
import { authActionClient } from "../safe-action";

const setDefaultFolderSchema = z.object({
  workspaceId: z.string(),
  folderId: z.string().nullable(),
});

// Set the default folder for a workspace for a user
export const setDefaultFolderAction = authActionClient
  .inputSchema(setDefaultFolderSchema)
  .action(async ({ ctx, parsedInput }) => {
    const { user, workspace } = ctx;
    const { folderId } = parsedInput;

    if (folderId) {
      await verifyFolderAccess({
        workspace,
        userId: user.id,
        folderId,
        requiredPermission: "folders.read",
      });
    }

    await prisma.projectUsers.update({
      where: {
        userId_projectId: {
          userId: user.id,
          projectId: workspace.id,
        },
      },
      data: {
        defaultFolderId: folderId,
      },
    });
  });