Add all REST API endpoints for mobile app consumption: Routes: - GET /api/v1/routes — paginated list with cursor, Zod validation - GET /api/v1/routes/:id — full detail with GPX, versions - POST /api/v1/routes — create with Zod-validated body - PUT /api/v1/routes/:id — update, creates new version - DELETE /api/v1/routes/:id — returns 204 Activities: - GET /api/v1/activities — paginated list with cursor - GET /api/v1/activities/:id — full detail - POST /api/v1/activities — create with GPX stat extraction - DELETE /api/v1/activities/:id — returns 204 Supporting: - POST /api/v1/routes/compute — BRouter proxy - POST /api/v1/uploads — presigned upload URL generation Device management: - GET /api/v1/auth/devices — list connected devices with isCurrent - DELETE /api/v1/auth/devices/:id — revoke device token - Store device_name on token exchange Infrastructure: - requireApiUser() guard — returns 401 with structured error - apiError() helper for consistent error responses - All endpoints use Zod schemas from @trails-cool/api for validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { Route } from "./+types/api.v1.auth.devices.$id";
|
|
import { requireApiUser, apiError } from "~/lib/api-guard.server";
|
|
import { eq, and, isNull } from "drizzle-orm";
|
|
import { getDb } from "~/lib/db";
|
|
import { oauthTokens } from "@trails-cool/db/schema/journal";
|
|
import { ERROR_CODES } from "@trails-cool/api";
|
|
|
|
/** DELETE /api/v1/auth/devices/:id — revoke a device token */
|
|
export async function action({ request, params }: Route.ActionArgs) {
|
|
if (request.method !== "DELETE") return new Response(null, { status: 405 });
|
|
const user = await requireApiUser(request);
|
|
const db = getDb();
|
|
|
|
const [token] = await db
|
|
.select({ id: oauthTokens.id })
|
|
.from(oauthTokens)
|
|
.where(
|
|
and(
|
|
eq(oauthTokens.id, params.id),
|
|
eq(oauthTokens.userId, user.id),
|
|
isNull(oauthTokens.revokedAt),
|
|
),
|
|
);
|
|
|
|
if (!token) {
|
|
return apiError(404, ERROR_CODES.NOT_FOUND, "Device not found");
|
|
}
|
|
|
|
await db
|
|
.update(oauthTokens)
|
|
.set({ revokedAt: new Date() })
|
|
.where(eq(oauthTokens.id, params.id));
|
|
|
|
return new Response(null, { status: 204 });
|
|
}
|