File size: 816 Bytes
82fcab7
 
 
 
 
 
 
da7f5d6
 
 
82fcab7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { invalidate } from "$app/navigation";
import { base } from "$app/paths";
import { error } from "$lib/stores/errors";
import type { Settings } from "./types/Settings";
import { UrlDependency } from "./types/UrlDependency";

export async function updateSettings(
	settings: Partial<
		Omit<Settings, "sessionId" | "ethicsModalAcceptedAt"> & { ethicsModalAccepted?: boolean }
	>
): Promise<boolean> {
	try {
		const res = await fetch(`${base}/settings`, {
			method: "PATCH",
			headers: { "Content-Type": "application/json" },
			body: JSON.stringify(settings),
		});
		if (!res.ok) {
			error.set("Error while updating settings, try again.");
			return false;
		}
		await invalidate(UrlDependency.Settings);
		return true;
	} catch (err) {
		console.error(err);
		error.set(String(err));
		return false;
	}
}