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", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev --turbopack",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",

View File

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