create-crm-tmp 1.1.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create-crm-tmp.js +56 -35
- package/package.json +1 -1
- package/template/.prettierignore +2 -0
- package/template/README.md +230 -115
- package/template/components.json +22 -0
- package/template/eslint.config.mjs +13 -0
- package/template/exemple-contacts.csv +54 -0
- package/template/next.config.ts +41 -1
- package/template/package.json +63 -15
- package/template/prisma/migrations/20260318095700_init_db/migration.sql +978 -0
- package/template/prisma/schema.prisma +311 -67
- package/template/src/app/(auth)/invite/[token]/page.tsx +28 -29
- package/template/src/app/(auth)/layout.tsx +1 -1
- package/template/src/app/(auth)/reset-password/complete/page.tsx +21 -27
- package/template/src/app/(auth)/reset-password/page.tsx +14 -10
- package/template/src/app/(auth)/reset-password/verify/page.tsx +14 -10
- package/template/src/app/(auth)/signin/page.tsx +34 -23
- package/template/src/app/(dashboard)/agenda/page.tsx +3655 -2357
- package/template/src/app/(dashboard)/automatisation/[id]/page.tsx +10 -7
- package/template/src/app/(dashboard)/automatisation/_components/workflow-editor.tsx +609 -338
- package/template/src/app/(dashboard)/automatisation/new/page.tsx +11 -8
- package/template/src/app/(dashboard)/automatisation/page.tsx +463 -186
- package/template/src/app/(dashboard)/closing/page.tsx +517 -469
- package/template/src/app/(dashboard)/contacts/[id]/page.tsx +6151 -4210
- package/template/src/app/(dashboard)/contacts/companies/[id]/page.tsx +1702 -0
- package/template/src/app/(dashboard)/contacts/loading.tsx +13 -0
- package/template/src/app/(dashboard)/contacts/page.tsx +4124 -2130
- package/template/src/app/(dashboard)/dashboard/page.tsx +119 -105
- package/template/src/app/(dashboard)/dev/page.tsx +1291 -0
- package/template/src/app/(dashboard)/error.tsx +37 -0
- package/template/src/app/(dashboard)/layout.tsx +6 -2
- package/template/src/app/(dashboard)/loading.tsx +5 -0
- package/template/src/app/(dashboard)/settings/loading.tsx +19 -0
- package/template/src/app/(dashboard)/settings/page.tsx +1773 -3362
- package/template/src/app/(dashboard)/templates/page.tsx +504 -303
- package/template/src/app/(dashboard)/users/list/page.tsx +364 -355
- package/template/src/app/(dashboard)/users/page.tsx +279 -310
- package/template/src/app/(dashboard)/users/permissions/page.tsx +104 -99
- package/template/src/app/(dashboard)/users/roles/page.tsx +169 -140
- package/template/src/app/api/agenda/google-events/route.ts +92 -0
- package/template/src/app/api/audit-logs/route.ts +1 -1
- package/template/src/app/api/auth/check-active/route.ts +3 -2
- package/template/src/app/api/auth/google/callback/route.ts +8 -5
- package/template/src/app/api/auth/google/disconnect/route.ts +2 -2
- package/template/src/app/api/auth/google/route.ts +2 -1
- package/template/src/app/api/auth/google/status/route.ts +7 -31
- package/template/src/app/api/companies/[id]/activities/route.ts +129 -0
- package/template/src/app/api/companies/[id]/route.ts +194 -0
- package/template/src/app/api/companies/export/route.ts +206 -0
- package/template/src/app/api/companies/route.ts +196 -0
- package/template/src/app/api/contact-views/[id]/pin/route.ts +69 -0
- package/template/src/app/api/contact-views/[id]/route.ts +197 -0
- package/template/src/app/api/contact-views/route.ts +146 -0
- package/template/src/app/api/contacts/[id]/files/[fileId]/preview/route.ts +55 -0
- package/template/src/app/api/contacts/[id]/files/[fileId]/route.ts +20 -48
- package/template/src/app/api/contacts/[id]/files/route.ts +125 -186
- package/template/src/app/api/contacts/[id]/interactions/[interactionId]/route.ts +27 -1
- package/template/src/app/api/contacts/[id]/interactions/route.ts +45 -8
- package/template/src/app/api/contacts/[id]/kyc/route.ts +81 -0
- package/template/src/app/api/contacts/[id]/meet/route.ts +55 -29
- package/template/src/app/api/contacts/[id]/route.ts +184 -21
- package/template/src/app/api/contacts/[id]/send-email/route.ts +33 -11
- package/template/src/app/api/contacts/[id]/workflows/run/route.ts +67 -0
- package/template/src/app/api/contacts/export/route.ts +22 -31
- package/template/src/app/api/contacts/import/route.ts +77 -44
- package/template/src/app/api/contacts/import-preview/route.ts +139 -0
- package/template/src/app/api/contacts/origins/route.ts +63 -0
- package/template/src/app/api/contacts/route.ts +322 -57
- package/template/src/app/api/cron/cleanup-editor-images/route.ts +166 -0
- package/template/src/app/api/dashboard/stats/route.ts +9 -292
- package/template/src/app/api/dashboard/widgets/[id]/route.ts +0 -3
- package/template/src/app/api/dashboard/widgets/route.ts +19 -19
- package/template/src/app/api/dev/reminders/test/route.ts +114 -0
- package/template/src/app/api/editor/upload-image/route.ts +61 -0
- package/template/src/app/api/integrations/google-sheet/jobs/[jobId]/route.ts +47 -0
- package/template/src/app/api/integrations/google-sheet/jobs/usage/route.ts +50 -0
- package/template/src/app/api/integrations/google-sheet/sync/route.ts +28 -542
- package/template/src/app/api/invite/complete/route.ts +20 -23
- package/template/src/app/api/jobs/google-sheet/process/route.ts +84 -0
- package/template/src/app/api/jobs/google-sheet/schedule/route.ts +50 -0
- package/template/src/app/api/reminders/clear/route.ts +120 -0
- package/template/src/app/api/reminders/clear/undo/route.ts +112 -0
- package/template/src/app/api/reminders/route.ts +165 -39
- package/template/src/app/api/reminders/state/route.ts +164 -0
- package/template/src/app/api/reset-password/complete/route.ts +11 -13
- package/template/src/app/api/reset-password/request/route.ts +1 -1
- package/template/src/app/api/reset-password/verify/route.ts +1 -1
- package/template/src/app/api/send/route.ts +25 -47
- package/template/src/app/api/settings/closing-reasons/[id]/route.ts +10 -21
- package/template/src/app/api/settings/closing-reasons/route.ts +10 -21
- package/template/src/app/api/settings/company/route.ts +19 -26
- package/template/src/app/api/settings/google-ads/[id]/route.ts +20 -23
- package/template/src/app/api/settings/google-ads/route.ts +34 -23
- package/template/src/app/api/settings/google-calendar/calendars/route.ts +97 -0
- package/template/src/app/api/settings/google-calendar/route.ts +124 -0
- package/template/src/app/api/settings/google-sheet/[id]/route.ts +48 -23
- package/template/src/app/api/settings/google-sheet/auto-map/route.ts +56 -32
- package/template/src/app/api/settings/google-sheet/preview/route.ts +110 -0
- package/template/src/app/api/settings/google-sheet/route.ts +34 -23
- package/template/src/app/api/settings/integrations/logs/route.ts +93 -0
- package/template/src/app/api/settings/integrations/notifications/route.ts +67 -0
- package/template/src/app/api/settings/meta-leads/[id]/route.ts +20 -24
- package/template/src/app/api/settings/meta-leads/route.ts +34 -25
- package/template/src/app/api/settings/smtp/route.ts +53 -6
- package/template/src/app/api/settings/statuses/[id]/route.ts +29 -32
- package/template/src/app/api/settings/statuses/route.ts +24 -22
- package/template/src/app/api/statuses/route.ts +2 -5
- package/template/src/app/api/tasks/[id]/attendees/route.ts +36 -13
- package/template/src/app/api/tasks/[id]/route.ts +357 -145
- package/template/src/app/api/tasks/meet/route.ts +37 -26
- package/template/src/app/api/tasks/route.ts +201 -96
- package/template/src/app/api/templates/[id]/route.ts +22 -13
- package/template/src/app/api/templates/route.ts +22 -5
- package/template/src/app/api/users/[id]/resend-invite/route.ts +95 -0
- package/template/src/app/api/users/[id]/route.ts +22 -16
- package/template/src/app/api/users/commercials/route.ts +38 -0
- package/template/src/app/api/users/for-agenda/route.ts +1 -2
- package/template/src/app/api/users/list/route.ts +57 -19
- package/template/src/app/api/users/route.ts +89 -34
- package/template/src/app/api/webhooks/google-ads/route.ts +40 -1
- package/template/src/app/api/webhooks/meta-leads/route.ts +38 -1
- package/template/src/app/api/workflows/[id]/route.ts +29 -6
- package/template/src/app/api/workflows/process/route.ts +505 -170
- package/template/src/app/api/workflows/route.ts +42 -4
- package/template/src/app/globals.css +512 -32
- package/template/src/app/layout.tsx +28 -9
- package/template/src/app/page.tsx +37 -7
- package/template/src/components/address-autocomplete.tsx +233 -0
- package/template/src/components/config-error-alert.tsx +46 -0
- package/template/src/components/contacts/filter-bar.tsx +190 -0
- package/template/src/components/contacts/filter-builder.tsx +574 -0
- package/template/src/components/contacts/save-view-dialog.tsx +160 -0
- package/template/src/components/contacts/views-tab-bar.tsx +449 -0
- package/template/src/components/dashboard/activity-chart.tsx +6 -1
- package/template/src/components/dashboard/add-widget-dialog.tsx +13 -17
- package/template/src/components/dashboard/color-picker.tsx +7 -8
- package/template/src/components/dashboard/recent-activity.tsx +2 -5
- package/template/src/components/dashboard/stat-card.tsx +1 -3
- package/template/src/components/dashboard/status-distribution-chart.tsx +0 -1
- package/template/src/components/dashboard/top-contacts-list.tsx +7 -13
- package/template/src/components/dashboard/upcoming-tasks-list.tsx +2 -5
- package/template/src/components/dashboard/widget-wrapper.tsx +3 -6
- package/template/src/components/date-picker.tsx +399 -0
- package/template/src/components/editor/upload-editor-image.ts +42 -0
- package/template/src/components/editor.tsx +188 -35
- package/template/src/components/email-template.tsx +4 -2
- package/template/src/components/global-search.tsx +360 -0
- package/template/src/components/header.tsx +200 -107
- package/template/src/components/inactive-account-guard.tsx +58 -0
- package/template/src/components/integration-notifications-listener.tsx +12 -0
- package/template/src/components/invitation-email-template.tsx +4 -2
- package/template/src/components/lazy-editor.tsx +11 -0
- package/template/src/components/meet-cancellation-email-template.tsx +11 -3
- package/template/src/components/meet-confirmation-email-template.tsx +10 -3
- package/template/src/components/meet-update-email-template.tsx +10 -3
- package/template/src/components/page-header.tsx +19 -15
- package/template/src/components/protected-page.tsx +94 -0
- package/template/src/components/reset-password-email-template.tsx +4 -2
- package/template/src/components/settings/integrations/GoogleAdsIntegration.tsx +428 -0
- package/template/src/components/settings/integrations/GoogleSheetConfigMonitoringModal.tsx +680 -0
- package/template/src/components/settings/integrations/GoogleSheetIntegration.tsx +809 -0
- package/template/src/components/settings/integrations/ImportResultDialog.tsx +124 -0
- package/template/src/components/settings/integrations/IntegrationLogPanel.tsx +57 -0
- package/template/src/components/settings/integrations/IntegrationLogsTable.tsx +186 -0
- package/template/src/components/settings/integrations/MetaLeadIntegration.tsx +451 -0
- package/template/src/components/sidebar.tsx +117 -100
- package/template/src/components/skeleton.tsx +128 -45
- package/template/src/components/ui/accordion.tsx +64 -0
- package/template/src/components/ui/alert-dialog.tsx +139 -0
- package/template/src/components/ui/button.tsx +71 -0
- package/template/src/components/ui/components.tsx +1 -1
- package/template/src/components/ui/date-picker.tsx +422 -0
- package/template/src/components/ui/datetime-picker.tsx +338 -0
- package/template/src/components/ui/status-select.tsx +271 -0
- package/template/src/components/ui/tooltip.tsx +37 -0
- package/template/src/components/view-as-banner.tsx +1 -1
- package/template/src/components/view-as-modal.tsx +30 -19
- package/template/src/config/nav-pages.ts +108 -0
- package/template/src/contexts/app-toast-context.tsx +362 -0
- package/template/src/contexts/dashboard-theme-context.tsx +2 -7
- package/template/src/contexts/sidebar-context.tsx +27 -53
- package/template/src/contexts/task-reminder-context.tsx +134 -160
- package/template/src/contexts/view-as-context.tsx +32 -10
- package/template/src/hooks/use-alert.tsx +65 -0
- package/template/src/hooks/use-confirm.tsx +87 -0
- package/template/src/hooks/use-contact-views.ts +140 -0
- package/template/src/hooks/use-contacts.ts +69 -0
- package/template/src/hooks/use-fetch.ts +17 -0
- package/template/src/hooks/use-focus-trap.ts +73 -0
- package/template/src/hooks/use-statuses.ts +22 -0
- package/template/src/hooks/useIntegrationNotifications.ts +49 -0
- package/template/src/lib/address-api.ts +155 -0
- package/template/src/lib/auth.ts +8 -1
- package/template/src/lib/cache.ts +73 -0
- package/template/src/lib/check-permission.ts +12 -177
- package/template/src/lib/config-links.ts +14 -0
- package/template/src/lib/contact-duplicate.ts +79 -61
- package/template/src/lib/contact-interactions.ts +24 -22
- package/template/src/lib/contact-view-filters.ts +301 -0
- package/template/src/lib/contacts-list-url.ts +190 -0
- package/template/src/lib/dashboard-stats.ts +282 -0
- package/template/src/lib/dashboard-themes.ts +0 -5
- package/template/src/lib/date-utils.ts +176 -0
- package/template/src/lib/default-widgets.ts +0 -2
- package/template/src/lib/editor-html-image-dimensions.ts +172 -0
- package/template/src/lib/editor-image-limits.ts +19 -0
- package/template/src/lib/email-html-sanitize.ts +19 -0
- package/template/src/lib/encryption.ts +9 -6
- package/template/src/lib/fr-geography.ts +192 -0
- package/template/src/lib/get-auth-user.ts +25 -0
- package/template/src/lib/google-calendar-agenda.ts +201 -0
- package/template/src/lib/google-calendar.ts +309 -17
- package/template/src/lib/google-fetch.ts +63 -0
- package/template/src/lib/google-sheet-sync-jobs.ts +96 -0
- package/template/src/lib/google-sheet-sync-runner.ts +514 -0
- package/template/src/lib/integration-import-log.ts +21 -0
- package/template/src/lib/local-storage.ts +34 -0
- package/template/src/lib/permissions.ts +268 -40
- package/template/src/lib/prisma.ts +15 -12
- package/template/src/lib/qstash.ts +65 -0
- package/template/src/lib/reminder-state-server.ts +80 -0
- package/template/src/lib/reminder-state.ts +29 -0
- package/template/src/lib/roles.ts +12 -15
- package/template/src/lib/supabase-storage.ts +113 -0
- package/template/src/lib/template-variables.ts +204 -29
- package/template/src/lib/utils.ts +71 -11
- package/template/src/lib/widget-registry.ts +0 -4
- package/template/src/lib/workflow-executor.ts +391 -228
- package/template/src/proxy.ts +35 -73
- package/template/src/types/contact-views.ts +351 -0
- package/template/vercel.json +5 -0
- package/template/WORKFLOWS_CRON.md +0 -185
- package/template/prisma/migrations/20251126144728_init/migration.sql +0 -78
- package/template/prisma/migrations/20251126155204_add_user_roles/migration.sql +0 -5
- package/template/prisma/migrations/20251128095126_add_company_info/migration.sql +0 -19
- package/template/prisma/migrations/20251128123321_add_smtp_config/migration.sql +0 -22
- package/template/prisma/migrations/20251128132303_add_status/migration.sql +0 -23
- package/template/prisma/migrations/20251201102207_add_user_active/migration.sql +0 -75
- package/template/prisma/migrations/20251201105507_add_email_signature/migration.sql +0 -2
- package/template/prisma/migrations/20251201151122_add_tasks/migration.sql +0 -45
- package/template/prisma/migrations/20251202111854_add_task_reminder/migration.sql +0 -2
- package/template/prisma/migrations/20251202135859_add_google_meet_integration/migration.sql +0 -27
- package/template/prisma/migrations/20251203103317_add_meta_lead_integration/migration.sql +0 -20
- package/template/prisma/migrations/20251203104002_add_google_ads_integration/migration.sql +0 -18
- package/template/prisma/migrations/20251203112122_add_google_sheet_integration/migration.sql +0 -32
- package/template/prisma/migrations/20251203153853_allow_multiple_integration_configs/migration.sql +0 -20
- package/template/prisma/migrations/20251205141705_update_user_roles/migration.sql +0 -12
- package/template/prisma/migrations/20251205150000_add_commercial_and_telepro_assignment/migration.sql +0 -21
- package/template/prisma/migrations/20251205160000_add_interaction_logging/migration.sql +0 -11
- package/template/prisma/migrations/20251208090314_add_automatic_interaction_types/migration.sql +0 -12
- package/template/prisma/migrations/20251208094843_mg/migration.sql +0 -14
- package/template/prisma/migrations/20251208100000_add_company_support/migration.sql +0 -14
- package/template/prisma/migrations/20251208110000_add_templates/migration.sql +0 -26
- package/template/prisma/migrations/20251208141304_add_video_conference_task_type/migration.sql +0 -2
- package/template/prisma/migrations/20251209104759_add_internal_note_to_task/migration.sql +0 -2
- package/template/prisma/migrations/20251209134803_add_company_field/migration.sql +0 -2
- package/template/prisma/migrations/20251209150000_rename_company_to_company_name/migration.sql +0 -3
- package/template/prisma/migrations/20251209150016_add_email_tracking/migration.sql +0 -21
- package/template/prisma/migrations/20251209155908_add_notify_contact_to_task/migration.sql +0 -2
- package/template/prisma/migrations/20251210110019_add_appointment_types/migration.sql +0 -10
- package/template/prisma/migrations/20251210113928_add_contact_files/migration.sql +0 -26
- package/template/prisma/migrations/20251212132339_add_custom_roles/migration.sql +0 -24
- package/template/prisma/migrations/20251215104448_add_file_interaction_types/migration.sql +0 -11
- package/template/prisma/migrations/20251215145616_add_closing_reasons/migration.sql +0 -12
- package/template/prisma/migrations/20251216140850_add_log_users/migration.sql +0 -25
- package/template/prisma/migrations/20251216151000_rename_perdu_to_ferme/migration.sql +0 -8
- package/template/prisma/migrations/20251216162318_add_column_mappings_to_google_sheet/migration.sql +0 -2
- package/template/prisma/migrations/20251216185127_add_workflows/migration.sql +0 -80
- package/template/prisma/migrations/20251216192237_add_scheduled_workflow_actions/migration.sql +0 -32
- package/template/prisma/migrations/20251220000000_add_task_interaction_type/migration.sql +0 -4
- package/template/prisma/migrations/20251221000000_add_task_type/migration.sql +0 -3
- package/template/prisma/migrations/20251221000001_add_event_color/migration.sql +0 -23
- package/template/prisma/migrations/20260210114913_add_dashboard_widget/migration.sql +0 -20
- package/template/prisma/migrations/20260226093949_fix_cascade_on_user_delete/migration.sql +0 -69
- package/template/src/app/(dashboard)/users/layout.tsx +0 -30
- package/template/src/lib/google-drive.ts +0 -380
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { prisma } from '@/lib/prisma';
|
|
3
|
+
import { runGoogleSheetSync } from '@/lib/google-sheet-sync-runner';
|
|
4
|
+
import { QstashAuthError, verifyQstashRequest } from '@/lib/qstash';
|
|
5
|
+
|
|
6
|
+
export async function POST(request: NextRequest) {
|
|
7
|
+
let bodyText = '';
|
|
8
|
+
let parsedJobId: string | null = null;
|
|
9
|
+
try {
|
|
10
|
+
bodyText = await request.text();
|
|
11
|
+
const signature = request.headers.get('upstash-signature');
|
|
12
|
+
await verifyQstashRequest(signature, bodyText);
|
|
13
|
+
|
|
14
|
+
const body = JSON.parse(bodyText) as { jobId?: string };
|
|
15
|
+
const jobId = body.jobId;
|
|
16
|
+
parsedJobId = jobId ?? null;
|
|
17
|
+
if (!jobId) {
|
|
18
|
+
return NextResponse.json({ error: 'jobId manquant' }, { status: 400 });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const claimed = await prisma.googleSheetSyncJob.updateMany({
|
|
22
|
+
where: {
|
|
23
|
+
id: jobId,
|
|
24
|
+
status: 'QUEUED',
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
status: 'RUNNING',
|
|
28
|
+
startedAt: new Date(),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (claimed.count === 0) {
|
|
33
|
+
return NextResponse.json({ ok: true, skipped: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const job = await prisma.googleSheetSyncJob.findUnique({
|
|
37
|
+
where: { id: jobId },
|
|
38
|
+
select: { requestedByUserId: true, configId: true },
|
|
39
|
+
});
|
|
40
|
+
if (!job) {
|
|
41
|
+
return NextResponse.json({ error: 'Job introuvable' }, { status: 404 });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const result = await runGoogleSheetSync({
|
|
45
|
+
sessionUserId: job.requestedByUserId,
|
|
46
|
+
requestedConfigId: job.configId ?? undefined,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await prisma.googleSheetSyncJob.update({
|
|
50
|
+
where: { id: jobId },
|
|
51
|
+
data: {
|
|
52
|
+
status: 'SUCCEEDED',
|
|
53
|
+
finishedAt: new Date(),
|
|
54
|
+
result: result as object,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return NextResponse.json({ ok: true });
|
|
59
|
+
} catch (error: any) {
|
|
60
|
+
if (error instanceof QstashAuthError) {
|
|
61
|
+
return NextResponse.json({ error: 'Signature QStash invalide' }, { status: 401 });
|
|
62
|
+
}
|
|
63
|
+
console.error('Erreur worker Google Sheet:', error);
|
|
64
|
+
try {
|
|
65
|
+
if (!parsedJobId && bodyText) {
|
|
66
|
+
const parsed = JSON.parse(bodyText) as { jobId?: string };
|
|
67
|
+
parsedJobId = parsed.jobId ?? null;
|
|
68
|
+
}
|
|
69
|
+
if (parsedJobId) {
|
|
70
|
+
await prisma.googleSheetSyncJob.update({
|
|
71
|
+
where: { id: parsedJobId },
|
|
72
|
+
data: {
|
|
73
|
+
status: 'FAILED',
|
|
74
|
+
finishedAt: new Date(),
|
|
75
|
+
error: error?.message || 'Erreur worker',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
// ignore
|
|
81
|
+
}
|
|
82
|
+
return NextResponse.json({ error: 'Erreur worker' }, { status: 500 });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { enqueueGoogleSheetSyncJob } from '@/lib/google-sheet-sync-jobs';
|
|
3
|
+
import { QstashAuthError, verifyQstashRequest } from '@/lib/qstash';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Déclenchement planifié de la synchro Google Sheets.
|
|
7
|
+
*
|
|
8
|
+
* - Planification : **Upstash QStash Schedule** en `POST` avec header `upstash-signature` (corps signé).
|
|
9
|
+
* - Optionnel : déclenchement manuel / secours avec `Authorization: Bearer <CRON_SECRET>` (`CRON_SECRET` sur l’hébergeur).
|
|
10
|
+
*/
|
|
11
|
+
export async function POST(request: NextRequest) {
|
|
12
|
+
try {
|
|
13
|
+
const cronSecret = process.env.CRON_SECRET;
|
|
14
|
+
const authHeader = request.headers.get('authorization');
|
|
15
|
+
const expectedBearer = cronSecret ? `Bearer ${cronSecret}` : null;
|
|
16
|
+
const isVercelCron =
|
|
17
|
+
Boolean(expectedBearer && authHeader === expectedBearer);
|
|
18
|
+
|
|
19
|
+
if (!isVercelCron) {
|
|
20
|
+
const signature = request.headers.get('upstash-signature');
|
|
21
|
+
if (signature) {
|
|
22
|
+
const body = await request.text();
|
|
23
|
+
await verifyQstashRequest(signature, body);
|
|
24
|
+
} else {
|
|
25
|
+
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const job = await enqueueGoogleSheetSyncJob({
|
|
30
|
+
requestedByUserId: null,
|
|
31
|
+
configId: null,
|
|
32
|
+
triggerType: 'SCHEDULED',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return NextResponse.json(
|
|
36
|
+
{
|
|
37
|
+
ok: true,
|
|
38
|
+
jobId: job.id,
|
|
39
|
+
status: job.status,
|
|
40
|
+
},
|
|
41
|
+
{ status: 202 },
|
|
42
|
+
);
|
|
43
|
+
} catch (error: any) {
|
|
44
|
+
if (error instanceof QstashAuthError) {
|
|
45
|
+
return NextResponse.json({ error: 'Signature QStash invalide' }, { status: 401 });
|
|
46
|
+
}
|
|
47
|
+
console.error('Erreur schedule Google Sheet:', error);
|
|
48
|
+
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { auth } from '@/lib/auth';
|
|
3
|
+
import { prisma, Prisma } from '@/lib/prisma';
|
|
4
|
+
import {
|
|
5
|
+
REMINDERS_CLEAR_ALL_ID,
|
|
6
|
+
REMINDERS_CLEAR_UNDO_WINDOW_MS,
|
|
7
|
+
} from '@/lib/reminder-state';
|
|
8
|
+
import {
|
|
9
|
+
computeExpiresAtForUpsert,
|
|
10
|
+
getRequestId,
|
|
11
|
+
isMissingReminderStateTableError,
|
|
12
|
+
logReminderEvent,
|
|
13
|
+
} from '@/lib/reminder-state-server';
|
|
14
|
+
|
|
15
|
+
export async function POST(request: NextRequest) {
|
|
16
|
+
const started = Date.now();
|
|
17
|
+
const requestId = getRequestId(request);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const session = await auth.api.getSession({ headers: request.headers });
|
|
21
|
+
if (!session) {
|
|
22
|
+
return NextResponse.json({ error: 'Non authentifié' }, { status: 401 });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const now = new Date();
|
|
26
|
+
const undoUntil = new Date(now.getTime() + REMINDERS_CLEAR_UNDO_WINDOW_MS);
|
|
27
|
+
const expiresAt = computeExpiresAtForUpsert(REMINDERS_CLEAR_ALL_ID, 'CLEARED', now);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const existing = await prisma.userReminderState.findUnique({
|
|
31
|
+
where: {
|
|
32
|
+
userId_reminderId: {
|
|
33
|
+
userId: session.user.id,
|
|
34
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
select: {
|
|
38
|
+
status: true,
|
|
39
|
+
clearedCutoffAt: true,
|
|
40
|
+
updatedAt: true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const previousClearedAt =
|
|
45
|
+
existing?.status === 'CLEARED'
|
|
46
|
+
? (existing.clearedCutoffAt ?? existing.updatedAt).toISOString()
|
|
47
|
+
: null;
|
|
48
|
+
|
|
49
|
+
const metadata: Prisma.InputJsonValue = {
|
|
50
|
+
undoUntil: undoUntil.toISOString(),
|
|
51
|
+
previousClearedAt,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const clearState = await prisma.userReminderState.upsert({
|
|
55
|
+
where: {
|
|
56
|
+
userId_reminderId: {
|
|
57
|
+
userId: session.user.id,
|
|
58
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
update: {
|
|
62
|
+
status: 'CLEARED',
|
|
63
|
+
clearedCutoffAt: now,
|
|
64
|
+
metadata,
|
|
65
|
+
expiresAt,
|
|
66
|
+
},
|
|
67
|
+
create: {
|
|
68
|
+
userId: session.user.id,
|
|
69
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
70
|
+
status: 'CLEARED',
|
|
71
|
+
clearedCutoffAt: now,
|
|
72
|
+
metadata,
|
|
73
|
+
expiresAt,
|
|
74
|
+
},
|
|
75
|
+
select: {
|
|
76
|
+
clearedCutoffAt: true,
|
|
77
|
+
updatedAt: true,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const clearedAt = (clearState.clearedCutoffAt ?? clearState.updatedAt).toISOString();
|
|
82
|
+
|
|
83
|
+
logReminderEvent({
|
|
84
|
+
event: 'reminders_clear_all',
|
|
85
|
+
requestId,
|
|
86
|
+
userId: session.user.id,
|
|
87
|
+
degraded: false,
|
|
88
|
+
durationMs: Date.now() - started,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return NextResponse.json({
|
|
92
|
+
success: true,
|
|
93
|
+
clearedAt,
|
|
94
|
+
undoUntil: undoUntil.toISOString(),
|
|
95
|
+
degraded: false,
|
|
96
|
+
});
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (isMissingReminderStateTableError(err)) {
|
|
99
|
+
logReminderEvent({
|
|
100
|
+
event: 'reminders_fallback_missing_table',
|
|
101
|
+
requestId,
|
|
102
|
+
userId: session.user.id,
|
|
103
|
+
degraded: true,
|
|
104
|
+
durationMs: Date.now() - started,
|
|
105
|
+
});
|
|
106
|
+
return NextResponse.json({
|
|
107
|
+
success: true,
|
|
108
|
+
clearedAt: now.toISOString(),
|
|
109
|
+
undoUntil: undoUntil.toISOString(),
|
|
110
|
+
degraded: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
} catch (error: unknown) {
|
|
116
|
+
const msg = error instanceof Error ? error.message : 'Erreur serveur';
|
|
117
|
+
console.error('Erreur lors du vidage des rappels:', error);
|
|
118
|
+
return NextResponse.json({ error: msg }, { status: 500 });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { auth } from '@/lib/auth';
|
|
3
|
+
import { prisma, Prisma } from '@/lib/prisma';
|
|
4
|
+
import { REMINDERS_CLEAR_ALL_ID } from '@/lib/reminder-state';
|
|
5
|
+
import {
|
|
6
|
+
computeExpiresAtForUpsert,
|
|
7
|
+
getRequestId,
|
|
8
|
+
isMissingReminderStateTableError,
|
|
9
|
+
logReminderEvent,
|
|
10
|
+
parseClearMetadata,
|
|
11
|
+
} from '@/lib/reminder-state-server';
|
|
12
|
+
|
|
13
|
+
export async function POST(request: NextRequest) {
|
|
14
|
+
const started = Date.now();
|
|
15
|
+
const requestId = getRequestId(request);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const session = await auth.api.getSession({ headers: request.headers });
|
|
19
|
+
if (!session) {
|
|
20
|
+
return NextResponse.json({ error: 'Non authentifié' }, { status: 401 });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const now = new Date();
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const row = await prisma.userReminderState.findUnique({
|
|
27
|
+
where: {
|
|
28
|
+
userId_reminderId: {
|
|
29
|
+
userId: session.user.id,
|
|
30
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
select: {
|
|
34
|
+
status: true,
|
|
35
|
+
reminderId: true,
|
|
36
|
+
metadata: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (!row || row.status !== 'CLEARED') {
|
|
41
|
+
return NextResponse.json({ error: 'Rien à annuler.' }, { status: 400 });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const meta = parseClearMetadata(row.metadata);
|
|
45
|
+
if (!meta || now.getTime() > new Date(meta.undoUntil).getTime()) {
|
|
46
|
+
logReminderEvent({
|
|
47
|
+
event: 'reminders_clear_undo',
|
|
48
|
+
requestId,
|
|
49
|
+
userId: session.user.id,
|
|
50
|
+
degraded: false,
|
|
51
|
+
durationMs: Date.now() - started,
|
|
52
|
+
extra: { rejected: true, reason: 'undo_expired' },
|
|
53
|
+
});
|
|
54
|
+
return NextResponse.json({ error: "Délai d'annulation dépassé." }, { status: 400 });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (meta.previousClearedAt === null) {
|
|
58
|
+
await prisma.userReminderState.delete({
|
|
59
|
+
where: {
|
|
60
|
+
userId_reminderId: {
|
|
61
|
+
userId: session.user.id,
|
|
62
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
const previous = new Date(meta.previousClearedAt);
|
|
68
|
+
const expiresAt = computeExpiresAtForUpsert(REMINDERS_CLEAR_ALL_ID, 'CLEARED', now);
|
|
69
|
+
await prisma.userReminderState.update({
|
|
70
|
+
where: {
|
|
71
|
+
userId_reminderId: {
|
|
72
|
+
userId: session.user.id,
|
|
73
|
+
reminderId: REMINDERS_CLEAR_ALL_ID,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
data: {
|
|
77
|
+
clearedCutoffAt: previous,
|
|
78
|
+
metadata: Prisma.JsonNull,
|
|
79
|
+
expiresAt,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
logReminderEvent({
|
|
85
|
+
event: 'reminders_clear_undo',
|
|
86
|
+
requestId,
|
|
87
|
+
userId: session.user.id,
|
|
88
|
+
degraded: false,
|
|
89
|
+
durationMs: Date.now() - started,
|
|
90
|
+
extra: { restoredPrevious: meta.previousClearedAt != null },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return NextResponse.json({ success: true, degraded: false });
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (isMissingReminderStateTableError(err)) {
|
|
96
|
+
logReminderEvent({
|
|
97
|
+
event: 'reminders_fallback_missing_table',
|
|
98
|
+
requestId,
|
|
99
|
+
userId: session.user.id,
|
|
100
|
+
degraded: true,
|
|
101
|
+
durationMs: Date.now() - started,
|
|
102
|
+
});
|
|
103
|
+
return NextResponse.json({ success: true, degraded: true });
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
} catch (error: unknown) {
|
|
108
|
+
const msg = error instanceof Error ? error.message : 'Erreur serveur';
|
|
109
|
+
console.error('Erreur lors de l’annulation du vidage des rappels:', error);
|
|
110
|
+
return NextResponse.json({ error: msg }, { status: 500 });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { auth } from '@/lib/auth';
|
|
3
3
|
import { prisma } from '@/lib/prisma';
|
|
4
|
+
import { REMINDERS_CLEAR_ALL_ID, REMINDER_READ_STATUSES } from '@/lib/reminder-state';
|
|
5
|
+
import {
|
|
6
|
+
getRequestId,
|
|
7
|
+
isMissingReminderStateTableError,
|
|
8
|
+
logReminderEvent,
|
|
9
|
+
reminderStateNotExpired,
|
|
10
|
+
} from '@/lib/reminder-state-server';
|
|
4
11
|
|
|
5
12
|
// GET /api/reminders - Récupérer tous les rappels de l'utilisateur
|
|
6
13
|
export async function GET(request: NextRequest) {
|
|
14
|
+
const started = Date.now();
|
|
15
|
+
const requestId = getRequestId(request);
|
|
16
|
+
let degraded = false;
|
|
17
|
+
|
|
7
18
|
try {
|
|
8
19
|
const session = await auth.api.getSession({
|
|
9
20
|
headers: request.headers,
|
|
@@ -14,20 +25,19 @@ export async function GET(request: NextRequest) {
|
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
const now = new Date();
|
|
17
|
-
const
|
|
18
|
-
|
|
28
|
+
const start = new Date(now);
|
|
29
|
+
start.setDate(start.getDate() - 7);
|
|
30
|
+
const end = new Date(now);
|
|
31
|
+
end.setDate(end.getDate() + 1);
|
|
19
32
|
|
|
20
|
-
// Récupérer
|
|
33
|
+
// Récupérer les tâches non complétées de l'utilisateur dans une fenêtre proche
|
|
21
34
|
const tasks = await prisma.task.findMany({
|
|
22
35
|
where: {
|
|
23
36
|
assignedUserId: session.user.id,
|
|
24
37
|
completed: false,
|
|
25
38
|
scheduledAt: {
|
|
26
|
-
gte:
|
|
27
|
-
lte:
|
|
28
|
-
},
|
|
29
|
-
reminderMinutesBefore: {
|
|
30
|
-
not: null,
|
|
39
|
+
gte: start,
|
|
40
|
+
lte: end,
|
|
31
41
|
},
|
|
32
42
|
},
|
|
33
43
|
include: {
|
|
@@ -51,47 +61,163 @@ export async function GET(request: NextRequest) {
|
|
|
51
61
|
orderBy: {
|
|
52
62
|
scheduledAt: 'asc',
|
|
53
63
|
},
|
|
64
|
+
take: 100,
|
|
54
65
|
});
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.filter((task) => {
|
|
59
|
-
if (!task.reminderMinutesBefore) return false;
|
|
67
|
+
const reminderCandidates = tasks
|
|
68
|
+
.flatMap((task) => {
|
|
60
69
|
const scheduled = new Date(task.scheduledAt);
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const entries: Array<{
|
|
71
|
+
id: string;
|
|
72
|
+
taskId: string;
|
|
73
|
+
kind: 'due' | 'reminder';
|
|
74
|
+
type: string;
|
|
75
|
+
title: string | null;
|
|
76
|
+
description: string;
|
|
77
|
+
priority: string;
|
|
78
|
+
scheduledAt: Date;
|
|
79
|
+
reminderTime: string;
|
|
80
|
+
reminderMinutesBefore: number | null;
|
|
81
|
+
contact: typeof task.contact;
|
|
82
|
+
assignedUser: typeof task.assignedUser;
|
|
83
|
+
}> = [];
|
|
84
|
+
|
|
85
|
+
const diffMs = now.getTime() - scheduled.getTime();
|
|
86
|
+
if (diffMs >= 0) {
|
|
87
|
+
entries.push({
|
|
88
|
+
id: `${task.id}-due`,
|
|
89
|
+
taskId: task.id,
|
|
90
|
+
kind: 'due',
|
|
91
|
+
type: task.type,
|
|
92
|
+
title: task.title,
|
|
93
|
+
description: task.description,
|
|
94
|
+
priority: task.priority,
|
|
95
|
+
scheduledAt: task.scheduledAt,
|
|
96
|
+
reminderTime: scheduled.toISOString(),
|
|
97
|
+
reminderMinutesBefore: task.reminderMinutesBefore,
|
|
98
|
+
contact: task.contact,
|
|
99
|
+
assignedUser: task.assignedUser,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (task.reminderMinutesBefore != null && task.reminderMinutesBefore > 0) {
|
|
104
|
+
const reminderTime = new Date(scheduled.getTime() - task.reminderMinutesBefore * 60 * 1000);
|
|
105
|
+
const diffReminderMs = now.getTime() - reminderTime.getTime();
|
|
106
|
+
if (diffReminderMs >= 0 && now < scheduled) {
|
|
107
|
+
entries.push({
|
|
108
|
+
id: `${task.id}-reminder`,
|
|
109
|
+
taskId: task.id,
|
|
110
|
+
kind: 'reminder',
|
|
111
|
+
type: task.type,
|
|
112
|
+
title: task.title,
|
|
113
|
+
description: task.description,
|
|
114
|
+
priority: task.priority,
|
|
115
|
+
scheduledAt: task.scheduledAt,
|
|
116
|
+
reminderTime: reminderTime.toISOString(),
|
|
117
|
+
reminderMinutesBefore: task.reminderMinutesBefore,
|
|
118
|
+
contact: task.contact,
|
|
119
|
+
assignedUser: task.assignedUser,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return entries;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const reminderIds = reminderCandidates.map((reminder) => reminder.id);
|
|
128
|
+
const countCandidates = reminderCandidates.length;
|
|
129
|
+
|
|
130
|
+
let reminderStates: Array<{
|
|
131
|
+
reminderId: string;
|
|
132
|
+
status: string;
|
|
133
|
+
updatedAt: Date;
|
|
134
|
+
clearedCutoffAt: Date | null;
|
|
135
|
+
}> = [];
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
reminderStates = await prisma.userReminderState.findMany({
|
|
139
|
+
where: {
|
|
140
|
+
userId: session.user.id,
|
|
141
|
+
AND: [
|
|
142
|
+
{
|
|
143
|
+
OR: [{ reminderId: { in: reminderIds } }, { reminderId: REMINDERS_CLEAR_ALL_ID }],
|
|
144
|
+
},
|
|
145
|
+
reminderStateNotExpired(now),
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
select: {
|
|
149
|
+
reminderId: true,
|
|
150
|
+
status: true,
|
|
151
|
+
updatedAt: true,
|
|
152
|
+
clearedCutoffAt: true,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (isMissingReminderStateTableError(err)) {
|
|
157
|
+
degraded = true;
|
|
158
|
+
logReminderEvent({
|
|
159
|
+
event: 'reminders_fallback_missing_table',
|
|
160
|
+
requestId,
|
|
161
|
+
userId: session.user.id,
|
|
162
|
+
degraded: true,
|
|
163
|
+
durationMs: Date.now() - started,
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const clearState = reminderStates.find(
|
|
171
|
+
(state) => state.reminderId === REMINDERS_CLEAR_ALL_ID && state.status === 'CLEARED',
|
|
172
|
+
);
|
|
173
|
+
const clearedAt = clearState
|
|
174
|
+
? (clearState.clearedCutoffAt ?? clearState.updatedAt)
|
|
175
|
+
: null;
|
|
176
|
+
const stateByReminderId = new Map(
|
|
177
|
+
reminderStates
|
|
178
|
+
.filter((state) => state.reminderId !== REMINDERS_CLEAR_ALL_ID)
|
|
179
|
+
.map((state) => [state.reminderId, state]),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const reminders = reminderCandidates
|
|
183
|
+
.filter((reminder) => {
|
|
184
|
+
if (!clearedAt) return true;
|
|
185
|
+
return new Date(reminder.reminderTime).getTime() > clearedAt.getTime();
|
|
69
186
|
})
|
|
70
|
-
.map((
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
187
|
+
.map((reminder) => {
|
|
188
|
+
const state = stateByReminderId.get(reminder.id);
|
|
189
|
+
const isRead = Boolean(state && REMINDER_READ_STATUSES.has(state.status as 'READ' | 'DISMISSED'));
|
|
190
|
+
const isDismissed = state?.status === 'DISMISSED';
|
|
191
|
+
const isClearedByCutoff = Boolean(
|
|
192
|
+
clearedAt && new Date(reminder.reminderTime).getTime() <= clearedAt.getTime(),
|
|
74
193
|
);
|
|
75
194
|
|
|
76
195
|
return {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
description: task.description,
|
|
82
|
-
priority: task.priority,
|
|
83
|
-
scheduledAt: task.scheduledAt,
|
|
84
|
-
reminderTime: reminderTime.toISOString(),
|
|
85
|
-
reminderMinutesBefore: task.reminderMinutesBefore,
|
|
86
|
-
contact: task.contact,
|
|
87
|
-
assignedUser: task.assignedUser,
|
|
196
|
+
...reminder,
|
|
197
|
+
isRead,
|
|
198
|
+
isDismissed,
|
|
199
|
+
isClearedByCutoff,
|
|
88
200
|
};
|
|
89
201
|
})
|
|
90
|
-
.sort((a, b) => new Date(
|
|
202
|
+
.sort((a, b) => new Date(b.reminderTime).getTime() - new Date(a.reminderTime).getTime());
|
|
203
|
+
|
|
204
|
+
logReminderEvent({
|
|
205
|
+
event: 'reminders_fetch',
|
|
206
|
+
requestId,
|
|
207
|
+
userId: session.user.id,
|
|
208
|
+
countCandidates,
|
|
209
|
+
countReturned: reminders.length,
|
|
210
|
+
degraded,
|
|
211
|
+
durationMs: Date.now() - started,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const headers: Record<string, string> = {};
|
|
215
|
+
if (degraded) headers['x-reminders-degraded'] = '1';
|
|
91
216
|
|
|
92
|
-
return NextResponse.json(reminders);
|
|
93
|
-
} catch (error:
|
|
217
|
+
return NextResponse.json(reminders, { headers });
|
|
218
|
+
} catch (error: unknown) {
|
|
219
|
+
const msg = error instanceof Error ? error.message : 'Erreur serveur';
|
|
94
220
|
console.error('Erreur lors de la récupération des rappels:', error);
|
|
95
|
-
return NextResponse.json({ error:
|
|
221
|
+
return NextResponse.json({ error: msg }, { status: 500 });
|
|
96
222
|
}
|
|
97
223
|
}
|