mirror of
https://github.com/skidoodle/budgetable.git
synced 2025-02-15 03:39:14 +01:00
Merge pull request #1 from hasitotabla/main
feat: get collection from env
This commit is contained in:
@@ -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" },
|
||||
|
@@ -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" },
|
||||
|
Reference in New Issue
Block a user