51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { Hono } from "hono";
|
|
|
|
const app = new Hono();
|
|
|
|
import { Client } from "https://deno.land/x/mysql/mod.ts";
|
|
|
|
const client = await new Client().connect({
|
|
hostname: "127.0.0.1",
|
|
username: "root",
|
|
db: "depannTout",
|
|
password: "root",
|
|
});
|
|
|
|
async function getAllInterventions() {
|
|
const today = new Date().toISOString().split("T")[0];
|
|
return await client.query("SELECT * FROM interventions WHERE date = ?", [
|
|
today,
|
|
]);
|
|
}
|
|
|
|
async function getAllClients() {
|
|
return await client.query("SELECT * FROM clients");
|
|
}
|
|
|
|
app.get("/interventions", async (c) => {
|
|
const interventions = await getAllInterventions();
|
|
return c.json(interventions);
|
|
});
|
|
|
|
app.get("/clients", async (c) => {
|
|
const clients = await getAllClients();
|
|
return c.json(clients);
|
|
});
|
|
|
|
app.post("/client", async (c) => {
|
|
const newClient = await c.req.json();
|
|
console.log(newClient);
|
|
client.query(
|
|
"INSERT INTO clients (prenom, nom, email, telephone, adresse) VALUES (?, ?, ?, ?, ?)",
|
|
[
|
|
newClient.prenom,
|
|
newClient.nom,
|
|
newClient.email,
|
|
newClient.telephone,
|
|
newClient.adresse,
|
|
]
|
|
);
|
|
});
|
|
|
|
Deno.serve(app.fetch);
|