bugfixing: pocketbase crash

This commit is contained in:
MuslemRahimi 2024-12-10 22:38:31 +01:00
parent c467f40592
commit 429f8cb676
3 changed files with 5 additions and 51 deletions

View File

@ -39,9 +39,10 @@ export const handle = sequence(async ({ event, resolve }) => {
try {
await event.locals.pb.collection("users").authRefresh();
event.locals.user = serializeNonPOJOs(event.locals.pb.authStore.model);
} catch (_) {
} catch (e) {
event.locals.pb.authStore.clear();
event.locals.user = undefined;
console.log(e)
}
}

View File

@ -6,9 +6,9 @@ export const GET: RequestHandler = async ({ locals }) => {
let output;
try {
output = await pb.collection("notifications")?.getFullList({
output = await pb?.collection("notifications")?.getFullList({
filter: `opUser="${user?.id}" `,
expand: "user,post,comment",
expand: "user",
sort: "-created",
});
} catch (e) {
@ -16,5 +16,5 @@ export const GET: RequestHandler = async ({ locals }) => {
output = [];
}
return new Response(JSON.stringify(output));
return new Response(JSON?.stringify(output));
};

View File

@ -1,47 +0,0 @@
import type { RequestHandler } from "./$types";
import { serialize } from "object-to-formdata";
import { validateData } from "$lib/utils";
import { updateCommentTextSchema } from "$lib/schemas";
import { error } from "@sveltejs/kit";
export const POST = (async ({ request, locals }) => {
let output = "error";
const body = await request.formData();
const commentId = body?.get("commentId");
if (body?.get("comment") === "undefined") {
body?.delete("comment");
body?.append("comment", "");
}
const { formData, errors } = await validateData(
body,
updateCommentTextSchema,
);
console.log(error);
if (errors) {
return new Response(JSON.stringify(output));
}
let updateComment;
try {
updateComment = await locals.pb
.collection("comments")
.update(commentId, serialize(formData));
updateComment = await locals.pb.collection("comments").getOne(commentId, {
expand: "user,alreadyVoted(comment)",
fields:
"*,expand.user,expand.alreadyVoted(comment).user,expand.alreadyVoted(comment).type",
});
output = "success";
} catch (err) {
console.log("Error: ", err);
error(err.status, err.message);
}
return new Response(JSON.stringify([output, updateComment]));
}) satisfies RequestHandler;