feat: basic admin interface

This commit is contained in:
Zoe
2026-10-08 13:41:02 -05:00
parent 7b0800882a
commit f6e1bc1f47
27 changed files with 4095 additions and 49 deletions
+43
View File
@@ -0,0 +1,43 @@
import * as z from 'zod';
import { INSTANCE_SETTINGS_ID, REGISTRATION_MODES, instanceSettings } from '~~/drizzle/schema';
import { db } from '~~/server/lib/db';
export default defineEventHandler(async (event) => {
await protectAdminRoute(event);
const result = await readValidatedBody(event, (body) =>
z
.object({
registration: z.enum(REGISTRATION_MODES),
})
.safeParse(body),
);
if (!result.success) {
throw createError({
statusCode: 400,
message: result.error.issues[0]!.message,
});
}
if (isRegistrationLocked()) {
throw createError({
statusCode: 409,
statusMessage: 'Registration is locked by the environment',
data: {
code: 'REGISTRATION_LOCKED',
},
});
}
const { registration } = result.data;
await db.insert(instanceSettings)
.values({ id: INSTANCE_SETTINGS_ID, registration })
.onConflictDoUpdate({
target: instanceSettings.id,
set: { registration, updatedAt: new Date() },
});
return { registration, registrationLocked: false };
});