Files
HealthLog/src/app/api/whoop/sync/route.ts
T
Marc-André Bombeck 008160dc72 feat(whoop): settings surface — status, disconnect, credentials, sync routes + connect card
Fill the WHOOP route set beside the OAuth connect/callback: status reports
connection + token expiry + backfill progress, disconnect revokes the stored
tokens and parks the integration, credentials saves/clears the per-user BYO
client id/secret encrypted at rest, sync triggers a manual incremental or full
pull. Add a WHOOP card to Settings -> Integrations mirroring the Withings card
(BYO-keys form, connect/disconnect, status pill, last-sync, backfill notice)
and surface whoop rows in the combined integrations-status envelope so the pill
reflects real failure state. WHOOP lives under the existing integrations
section -- no new slug.
2026-06-04 02:34:33 +02:00

28 lines
896 B
TypeScript

import { apiHandler, requireAuth } from "@/lib/api-handler";
import { apiSuccess } from "@/lib/api-response";
import { annotate } from "@/lib/logging/context";
import { syncUserWhoop } from "@/lib/whoop/sync";
import { NextRequest } from "next/server";
/**
* Manually trigger a WHOOP sync for the current user (v1.11.0).
*
* Mirrors the Withings manual-sync route: incremental by default, full
* history when `{ fullSync: true }` is posted.
*/
export const POST = apiHandler(async (request: NextRequest) => {
const { user } = await requireAuth();
annotate({ action: { name: "whoop.sync" } });
let fullSync = false;
try {
const body = await request.json();
fullSync = body?.fullSync === true;
} catch {
// no body provided -> default incremental sync
}
const imported = await syncUserWhoop(user.id, { fullSync });
return apiSuccess({ imported, fullSync });
});