File tree Expand file tree Collapse file tree
api/cron/cleanup/rejected-applications
partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled) Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { handleAndReturnErrorResponse } from "@/lib/api/errors" ;
2+ import { verifyQstashSignature } from "@/lib/cron/verify-qstash" ;
3+ import { prisma } from "@dub/prisma" ;
4+ import { log } from "@dub/utils" ;
5+ import { NextResponse } from "next/server" ;
6+
7+ export const dynamic = "force-dynamic" ;
8+
9+ // This route is used to remove rejected programEnrollments from the database after 30 days so partners can re-apply
10+ // Runs once every day at 02:00:00 AM UTC (0 2 * * *)
11+ // POST /api/cron/cleanup/rejected-applications
12+ export async function POST ( req : Request ) {
13+ try {
14+ const rawBody = await req . text ( ) ;
15+
16+ await verifyQstashSignature ( {
17+ req,
18+ rawBody,
19+ } ) ;
20+
21+ // rejected programEnrollments more than 30 days ago
22+ const rejectedProgramEnrollments =
23+ await prisma . programEnrollment . deleteMany ( {
24+ where : {
25+ status : "rejected" ,
26+ updatedAt : {
27+ lt : new Date ( Date . now ( ) - 1000 * 60 * 60 * 24 * 30 ) ,
28+ } ,
29+ } ,
30+ } ) ;
31+
32+ console . log (
33+ `Deleted ${ rejectedProgramEnrollments . count } rejected programEnrollments (older than 30 days)` ,
34+ ) ;
35+
36+ return NextResponse . json ( { status : "OK" } ) ;
37+ } catch ( error ) {
38+ await log ( {
39+ message : `/api/cron/cleanup/rejected-applications failed - ${ error . message } ` ,
40+ type : "errors" ,
41+ } ) ;
42+
43+ return handleAndReturnErrorResponse ( error ) ;
44+ }
45+ }
Original file line number Diff line number Diff line change @@ -34,7 +34,8 @@ const states: Record<
3434 } ) ,
3535 rejected : ( ) => ( {
3636 title : "Application rejected" ,
37- description : "Your application has been rejected." ,
37+ description :
38+ "Your application has been rejected. You can re-apply in 30 days." ,
3839 } ) ,
3940} ;
4041
@@ -86,7 +87,7 @@ export function UnapprovedProgramPage({
8687 </ h2 >
8788 < p className = "text-content-subtle [&_strong]:text-content-default mt-2 max-w-sm text-balance text-sm font-medium [&_strong]:font-semibold" >
8889 { description } { " " }
89- { [ "banned" , "rejected" ] . includes ( programEnrollment . status ) && (
90+ { programEnrollment . status === "banned" && (
9091 < >
9192 < Link
9293 href = { `/messages/${ programEnrollment . program . slug } ` }
Original file line number Diff line number Diff line change @@ -59,20 +59,18 @@ export function ProgramCard({
5959 < div className = "mt-4 flex h-20 items-center justify-center text-balance rounded-md border border-neutral-200 bg-neutral-50 p-5 text-center text-sm text-neutral-500" >
6060 { status === "pending" ? (
6161 `Applied ${ formatDate ( createdAt ) } `
62+ ) : status === "rejected" ? (
63+ `${ statusDescription } You can re-apply in 30 days.`
6264 ) : statusDescription ? (
6365 < p >
64- { ` ${ statusDescription } ` }
65- { status !== "rejected" && (
66- < >
67- < Link
68- href = { `/messages/${ program . slug } ` }
69- className = "text-neutral-400 underline decoration-dotted underline-offset-2 hover:text-neutral-700"
70- >
71- Reach out to the { program . name } team
72- </ Link > { " " }
73- if you have any questions.
74- </ >
75- ) }
66+ { statusDescription } { " " }
67+ < Link
68+ href = { `/messages/${ program . slug } ` }
69+ className = "text-neutral-400 underline decoration-dotted underline-offset-2 hover:text-neutral-700"
70+ >
71+ Reach out to the { program . name } team
72+ </ Link > { " " }
73+ if you have any questions.
7674 </ p >
7775 ) : null }
7876 </ div >
You can’t perform that action at this time.
0 commit comments