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.

update program

Kiran K47951223590a
diff --git a/apps/web/lib/actions/update-program.ts b/apps/web/lib/actions/update-program.ts
new file mode 100644
index 0000000000..256a01ace4
--- /dev/null
+++ b/apps/web/lib/actions/update-program.ts
@@ -0,0 +1,52 @@
+"use server";
+
+import { prisma } from "@/lib/prisma";
+import { z } from "zod";
+import { getProgramOrThrow } from "../api/programs/get-program";
+import { createProgramSchema } from "../zod/schemas/programs";
+import { authActionClient } from "./safe-action";
+
+const schema = createProgramSchema.partial().extend({
+ workspaceId: z.string(),
+ programId: z.string(),
+});
+
+export const updateProgramAction = authActionClient
+ .schema(schema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace } = ctx;
+ const {
+ programId,
+ name,
+ commissionType,
+ commissionAmount,
+ recurringCommission,
+ minimumPayout,
+ recurringDuration,
+ recurringInterval,
+ isLifetimeRecurring,
+ } = parsedInput;
+
+ await getProgramOrThrow({
+ workspaceId: workspace.id,
+ programId,
+ });
+
+ const program = await prisma.program.update({
+ where: {
+ id: programId,
+ },
+ data: {
+ name,
+ commissionType,
+ commissionAmount,
+ recurringCommission,
+ minimumPayout,
+ recurringDuration,
+ recurringInterval,
+ isLifetimeRecurring,
+ },
+ });
+
+ return program;
+ });