fix: pref no connectDB

This commit is contained in:
Julien Froidefond
2025-03-05 08:23:41 +01:00
parent 1fc0f071ae
commit c148a4421c
2 changed files with 4 additions and 1 deletions

View File

@@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",

View File

@@ -5,6 +5,7 @@ import { AppError } from "../../utils/errors";
import type { UserPreferences } from "@/types/preferences";
import { defaultPreferences } from "@/types/preferences";
import type { User } from "@/types/komga";
import connectDB from "@/lib/mongodb";
export class PreferencesService {
static async getCurrentUser(): Promise<User> {
@@ -18,6 +19,7 @@ export class PreferencesService {
static async getPreferences(): Promise<UserPreferences> {
try {
const user = await this.getCurrentUser();
await connectDB();
const preferences = await PreferencesModel.findOne({ userId: user.id });
if (!preferences) {
return defaultPreferences;
@@ -37,6 +39,7 @@ export class PreferencesService {
static async updatePreferences(preferences: Partial<UserPreferences>): Promise<UserPreferences> {
try {
const user = await this.getCurrentUser();
await connectDB();
const updatedPreferences = await PreferencesModel.findOneAndUpdate(
{ userId: user.id },
{ $set: preferences },