espace-paie-odentas/app/api/staff/organizations/emails/route.ts
odentas d7bdb1ef08 feat: Add notification tracking system with smart reminders
- Add database columns for last_employer_notification_at and last_employee_notification_at in cddu_contracts
- Update all email sending endpoints to record timestamps (remind-employer, relance-salarie, docuseal-signature, signature-salarie)
- Create smart reminder system with 24h cooldown to prevent spam
- Add progress tracking modal with real-time status (pending/sending/success/error)
- Display actual employer/employee email addresses in reminder modal
- Show notification timestamps in contracts grid with color coding (green/orange/red based on contract start date)
- Change employer email button URL from DocuSeal direct link to /signatures-electroniques
- Create /api/staff/organizations/emails endpoint for bulk email fetching
- Add retroactive migration script for historical email_logs data
- Update Contract TypeScript type and API responses to include new fields
2025-10-22 21:49:35 +02:00

47 lines
1.7 KiB
TypeScript

export const dynamic = 'force-dynamic';
export const revalidate = 0;
import { NextResponse } from "next/server";
import { createSbServer } from "@/lib/supabaseServer";
/**
* Récupère les emails de signature (employeur) pour plusieurs organisations
* POST /api/staff/organizations/emails
* Body: { org_ids: string[] }
*/
export async function POST(req: Request) {
try {
const sb = createSbServer();
// Vérification de l'authentification
const { data: { user } } = await sb.auth.getUser();
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
// Vérification des droits staff
const { data: me } = await sb.from("staff_users").select("is_staff").eq("user_id", user.id).maybeSingle();
if (!me?.is_staff) return NextResponse.json({ error: "Forbidden" }, { status: 403 });
const body = await req.json();
const orgIds = body.org_ids as string[];
if (!Array.isArray(orgIds) || orgIds.length === 0) {
return NextResponse.json({ error: "org_ids array required" }, { status: 400 });
}
// Récupérer les emails de signature pour toutes les organisations
const { data, error } = await sb
.from("organization_details")
.select("org_id, email_signature")
.in("org_id", orgIds);
if (error) {
console.error('Error fetching organization emails:', error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
return NextResponse.json(data || []);
} catch (err: any) {
console.error('Unexpected error in /api/staff/organizations/emails:', err);
return NextResponse.json({ error: err.message || "Internal Server Error" }, { status: 500 });
}
}