+
+
+
+
)}
diff --git a/src/app/api/assessments/send-invitation/route.ts b/src/app/api/assessments/send-invitation/route.ts
index f59bbc56..6d960e93 100644
--- a/src/app/api/assessments/send-invitation/route.ts
+++ b/src/app/api/assessments/send-invitation/route.ts
@@ -1,13 +1,8 @@
import { type NextRequest } from 'next/server';
-import { z } from 'zod';
import { handleError } from '@/lib/utils/errors.utils';
import { getSession } from '@/lib/utils/auth.utils';
import { assertRecruiterOrAbove } from '@/lib/utils/permissions.utils';
-import emailService from '@/lib/services/email.service';
-
-const sendAssessmentInvitationSchema = z.object({
- candidateId: z.string().cuid(),
-});
+import AssessmentService from '@/lib/services/assessment.service';
export async function POST(request: NextRequest) {
try {
@@ -15,19 +10,14 @@ export async function POST(request: NextRequest) {
await assertRecruiterOrAbove(request.headers);
const body = await request.json();
- const { candidateId } = sendAssessmentInvitationSchema.parse(body);
+ const { positionId } = body as { positionId: string };
- const result = await emailService.sendAssessmentInvitationEmail(
- candidateId,
+ const result = await AssessmentService.sendAssessmentInvitationsToPosition(
+ positionId,
session.activeOrganizationId
);
- return Response.json(
- {
- data: result,
- },
- { status: 200 }
- );
+ return Response.json({ data: result }, { status: 200 });
} catch (err) {
return handleError(err);
}
diff --git a/src/lib/api/assessments.ts b/src/lib/api/assessments.ts
index 2e73f4b0..b2959c33 100644
--- a/src/lib/api/assessments.ts
+++ b/src/lib/api/assessments.ts
@@ -1,7 +1,10 @@
import { type Application } from '@/generated/prisma';
import { type AssessmentStatus } from '@/generated/prisma';
import { type Assessment, type UpdateAssessmentDTO } from '@/lib/schemas/assessment.schema';
-import { type AssessmentWithRelations } from '@/lib/types/assessment-template.types';
+import {
+ type AssessmentWithRelations,
+ type AssessmentInvitationResult,
+} from '@/lib/types/assessment-template.types';
/**
* GET /api/assessments/:assessmentId
@@ -67,27 +70,23 @@ export async function updateAssessmentStatus(
/**
* POST /api/assessments/send-invitation
- * Sends an assessment invitation email to a candidate
+ * Sends assessment invitation emails to all NOT_SENT candidates of a position
*/
-export async function sendAssessmentInvitation(candidateId: string): Promise<{
- success: boolean;
- message: string;
- candidateName: string;
- positionTitle: string;
- assessmentId: string;
-}> {
+export async function sendAssessmentInvitation(
+ positionId: string
+): Promise