trail save fix
This commit is contained in:
14
web/src/routes/api/v1/integration/komoot/login/+server.ts
Normal file
14
web/src/routes/api/v1/integration/komoot/login/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { handleError } from "$lib/util/api_util";
|
||||
import { json } from "@sveltejs/kit";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const r = await pb.send("/integration/komoot/login", {
|
||||
method: "GET",
|
||||
});
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export async function POST(event: RequestEvent) {
|
||||
const r = await event.locals.ms.index(event.params.index as string).search(data.q, data.options);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
console.log(e);
|
||||
console.error(e);
|
||||
|
||||
throw error(e.httpStatus, e)
|
||||
}
|
||||
|
||||
@@ -16,17 +16,7 @@ export async function GET(event: RequestEvent) {
|
||||
}
|
||||
|
||||
// remove time from dates
|
||||
r.date = r.date?.substring(0, 10) ?? ""
|
||||
for (const log of r.expand?.summit_logs ?? []) {
|
||||
log.date = log.date.substring(0, 10)
|
||||
|
||||
if (!log.expand) {
|
||||
log.expand = {} as any
|
||||
}
|
||||
if (log.author) {
|
||||
log.expand!.author = await pb.collection("users_anonymous").getOne(log.author);
|
||||
}
|
||||
}
|
||||
await enrichRecord(r);
|
||||
|
||||
// sort waypoints by distance
|
||||
r.expand?.waypoints?.sort((a, b) => (a.distance_from_start ?? 0) - (b.distance_from_start ?? 0))
|
||||
@@ -36,10 +26,10 @@ export async function GET(event: RequestEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
try {
|
||||
const r = await update<Trail>(event, TrailUpdateSchema, Collection.trails)
|
||||
await enrichRecord(r)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw handleError(e)
|
||||
@@ -54,3 +44,19 @@ export async function DELETE(event: RequestEvent) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function enrichRecord(r: Trail) {
|
||||
r.date = r.date?.substring(0, 10) ?? "";
|
||||
for (const log of r.expand?.summit_logs ?? []) {
|
||||
log.date = log.date.substring(0, 10);
|
||||
|
||||
if (!log.expand) {
|
||||
log.expand = {} as any;
|
||||
}
|
||||
if (log.author) {
|
||||
log.expand!.author = await pb.collection("users_anonymous").getOne(log.author);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export async function PUT(event: RequestEvent) {
|
||||
const fileName = (data.get("name") as string | null)?.length ? data.get("name") as string : "file"
|
||||
log._gpx = new File([gpxFile], fileName);
|
||||
|
||||
trail.expand!.summit_logs.push(log);
|
||||
trail.expand!.summit_logs?.push(log);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import LogoTextTwoLineDark from "$lib/components/logo/logo_text_two_line_dark.svelte";
|
||||
import LogoTextTwoLineLight from "$lib/components/logo/logo_text_two_line_light.svelte";
|
||||
import { theme } from "$lib/stores/theme_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { users_confirm_reset } from "$lib/stores/user_store";
|
||||
import { validator } from "@felte/validator-zod";
|
||||
import { createForm } from "felte";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import LogoTextTwoLineDark from "$lib/components/logo/logo_text_two_line_dark.svelte";
|
||||
import LogoTextTwoLineLight from "$lib/components/logo/logo_text_two_line_light.svelte";
|
||||
import { theme } from "$lib/stores/theme_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { users_reset_password } from "$lib/stores/user_store";
|
||||
import { validator } from "@felte/validator-zod";
|
||||
import { createForm } from "felte";
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
import { TrailShare } from "$lib/models/trail_share.js";
|
||||
import { lists_create, lists_update } from "$lib/stores/list_store.js";
|
||||
import { theme } from "$lib/stores/theme_store.js";
|
||||
import { show_toast } from "$lib/stores/toast_store.js";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte.js";
|
||||
import {
|
||||
trail_share_create,
|
||||
trail_share_index,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import LogoTextTwoLineLight from "$lib/components/logo/logo_text_two_line_light.svelte";
|
||||
import type { User } from "$lib/models/user";
|
||||
import { theme } from "$lib/stores/theme_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { login } from "$lib/stores/user_store";
|
||||
import { APIError } from "$lib/util/api_util";
|
||||
import { validator } from "@felte/validator-zod";
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import LogoText from "$lib/components/logo/logo_text.svelte";
|
||||
import MapWithElevationMaplibre from "$lib/components/trail/map_with_elevation_maplibre.svelte";
|
||||
import type { Settings } from "$lib/models/settings";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { trail } from "$lib/stores/trail_store";
|
||||
import {
|
||||
formatDistance,
|
||||
|
||||
@@ -11,7 +11,7 @@ export const load: Load = async ({ params, fetch }) => {
|
||||
message: e.status == 404 ? 'Not found' : e.message
|
||||
});
|
||||
}
|
||||
console.log(e);
|
||||
console.error(e);
|
||||
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@
|
||||
import type { User } from "$lib/models/user";
|
||||
import { settings_update } from "$lib/stores/settings_store";
|
||||
import { theme } from "$lib/stores/theme_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { login, users_create } from "$lib/stores/user_store";
|
||||
import { validator } from "@felte/validator-zod";
|
||||
import { createForm } from "felte";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import ConfirmModal from "$lib/components/confirm_modal.svelte";
|
||||
import EmailModal from "$lib/components/settings/email_modal.svelte";
|
||||
import PasswordModal from "$lib/components/settings/password_modal.svelte";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import {
|
||||
currentUser,
|
||||
logout,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { } from "$lib/components/settings/upload_dialog.svelte";
|
||||
import TrailExportModal from "$lib/components/trail/trail_export_modal.svelte";
|
||||
import { theme } from "$lib/stores/theme_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte";
|
||||
import { fetchGPX, trails_index, trails_upload } from "$lib/stores/trail_store";
|
||||
import { processUploadQueue, uploadStore, type Upload } from "$lib/stores/upload_store.svelte";
|
||||
import { getFileURL, saveAs } from "$lib/util/file_util";
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
integrations_create,
|
||||
integrations_update,
|
||||
} from "$lib/stores/integration_store.js";
|
||||
import { show_toast } from "$lib/stores/toast_store.js";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte.js";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
let { data } = $props();
|
||||
@@ -102,9 +102,7 @@
|
||||
}
|
||||
|
||||
show_toast({
|
||||
text:
|
||||
"strava " +
|
||||
$_("integration-disabled"),
|
||||
text: "strava " + $_("integration-disabled"),
|
||||
icon: "check",
|
||||
type: "success",
|
||||
});
|
||||
@@ -117,9 +115,13 @@
|
||||
}
|
||||
if (value) {
|
||||
try {
|
||||
await pb.send("/integration/komoot/login", {
|
||||
const r = await fetch("/api/v1/integration/komoot/login", {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
if (!r.ok) {
|
||||
throw Error();
|
||||
}
|
||||
} catch (e) {
|
||||
komootToggleValue = false;
|
||||
show_toast({
|
||||
@@ -127,6 +129,7 @@
|
||||
icon: "close",
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
integration.komoot.active = true;
|
||||
} else {
|
||||
@@ -140,6 +143,7 @@
|
||||
icon: "close",
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
show_toast({
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import Textarea from "$lib/components/base/textarea.svelte";
|
||||
import type { Category } from "$lib/models/category.js";
|
||||
import { settings_update } from "$lib/stores/settings_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte.js";
|
||||
import { currentUser, users_update } from "$lib/stores/user_store";
|
||||
import { getFileURL } from "$lib/util/file_util";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
lists_remove_trail,
|
||||
} from "$lib/stores/list_store";
|
||||
import { summitLog } from "$lib/stores/summit_log_store";
|
||||
import { show_toast } from "$lib/stores/toast_store";
|
||||
import { show_toast } from "$lib/stores/toast_store.svelte.js";
|
||||
import {
|
||||
trail,
|
||||
trails_create,
|
||||
@@ -106,12 +106,12 @@
|
||||
expand: z
|
||||
.object({
|
||||
gpx_data: z.string().optional(),
|
||||
summit_logs: z.array(SummitLogCreateSchema),
|
||||
summit_logs: z.array(SummitLogCreateSchema).optional(),
|
||||
waypoints: z.array(
|
||||
WaypointCreateSchema.extend({
|
||||
marker: z.any().optional(),
|
||||
}),
|
||||
),
|
||||
).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
@@ -188,12 +188,13 @@
|
||||
);
|
||||
form.id = createdTrail.id;
|
||||
} else {
|
||||
await trails_update(
|
||||
const updatedTrail = await trails_update(
|
||||
$trail,
|
||||
form as Trail,
|
||||
photoFiles,
|
||||
gpxFile,
|
||||
);
|
||||
setFields(updatedTrail)
|
||||
}
|
||||
|
||||
listAddEnabled = true;
|
||||
@@ -294,7 +295,7 @@
|
||||
type: selectedFile.type,
|
||||
});
|
||||
|
||||
$formData.expand!.summit_logs.push(log);
|
||||
$formData.expand!.summit_logs?.push(log);
|
||||
|
||||
if (parseResult.gpx.rte?.length && !parseResult.gpx.trk) {
|
||||
parseResult.gpx.trk = [
|
||||
@@ -328,7 +329,7 @@
|
||||
}
|
||||
|
||||
function clearWaypoints() {
|
||||
for (const waypoint of $formData.expand!.waypoints) {
|
||||
for (const waypoint of $formData.expand!.waypoints ?? []) {
|
||||
waypoint.marker?.remove();
|
||||
}
|
||||
$formData.expand!.waypoints = [];
|
||||
@@ -395,23 +396,23 @@
|
||||
}
|
||||
|
||||
function deleteWaypoint(index: number) {
|
||||
$formData.expand!.waypoints.splice(index, 1);
|
||||
$formData.expand!.waypoints?.splice(index, 1);
|
||||
$formData.waypoints.splice(index, 1);
|
||||
$formData.expand!.waypoints = $formData.expand!.waypoints;
|
||||
// updateTrailOnMap();
|
||||
}
|
||||
|
||||
function saveWaypoint(savedWaypoint: Waypoint) {
|
||||
let editedWaypointIndex = $formData.expand!.waypoints.findIndex(
|
||||
let editedWaypointIndex = $formData.expand!.waypoints?.findIndex(
|
||||
(s) => s.id == savedWaypoint.id,
|
||||
);
|
||||
) ?? -1;
|
||||
|
||||
if (editedWaypointIndex >= 0) {
|
||||
$formData.expand!.waypoints[editedWaypointIndex] = savedWaypoint;
|
||||
$formData.expand!.waypoints![editedWaypointIndex] = savedWaypoint;
|
||||
} else {
|
||||
savedWaypoint.id = cryptoRandomString({ length: 15 });
|
||||
$formData.expand!.waypoints = [
|
||||
...$formData.expand!.waypoints,
|
||||
...$formData.expand!.waypoints ?? [],
|
||||
savedWaypoint,
|
||||
];
|
||||
|
||||
@@ -421,17 +422,17 @@
|
||||
|
||||
function moveMarker(marker: M.Marker, wpId?: string) {
|
||||
const position = marker.getLngLat();
|
||||
const editableWaypointIndex = $formData.expand!.waypoints.findIndex(
|
||||
const editableWaypointIndex = $formData.expand!.waypoints?.findIndex(
|
||||
(w) => w.id == wpId,
|
||||
);
|
||||
) ?? -1;
|
||||
const editableWaypoint =
|
||||
$formData.expand!.waypoints[editableWaypointIndex];
|
||||
$formData.expand!.waypoints![editableWaypointIndex];
|
||||
if (!editableWaypoint) {
|
||||
return;
|
||||
}
|
||||
editableWaypoint.lat = position.lat;
|
||||
editableWaypoint.lon = position.lng;
|
||||
$formData.expand!.waypoints = [...$formData.expand!.waypoints];
|
||||
$formData.expand!.waypoints = [...$formData.expand!.waypoints ?? []];
|
||||
// updateTrailOnMap();
|
||||
}
|
||||
|
||||
@@ -441,16 +442,16 @@
|
||||
}
|
||||
|
||||
function saveSummitLog(log: SummitLog) {
|
||||
let editedSummitLogIndex = $formData.expand!.summit_logs.findIndex(
|
||||
let editedSummitLogIndex = $formData.expand!.summit_logs?.findIndex(
|
||||
(s) => s.id == log.id,
|
||||
);
|
||||
|
||||
if (editedSummitLogIndex >= 0) {
|
||||
$formData.expand!.summit_logs[editedSummitLogIndex] = log;
|
||||
if (editedSummitLogIndex ?? 0 >= 0) {
|
||||
$formData.expand!.summit_logs![editedSummitLogIndex!] = log;
|
||||
} else {
|
||||
log.id = cryptoRandomString({ length: 15 });
|
||||
$formData.expand!.summit_logs = [
|
||||
...$formData.expand!.summit_logs,
|
||||
...$formData.expand!.summit_logs ?? [],
|
||||
log,
|
||||
];
|
||||
}
|
||||
@@ -465,7 +466,7 @@
|
||||
summitLog.set(currentSummitLog);
|
||||
summitLogModal.openModal();
|
||||
} else if (item.value === "delete") {
|
||||
$formData.expand!.summit_logs.splice(index, 1);
|
||||
$formData.expand!.summit_logs?.splice(index, 1);
|
||||
$formData.summit_logs.splice(index, 1);
|
||||
$formData.expand!.summit_logs = $formData.expand!.summit_logs;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export const load: Load = async ({ params, fetch }) => {
|
||||
message: e.status == 404 ? 'Not found' : e.message
|
||||
});
|
||||
}
|
||||
console.log(e);
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user