trails/apps/journal/app/routes/api.integrations.komoot.import.ts
Ullrich Schäfer 5fd60ba07d WIP: Komoot import integration
Add Komoot API client, import logic, crypto helpers, integration routes,
DB schema changes, and i18n strings for the Komoot import feature.

Import processing runs as a durable pg-boss background job with retries
instead of blocking the HTTP request.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 20:10:00 +02:00

45 lines
1.2 KiB
TypeScript

import { randomUUID } from "node:crypto";
import { data } from "react-router";
import { eq, and } from "drizzle-orm";
import type { Route } from "./+types/api.integrations.komoot.import";
import { getSessionUser } from "~/lib/auth.server";
import { getDb } from "~/lib/db";
import { syncConnections, importBatches } from "@trails-cool/db/schema/journal";
import { getBoss } from "~/lib/boss.server";
export async function action({ request }: Route.ActionArgs) {
const user = await getSessionUser(request);
if (!user) throw data(null, { status: 401 });
const db = getDb();
const [connection] = await db
.select()
.from(syncConnections)
.where(
and(
eq(syncConnections.userId, user.id),
eq(syncConnections.provider, "komoot"),
),
);
if (!connection?.encryptedCredentials) {
return data({ error: "Komoot not connected" }, { status: 400 });
}
const batchId = randomUUID();
await db.insert(importBatches).values({
id: batchId,
userId: user.id,
connectionId: connection.id,
status: "queued",
});
const boss = getBoss();
await boss.send("komoot-import", {
userId: user.id,
connectionId: connection.id,
batchId,
});
return data({ batchId });
}