The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add partner API for submitted lead comments
Rafia8ca0b1ca776
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/[leadId]/comments/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/[leadId]/comments/route.tsnew file mode 100644index 0000000000..375f41dce0--- /dev/null+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/submitted-leads/[leadId]/comments/route.ts@@ -0,0 +1,49 @@+import { DubApiError } from "@/lib/api/errors";+import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";+import { withPartnerProfile } from "@/lib/auth/partner";+import { prisma } from "@/lib/prisma";+import { SubmittedLeadCommentSchema } from "@/lib/zod/schemas/submitted-leads";+import { NextResponse } from "next/server";+import * as z from "zod/v4";++// GET /api/partner-profile/programs/[programId]/submitted-leads/[leadId]/comments+export const GET = withPartnerProfile(async ({ partner, params }) => {+ const { programId } = await getProgramEnrollmentOrThrow({+ partnerId: partner.id,+ programId: params.programId,+ include: {},+ });++ const lead = await prisma.submittedLead.findUnique({+ where: {+ id: params.leadId,+ programId,+ partnerId: partner.id,+ },+ select: {+ id: true,+ },+ });++ if (!lead) {+ throw new DubApiError({+ code: "not_found",+ message: "Submitted lead not found.",+ });+ }++ const comments = await prisma.submittedLeadComment.findMany({+ where: {+ leadId: lead.id,+ partnerVisible: true,+ },+ include: {+ user: true,+ },+ orderBy: {+ createdAt: "desc",+ },+ });++ return NextResponse.json(z.array(SubmittedLeadCommentSchema).parse(comments));+});diff --git a/apps/web/lib/submitted-leads/create-partner-submitted-lead-comment-action.ts b/apps/web/lib/submitted-leads/create-partner-submitted-lead-comment-action.tsnew file mode 100644index 0000000000..2c01f95217--- /dev/null+++ b/apps/web/lib/submitted-leads/create-partner-submitted-lead-comment-action.ts@@ -0,0 +1,58 @@+"use server";++import { DubApiError } from "@/lib/api/errors";+import { prisma } from "@/lib/prisma";+import {+ SubmittedLeadCommentSchema,+ createPartnerSubmittedLeadCommentSchema,+} from "@/lib/zod/schemas/submitted-leads";+import { authPartnerActionClient } from "../actions/safe-action";+import { ACTIVE_ENROLLMENT_STATUSES } from "../zod/schemas/partners";++// Create a comment on a submitted lead as the partner who submitted it+export const createPartnerSubmittedLeadCommentAction = authPartnerActionClient+ .inputSchema(createPartnerSubmittedLeadCommentSchema)+ .action(async ({ parsedInput, ctx }) => {+ const { partner, user } = ctx;+ const { programId, leadId, text } = parsedInput;++ const lead = await prisma.submittedLead.findUnique({+ where: {+ id: leadId,+ programId,+ partnerId: partner.id,+ programEnrollment: {+ status: {+ in: ACTIVE_ENROLLMENT_STATUSES,+ },+ },+ },+ select: {+ id: true,+ },+ });++ if (!lead) {+ throw new DubApiError({+ code: "not_found",+ message: "Submitted lead not found.",+ });+ }++ const comment = await prisma.submittedLeadComment.create({+ data: {+ leadId: lead.id,+ userId: user.id,+ partnerId: partner.id,+ text,+ partnerVisible: true,+ },+ include: {+ user: true,+ },+ });++ return {+ comment: SubmittedLeadCommentSchema.parse(comment),+ };+ });