mirror of
https://github.com/skidoodle/budgetable.git
synced 2025-02-15 03:39:14 +01:00
first commit
This commit is contained in:
commit
fc0e75383f
37 changed files with 11250 additions and 0 deletions
56
src/app/pocketbase/route.ts
Normal file
56
src/app/pocketbase/route.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import pb from "@/app/lib/pocketbase";
|
||||
|
||||
const { EMAIL, PASSWORD } = process.env;
|
||||
|
||||
async function authenticateSuperuser() {
|
||||
if (!pb.authStore.isValid) {
|
||||
await pb.collection("_superusers").authWithPassword(EMAIL!, PASSWORD!);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await authenticateSuperuser();
|
||||
const records = await pb.collection("budgetable").getFullList();
|
||||
return new Response(JSON.stringify(records), {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: {
|
||||
message: "Failed to fetch data",
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 500,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
await authenticateSuperuser();
|
||||
const data = await req.json();
|
||||
const record = await pb.collection("budgetable").create(data);
|
||||
return new Response(JSON.stringify(record), {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error adding data:", error);
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: {
|
||||
message: "Failed to add data",
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 500,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue