mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-21 14:06:42 +02:00
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>
57 lines
1.5 KiB
TypeScript
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 };
|