managarten/apps/todo/apps/server-archived/src/routes/admin.ts
Till JS 3556fc18be chore: archive 17 standalone app servers (replaced by unified API)
All app compute servers have been consolidated into apps/api/ (unified
Hono/Bun server). Old servers moved to apps/*/apps/server-archived/.

Archived: cards, chat, contacts, context, calendar, guides, moodlit,
mukke, news, nutriphi, picture, planta, presi, questions, storage, todo, traces

Still active: uload (separate domain), memoro (Supabase-based)

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

57 lines
1.5 KiB
TypeScript

/**
* Admin route — GDPR compliance + user data aggregation.
* Called by mana-core-auth, protected by service key.
*/
import { Hono } from 'hono';
import { eq, sql } from 'drizzle-orm';
import { serviceAuthMiddleware } from '@manacore/shared-hono';
import { db, tasks, projects, reminders } from '../db';
const adminRoutes = new Hono();
adminRoutes.use('/*', serviceAuthMiddleware());
/** Get user data counts. */
adminRoutes.get('/user-data/:userId', async (c) => {
const userId = c.req.param('userId');
const [taskCount] = await db
.select({ count: sql<number>`count(*)` })
.from(tasks)
.where(eq(tasks.userId, userId));
const [projectCount] = await db
.select({ count: sql<number>`count(*)` })
.from(projects)
.where(eq(projects.userId, userId));
const [reminderCount] = await db
.select({ count: sql<number>`count(*)` })
.from(reminders)
.where(eq(reminders.userId, userId));
return c.json({
userId,
counts: {
tasks: Number(taskCount?.count ?? 0),
projects: Number(projectCount?.count ?? 0),
reminders: Number(reminderCount?.count ?? 0),
},
});
});
/** Delete all user data (GDPR right to be forgotten). */
adminRoutes.delete('/user-data/:userId', async (c) => {
const userId = c.req.param('userId');
await db.delete(reminders).where(eq(reminders.userId, userId));
await db.delete(tasks).where(eq(tasks.userId, userId));
await db.delete(projects).where(eq(projects.userId, userId));
return c.json({
userId,
deleted: true,
message: 'All user data deleted',
});
});
export { adminRoutes };