diff --git a/packages/core/src/modules/applications/applications.ts b/packages/core/src/modules/applications/applications.ts index c562911dc..67c1a4dd9 100644 --- a/packages/core/src/modules/applications/applications.ts +++ b/packages/core/src/modules/applications/applications.ts @@ -631,12 +631,22 @@ async function shouldReject( return [true, 'email_already_used']; } - const memberWithSameLinkedIn = await db - .selectFrom('students') - .where('linkedInUrl', 'ilike', application.linkedInUrl) - .executeTakeFirst(); - - if (memberWithSameLinkedIn) { + const [memberWithSameLinkedIn, applicationAcceptedWithSameLinkedIn] = + await Promise.all([ + db + .selectFrom('students') + .where('linkedInUrl', 'ilike', application.linkedInUrl) + .executeTakeFirst(), + + db + .selectFrom('applications') + .where('id', '!=', application.id) + .where('linkedInUrl', 'ilike', application.linkedInUrl) + .where('status', '=', ApplicationStatus.ACCEPTED) + .executeTakeFirst(), + ]); + + if (memberWithSameLinkedIn || applicationAcceptedWithSameLinkedIn) { return [true, 'linkedin_already_used']; }