This commit is contained in:
2025-09-12 18:29:13 +02:00
parent dc385b8422
commit c98394b5bf
17 changed files with 1786 additions and 9 deletions

72
src/routes/banking.ts Normal file
View File

@@ -0,0 +1,72 @@
import { FastifyInstance } from "fastify";
import jwt from "jsonwebtoken";
import {insertHistoryItem} from "../utils/history";
export default async function bankingRoutes(server: FastifyInstance) {
//Create Banking Statement
server.post("/banking/statements", async (req, reply) => {
if (!req.user) {
return reply.code(401).send({ error: "Unauthorized" });
}
const body = req.body as { data: string };
console.log(body);
const {data,error} = await server.supabase.from("statementallocations").insert({
...body.data,
tenant: req.user.tenant_id,
}).select()
await insertHistoryItem(server,{
entity: "bankstatements",
entityId: data.id,
action: "created",
created_by: req.user.user_id,
tenant_id: req.user.tenant_id,
oldVal: null,
newVal: data,
text: `Buchung erstellt`,
});
if(data && !error){
return reply.send(data)
}
});
//Delete Banking Statement
server.delete("/banking/statements/:id", async (req, reply) => {
if (!req.user) {
return reply.code(401).send({ error: "Unauthorized" });
}
const { id } = req.params as { id?: string }
const {data} = await server.supabase.from("statementallocations").select().eq("id",id).single()
const {error} = await server.supabase.from("statementallocations").delete().eq("id",id)
if(!error){
await insertHistoryItem(server,{
entity: "bankstatements",
entityId: id,
action: "deleted",
created_by: req.user.user_id,
tenant_id: req.user.tenant_id,
oldVal: data,
newVal: null,
text: `Buchung gelöscht`,
});
return reply.send({success:true})
} else {
return reply.code(500).send({error:"Fehler beim löschen"})
}
})
}