fixes profile avatar upload

This commit is contained in:
Christian Beutel
2024-03-20 13:52:32 +01:00
parent 2732aaf9c1
commit 3e8fb85c05
3 changed files with 43 additions and 14 deletions

View File

@@ -0,0 +1,13 @@
import { pb } from "$lib/pocketbase";
import type { User } from "$lib/stores/user_store";
import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function POST(event: RequestEvent) {
const data = await event.request.formData()
try {
const r = await pb.collection("users").update<User>(event.params.id as string, data,);
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -60,7 +60,8 @@
async function handleSearchClick(item: SearchItem) {
citySearchQuery = item.text;
await users_update($currentUser!.id, {
await users_update({
id: $currentUser!.id,
location: {
name: item.value.name,
lat: item.value.lat,
@@ -74,25 +75,24 @@
document.getElementById("avatarInput") as HTMLInputElement
).files;
if (!files) {
if (!files || files.length == 0) {
return;
}
const formData = new FormData();
formData.append("avatar", files[0]);
await users_update($currentUser!.id, formData);
await users_update($currentUser!, files[0]);
}
async function handleUnitSelection(e: RadioItem) {
await users_update($currentUser!.id, {
await users_update({
id: $currentUser!.id,
unit: e.value as "imperial" | "metric",
});
}
async function handleLanguageSelection(value: "en" | "de") {
locale.set(value);
await users_update($currentUser!.id, {
await users_update({
id: $currentUser!.id,
language: value,
});
}