2026-04-27 11:40:38 +01:00
|
|
|
import { runComplianceExpiryCheck, runComplianceReminderScan } from '@api/services/course/compliance';
|
2026-05-18 03:47:22 +01:00
|
|
|
import { runProgramGoalEvaluationSweep, runProgramGoalReminderScan } from '@api/services/program/goal';
|
2026-04-27 11:40:38 +01:00
|
|
|
|
|
|
|
|
import { Hono } from '@api/utils/hono';
|
|
|
|
|
import { apiKeyMiddleware } from '@api/middlewares/api-key';
|
2026-06-22 05:43:48 +01:00
|
|
|
import { enqueueSessionReminderScan } from '@cio/jobs';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { handleError } from '@api/utils/errors';
|
|
|
|
|
|
|
|
|
|
export const internalComplianceRouter = new Hono()
|
2026-06-22 05:43:48 +01:00
|
|
|
.post('/send-session-reminders', apiKeyMiddleware, async (c) => {
|
|
|
|
|
try {
|
|
|
|
|
const jobId = await enqueueSessionReminderScan();
|
|
|
|
|
|
|
|
|
|
return c.json({ success: true, data: { jobId: jobId ?? null } }, 200);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return handleError(c, error, 'Failed to enqueue session reminder scan');
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-04-27 11:40:38 +01:00
|
|
|
.post('/check-expiry', apiKeyMiddleware, async (c) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await runComplianceExpiryCheck();
|
|
|
|
|
|
|
|
|
|
return c.json(
|
|
|
|
|
{
|
|
|
|
|
success: true,
|
|
|
|
|
data
|
|
|
|
|
},
|
|
|
|
|
200
|
|
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return handleError(c, error, 'Failed to run compliance expiry check');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.post('/send-reminders', apiKeyMiddleware, async (c) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await runComplianceReminderScan();
|
|
|
|
|
|
|
|
|
|
return c.json(
|
|
|
|
|
{
|
|
|
|
|
success: true,
|
|
|
|
|
data
|
|
|
|
|
},
|
|
|
|
|
200
|
|
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return handleError(c, error, 'Failed to run compliance reminder scan');
|
|
|
|
|
}
|
2026-05-18 03:47:22 +01:00
|
|
|
})
|
|
|
|
|
/**
|
|
|
|
|
* POST /internal/compliance/evaluate-program-goals
|
|
|
|
|
* Daily sweep: re-evaluate every active program goal and refresh per-learner
|
|
|
|
|
* `program_goal_assignment` rows.
|
|
|
|
|
*/
|
|
|
|
|
.post('/evaluate-program-goals', apiKeyMiddleware, async (c) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await runProgramGoalEvaluationSweep();
|
|
|
|
|
|
|
|
|
|
return c.json({ success: true, data }, 200);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return handleError(c, error, 'Failed to run program goal evaluation sweep');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
/**
|
|
|
|
|
* POST /internal/compliance/send-program-goal-reminders
|
|
|
|
|
* Sends learner reminder emails for upcoming/overdue program goals using
|
|
|
|
|
* each goal's `reminderDaysBefore` cadence.
|
|
|
|
|
*/
|
|
|
|
|
.post('/send-program-goal-reminders', apiKeyMiddleware, async (c) => {
|
|
|
|
|
try {
|
|
|
|
|
const data = await runProgramGoalReminderScan();
|
|
|
|
|
|
|
|
|
|
return c.json({ success: true, data }, 200);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return handleError(c, error, 'Failed to run program goal reminder scan');
|
|
|
|
|
}
|
2026-04-27 11:40:38 +01:00
|
|
|
});
|