initial 2
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 09:26:50 +01:00
parent 194330fb47
commit 3b37368e7d
213 changed files with 14688 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
import { handleApi } from "@/lib/api";
import { requireUser, updateUserProfile } from "@/lib/services/user";
import { db, spiritualConfig } from "@/lib/db";
import { eq } from "drizzle-orm";
import { normalizeSettingsTheme } from "@/lib/services/theme-migration";
import { migrateUserThemeInDb } from "@/lib/services/theme-migration";
import { seedPromptTemplatesForUser } from "@/lib/services/ai-templates";
import { getSettingsForUser, upsertSetting } from "@/lib/repositories/settings.repository";
import { parseJsonBody, settingsPatchSchema } from "@/lib/validation";
export async function GET() {
return handleApi(async () => {
const { user } = await requireUser();
const allSettings = await getSettingsForUser(user.id);
const settingsMap = Object.fromEntries(allSettings.map((s) => [s.key, s.value]));
const migratedTheme = await migrateUserThemeInDb(
user.id,
settingsMap.theme as string | undefined
);
settingsMap.theme = migratedTheme;
const [spiritual] = await db
.select()
.from(spiritualConfig)
.where(eq(spiritualConfig.userId, user.id));
await seedPromptTemplatesForUser(user.id);
return {
user,
settings: normalizeSettingsTheme(settingsMap),
spiritual,
};
});
}
export async function PATCH(request: Request) {
return handleApi(async () => {
const body = await parseJsonBody(request, settingsPatchSchema);
const { user } = await requireUser();
if (body.profile) {
await updateUserProfile(user.id, body.profile);
}
if (body.settings) {
for (const [key, value] of Object.entries(body.settings)) {
await upsertSetting(user.id, key, value);
}
}
if (body.spiritual) {
await db
.update(spiritualConfig)
.set({
prayerLabels: body.spiritual.prayerLabels,
litanyLabels: body.spiritual.litanyLabels,
})
.where(eq(spiritualConfig.userId, user.id));
}
return { ok: true };
});
}