Skip to content

Commit 6ebcbdf

Browse files
authored
Merge pull request #1 from hasitotabla/main
feat: get collection from env
2 parents fb7740d + adb45ca commit 6ebcbdf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/app/pocketbase/[id]/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pb from "@/lib/pocketbase";
22

3-
const { EMAIL, PASSWORD } = process.env;
3+
const { EMAIL, PASSWORD, COLLECTION = "budgetable" } = process.env;
44

55
async function authenticateSuperuser() {
66
if (!EMAIL || !PASSWORD) {
@@ -33,7 +33,7 @@ export async function GET(
3333
);
3434
}
3535

36-
const record = await pb.collection("budgetable").getOne(id);
36+
const record = await pb.collection(COLLECTION).getOne(id);
3737
return Response.json(record, {
3838
status: 200,
3939
headers: { "Content-Type": "application/json" },
@@ -76,7 +76,7 @@ export async function DELETE(
7676
);
7777
}
7878

79-
await pb.collection("budgetable").delete(id);
79+
await pb.collection(COLLECTION).delete(id);
8080
return Response.json(
8181
{
8282
success: true,
@@ -139,7 +139,7 @@ export async function PUT(
139139
);
140140
}
141141

142-
const updatedRecord = await pb.collection("budgetable").update(id, body);
142+
const updatedRecord = await pb.collection(COLLECTION).update(id, body);
143143
return Response.json(updatedRecord, {
144144
status: 200,
145145
headers: { "Content-Type": "application/json" },

src/app/pocketbase/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pb from "@/lib/pocketbase";
22

3-
const { EMAIL, PASSWORD } = process.env;
3+
const { EMAIL, PASSWORD, COLLECTION = "budgetable" } = process.env;
44

55
async function authenticateSuperuser() {
66
if (!EMAIL || !PASSWORD) {
@@ -14,7 +14,7 @@ async function authenticateSuperuser() {
1414
export async function GET() {
1515
try {
1616
await authenticateSuperuser();
17-
const records = await pb.collection("budgetable").getFullList();
17+
const records = await pb.collection(COLLECTION).getFullList();
1818
return Response.json(records, {
1919
status: 200,
2020
headers: { "Content-Type": "application/json" },
@@ -39,7 +39,7 @@ export async function POST(req: Request) {
3939
try {
4040
await authenticateSuperuser();
4141
const data = await req.json();
42-
const record = await pb.collection("budgetable").create(data);
42+
const record = await pb.collection(COLLECTION).create(data);
4343
return Response.json(record, {
4444
status: 201,
4545
headers: { "Content-Type": "application/json" },

0 commit comments

Comments
 (0)