Minor fix

This commit is contained in:
Clayzxr
2025-01-21 16:32:00 +01:00
parent db6669901b
commit 661b59645b
2 changed files with 0 additions and 3 deletions
+31
View File
@@ -0,0 +1,31 @@
import { Handlers } from "$fresh/server.ts";
import { Database } from "@db/sqlite";
export const handler: Handlers = {
async GET() {
try {
const db = new Database("databases/data/mobility.db");
db.prepare(
`
CREATE TABLE IF NOT EXISTS promotions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE NOT NULL
);
`
).run();
const promotions = db.prepare("SELECT id, name FROM promotions").all();
db.close();
return new Response(JSON.stringify(promotions), {
status: 200,
headers: { "Content-Type": "application/json" },
});
} catch (error) {
console.error("Error fetching promotions:", error);
return new Response("Failed to fetch promotions", { status: 500 });
}
},
};