Merge pull request #1 from hasitotabla/main

feat: get collection from env
This commit is contained in:
skidoodle 2025-01-03 12:13:48 +01:00 committed by GitHub
commit 6ebcbdfd0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,6 @@
import pb from "@/lib/pocketbase";
const { EMAIL, PASSWORD } = process.env;
const { EMAIL, PASSWORD, COLLECTION = "budgetable" } = process.env;
async function authenticateSuperuser() {
if (!EMAIL || !PASSWORD) {
@ -33,7 +33,7 @@ export async function GET(
);
}
const record = await pb.collection("budgetable").getOne(id);
const record = await pb.collection(COLLECTION).getOne(id);
return Response.json(record, {
status: 200,
headers: { "Content-Type": "application/json" },
@ -76,7 +76,7 @@ export async function DELETE(
);
}
await pb.collection("budgetable").delete(id);
await pb.collection(COLLECTION).delete(id);
return Response.json(
{
success: true,
@ -139,7 +139,7 @@ export async function PUT(
);
}
const updatedRecord = await pb.collection("budgetable").update(id, body);
const updatedRecord = await pb.collection(COLLECTION).update(id, body);
return Response.json(updatedRecord, {
status: 200,
headers: { "Content-Type": "application/json" },

View file

@ -1,6 +1,6 @@
import pb from "@/lib/pocketbase";
const { EMAIL, PASSWORD } = process.env;
const { EMAIL, PASSWORD, COLLECTION = "budgetable" } = process.env;
async function authenticateSuperuser() {
if (!EMAIL || !PASSWORD) {
@ -14,7 +14,7 @@ async function authenticateSuperuser() {
export async function GET() {
try {
await authenticateSuperuser();
const records = await pb.collection("budgetable").getFullList();
const records = await pb.collection(COLLECTION).getFullList();
return Response.json(records, {
status: 200,
headers: { "Content-Type": "application/json" },
@ -39,7 +39,7 @@ export async function POST(req: Request) {
try {
await authenticateSuperuser();
const data = await req.json();
const record = await pb.collection("budgetable").create(data);
const record = await pb.collection(COLLECTION).create(data);
return Response.json(record, {
status: 201,
headers: { "Content-Type": "application/json" },