Implement receipt management features including creation, loading, and display of receipts. Refactor related components and enhance UI with dialogs for adding new receipts. Update type definitions and improve error handling for better user experience.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import type { StackqReceipt } from "$lib/types/receipts";
|
||||
|
||||
const COLLECTION = "Stackq_Receipts";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
const { id } = params;
|
||||
try {
|
||||
const record = await locals.pb
|
||||
.collection(COLLECTION)
|
||||
.getOne<StackqReceipt>(id, { expand: "User" });
|
||||
return { receipt: record };
|
||||
} catch (err: unknown) {
|
||||
const is404 =
|
||||
err &&
|
||||
typeof err === "object" &&
|
||||
"status" in err &&
|
||||
(err as { status: number }).status === 404;
|
||||
if (is404) throw error(404, "Receipt not found");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user