mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 14:40:52 +00:00
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.
28 lines
896 B
TypeScript
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 });
|
|
});
|