mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 19:39:01 -05:00
35b2d12e18
Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
"use server";
|
|
|
|
import { authenticatedActionClient } from "@/lib/utils/action-client";
|
|
import { checkAuthorizationUpdated } from "@/lib/utils/action-client-middleware";
|
|
import { getOrganizationIdFromProjectId } from "@/lib/utils/helper";
|
|
import { deleteProject } from "@/modules/projects/settings/lib/project";
|
|
import { z } from "zod";
|
|
import { getUserProjects } from "@formbricks/lib/project/service";
|
|
import { ZId } from "@formbricks/types/common";
|
|
|
|
const ZProjectDeleteAction = z.object({
|
|
projectId: ZId,
|
|
});
|
|
|
|
export const deleteProjectAction = authenticatedActionClient
|
|
.schema(ZProjectDeleteAction)
|
|
.action(async ({ ctx, parsedInput }) => {
|
|
const organizationId = await getOrganizationIdFromProjectId(parsedInput.projectId);
|
|
|
|
await checkAuthorizationUpdated({
|
|
userId: ctx.user.id,
|
|
organizationId: organizationId,
|
|
access: [
|
|
{
|
|
type: "organization",
|
|
roles: ["owner", "manager"],
|
|
},
|
|
],
|
|
});
|
|
|
|
const availableProjects = (await getUserProjects(ctx.user.id, organizationId)) ?? null;
|
|
|
|
if (!!availableProjects && availableProjects?.length <= 1) {
|
|
throw new Error("You can't delete the last project in the environment.");
|
|
}
|
|
|
|
// delete project
|
|
return await deleteProject(parsedInput.projectId);
|
|
});
|