fix: types of nj15

This commit is contained in:
Julien Froidefond
2025-03-02 14:40:15 +01:00
parent a4b521fe2e
commit e60b48d549
27 changed files with 133 additions and 100 deletions

View File

@@ -2,13 +2,13 @@ import { PreferencesModel } from "@/lib/models/preferences.model";
import { AuthServerService } from "./auth-server.service";
import { ERROR_CODES } from "../../constants/errorCodes";
import { AppError } from "../../utils/errors";
import type { UserPreferences} from "@/types/preferences";
import type { UserPreferences } from "@/types/preferences";
import { defaultPreferences } from "@/types/preferences";
import type { User } from "@/types/komga";
export class PreferencesService {
static getCurrentUser(): User {
const user = AuthServerService.getCurrentUser();
static async getCurrentUser(): Promise<User> {
const user = await AuthServerService.getCurrentUser();
if (!user) {
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
}
@@ -17,7 +17,7 @@ export class PreferencesService {
static async getPreferences(): Promise<UserPreferences> {
try {
const user = this.getCurrentUser();
const user = await this.getCurrentUser();
const preferences = await PreferencesModel.findOne({ userId: user.id });
if (!preferences) {
return defaultPreferences;
@@ -36,7 +36,7 @@ export class PreferencesService {
static async updatePreferences(preferences: Partial<UserPreferences>): Promise<UserPreferences> {
try {
const user = this.getCurrentUser();
const user = await this.getCurrentUser();
const updatedPreferences = await PreferencesModel.findOneAndUpdate(
{ userId: user.id },
{ $set: preferences },