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 comment schema/action

Tim Wilson259d5b565e4b
diff --git a/apps/web/lib/actions/partners/update-partner-comment.ts b/apps/web/lib/actions/partners/update-partner-comment.ts
new file mode 100644
index 0000000000..af19d1bafe
--- /dev/null
+++ b/apps/web/lib/actions/partners/update-partner-comment.ts
@@ -0,0 +1,37 @@
+"use server";
+
+import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
+import { prisma } from "@dub/prisma";
+import {
+ PartnerCommentSchema,
+ updatePartnerCommentSchema,
+} from "../../zod/schemas/programs";
+import { authActionClient } from "../safe-action";
+
+// Update a partner comment
+export const updatePartnerCommentAction = authActionClient
+ .schema(updatePartnerCommentSchema)
+ .action(async ({ parsedInput, ctx }) => {
+ const { workspace, user } = ctx;
+ const { id, text } = parsedInput;
+
+ const programId = getDefaultProgramIdOrThrow(workspace);
+
+ const comment = await prisma.partnerComment.update({
+ where: {
+ id,
+ programId,
+ userId: user.id,
+ },
+ data: {
+ text,
+ },
+ include: {
+ user: true,
+ },
+ });
+
+ return {
+ comment: PartnerCommentSchema.parse(comment),
+ };
+ });
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 5284392ceb..46c1e622b5 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -210,18 +210,8 @@ export const createPartnerCommentSchema = z.object({
export const updatePartnerCommentSchema = z.object({
workspaceId: z.string(),
- partnerId: z.string(),
+ id: z.string(),
text: z.string().min(1).max(MAX_PROGRAM_PARTNER_COMMENT_LENGTH),
- createdAt: z.coerce
- .date()
- .refine(
- (date) =>
- date.getTime() <= Date.now() &&
- date.getTime() >= Date.now() - 1000 * 60,
- {
- message: "Comment timestamp must be within the last 60 seconds",
- },
- ),
});
export const deletePartnerCommentSchema = z.object({