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.

Only block group applications on a rejection since enrollment

Rafi13dc75b49944
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index d8d2b15b1e..26a2446d5a 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -322,25 +322,36 @@ async function createApplicationAndEnrollment({
let rejectedAt: Date | null = null;
- // Find the last application rejection date for the partner.
- // This is used to check if the partner is within the reapplication window.
+ // The stored timeframe belongs to the latest application reviewed since the
+ // enrollment was created, and only applies if that review was a rejection.
+ // Earlier rejections, or a rejection approved later, do not block.
if (shouldCheckReapplicationWindow) {
- const latestApplicationRejection =
- await tx.programApplication.findFirst({
- where: {
- programId: program.id,
- partnerId: partner.id,
- status: ProgramApplicationStatus.rejected,
- },
- orderBy: {
- reviewedAt: "desc",
+ const latestReview = await tx.programApplication.findFirst({
+ where: {
+ programId: program.id,
+ partnerId: partner.id,
+ status: {
+ in: [
+ ProgramApplicationStatus.rejected,
+ ProgramApplicationStatus.approved,
+ ],
},
- select: {
- reviewedAt: true,
+ reviewedAt: {
+ gte: enrollment.createdAt,
},
- });
+ },
+ orderBy: {
+ reviewedAt: "desc",
+ },
+ select: {
+ status: true,
+ reviewedAt: true,
+ },
+ });
- rejectedAt = latestApplicationRejection?.reviewedAt ?? null;
+ if (latestReview?.status === ProgramApplicationStatus.rejected) {
+ rejectedAt = latestReview.reviewedAt;
+ }
}
throwIfApplicationBlocked({
diff --git a/apps/web/lib/program-applications/throw-if-application-blocked.ts b/apps/web/lib/program-applications/throw-if-application-blocked.ts
index b176433f08..25eec3140c 100644
--- a/apps/web/lib/program-applications/throw-if-application-blocked.ts
+++ b/apps/web/lib/program-applications/throw-if-application-blocked.ts
@@ -10,8 +10,9 @@ import { addDays } from "date-fns";
* Throws if the partner's existing enrollment prevents a new application to `groupId`.
*
* Approved partners applying to another group are held to the stored
- * `reapplicationTimeframe`, measured from `rejectedAt` (the latest rejected
- * application's `reviewedAt`). Omit `rejectedAt` to skip that window.
+ * `reapplicationTimeframe`, measured from `rejectedAt` (the `reviewedAt` of the
+ * latest application reviewed since enrollment, if it was rejected). Omit
+ * `rejectedAt` to skip that window.
*/
export function throwIfApplicationBlocked({
enrollment,