From 0fe16ad79eb01751180574cc4eaa7932eae81926 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Fri, 12 Sep 2025 19:40:53 +0200 Subject: [PATCH] Changed types --- src/plugins/auth.ts | 2 +- src/plugins/swagger.ts | 1 + src/routes/auth/auth-authenticated.ts | 8 +++++--- src/routes/auth/auth.ts | 7 +++++++ src/routes/auth/user.ts | 2 +- src/routes/banking.ts | 2 ++ src/routes/files.ts | 7 ++++--- src/routes/resources.ts | 2 ++ src/routes/resourcesSpecial.ts | 1 + src/routes/tenant.ts | 5 +++++ src/utils/export/datev.ts | 6 ++++-- src/utils/sort.ts | 3 ++- 12 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/plugins/auth.ts b/src/plugins/auth.ts index 68cd018..eb92f5d 100644 --- a/src/plugins/auth.ts +++ b/src/plugins/auth.ts @@ -47,7 +47,7 @@ declare module "fastify" { user?: { user_id: string; email: string; - tenant_id?: string; + tenant_id?: number; role?: string; }; } diff --git a/src/plugins/swagger.ts b/src/plugins/swagger.ts index 7bd32d9..b529ea8 100644 --- a/src/plugins/swagger.ts +++ b/src/plugins/swagger.ts @@ -16,6 +16,7 @@ export default fp(async (server: FastifyInstance) => { }, }); + // @ts-ignore await server.register(swaggerUi, { routePrefix: "/docs", // UI erreichbar unter http://localhost:3000/docs swagger: { diff --git a/src/routes/auth/auth-authenticated.ts b/src/routes/auth/auth-authenticated.ts index 4cd0d0b..93e254c 100644 --- a/src/routes/auth/auth-authenticated.ts +++ b/src/routes/auth/auth-authenticated.ts @@ -1,8 +1,6 @@ import { FastifyInstance } from "fastify"; import bcrypt from "bcrypt"; -import jwt from "jsonwebtoken"; -import { generateRandomPassword, hashPassword } from "../utils/password" -import { sendMail } from "../utils/mailer" + export default async function authRoutesAuthenticated(server: FastifyInstance) { server.post("/auth/password/change", { @@ -33,6 +31,7 @@ export default async function authRoutesAuthenticated(server: FastifyInstance) { const user_id = req.user?.user_id; // kommt aus JWT Middleware if (!user_id) { + // @ts-ignore return reply.code(401).send({ error: "Unauthorized" }); } @@ -44,12 +43,14 @@ export default async function authRoutesAuthenticated(server: FastifyInstance) { .single(); if (error || !user) { + // @ts-ignore return reply.code(404).send({ error: "User not found" }); } // Altes Passwort prüfen const valid = await bcrypt.compare(old_password, user.password_hash); if (!valid) { + // @ts-ignore return reply.code(401).send({ error: "Old password incorrect" }); } @@ -68,6 +69,7 @@ export default async function authRoutesAuthenticated(server: FastifyInstance) { if (updateError) { console.log(updateError); + // @ts-ignore return reply.code(500).send({ error: "Password update failed" }); } diff --git a/src/routes/auth/auth.ts b/src/routes/auth/auth.ts index 5e70e86..d0ac34e 100644 --- a/src/routes/auth/auth.ts +++ b/src/routes/auth/auth.ts @@ -31,6 +31,7 @@ export default async function authRoutes(server: FastifyInstance) { const body = req.body as { email: string; password: string }; if (!body.email || !body.password) { + // @ts-ignore return reply.code(400).send({ error: "Email and password required" }); } @@ -45,6 +46,7 @@ export default async function authRoutes(server: FastifyInstance) { .single(); if (error) { + // @ts-ignore return reply.code(400).send({ error: error.message }); } @@ -77,6 +79,7 @@ export default async function authRoutes(server: FastifyInstance) { const body = req.body as { email: string; password: string }; if (!body.email || !body.password) { + // @ts-ignore return reply.code(400).send({ error: "Email and password required" }); } @@ -104,6 +107,7 @@ export default async function authRoutes(server: FastifyInstance) { user = (data || []).find(i => i.tenants.find(x => x.id === req.tenant.id)) console.log(user) if(error) { + // @ts-ignore return reply.code(500).send({ error: "Internal Server Error" }); } } else { @@ -116,11 +120,13 @@ export default async function authRoutes(server: FastifyInstance) { user = data if(error) { console.log(error); + // @ts-ignore return reply.code(500).send({ error: "Internal Server Error" }); } } if(!user) { + // @ts-ignore return reply.code(401).send({ error: "Invalid credentials" }); } else { @@ -129,6 +135,7 @@ export default async function authRoutes(server: FastifyInstance) { const valid = await bcrypt.compare(body.password, user.password_hash); if (!valid) { + // @ts-ignore return reply.code(401).send({ error: "Invalid credentials" }); } else { const token = jwt.sign( diff --git a/src/routes/auth/user.ts b/src/routes/auth/user.ts index 687ea15..78ac0e6 100644 --- a/src/routes/auth/user.ts +++ b/src/routes/auth/user.ts @@ -6,7 +6,7 @@ export default async function userRoutes(server: FastifyInstance) { server.get("/user/:id", async (req, reply) => { const authUser = req.user // kommt aus JWT (user_id + tenant_id) - const {id} = req.params + const { id } = req.params as { id?: string } if (!authUser) { return reply.code(401).send({ error: "Unauthorized" }) diff --git a/src/routes/banking.ts b/src/routes/banking.ts index a85fed4..1e88cee 100644 --- a/src/routes/banking.ts +++ b/src/routes/banking.ts @@ -14,12 +14,14 @@ export default async function bankingRoutes(server: FastifyInstance) { console.log(body); const {data,error} = await server.supabase.from("statementallocations").insert({ + //@ts-ignore ...body.data, tenant: req.user.tenant_id, }).select() await insertHistoryItem(server,{ entity: "bankstatements", + //@ts-ignore entityId: data.id, action: "created", created_by: req.user.user_id, diff --git a/src/routes/files.ts b/src/routes/files.ts index 8e2f2da..beea652 100644 --- a/src/routes/files.ts +++ b/src/routes/files.ts @@ -98,7 +98,8 @@ export default async function fileRoutes(server: FastifyInstance) { server.post("/files/download/:id?", async (req, reply) => { const { id } = req.params as { id?: string } - const ids = req.body?.ids || [] + const { ids } = req.body as { ids: string[] } + try { if (id) { @@ -180,8 +181,8 @@ export default async function fileRoutes(server: FastifyInstance) { }) server.post("/files/presigned/:id?", async (req, reply) => { - const { id } = req.params as { key: string }; - const { ids } = req.body as { keys: string[] } + const { id } = req.params as { id: string }; + const { ids } = req.body as { ids: string[] } if(id) { try { diff --git a/src/routes/resources.ts b/src/routes/resources.ts index d48ec9e..b159c1a 100644 --- a/src/routes/resources.ts +++ b/src/routes/resources.ts @@ -3,7 +3,9 @@ import {insertHistoryItem } from "../utils/history" import {diffObjects} from "../utils/diff"; import {sortData} from "../utils/sort"; + const dataTypes: any[] = { + // @ts-ignore tasks: { isArchivable: true, label: "Aufgaben", diff --git a/src/routes/resourcesSpecial.ts b/src/routes/resourcesSpecial.ts index d50a33d..9fae6ac 100644 --- a/src/routes/resourcesSpecial.ts +++ b/src/routes/resourcesSpecial.ts @@ -26,6 +26,7 @@ export default async function resourceRoutesSpecial(server: FastifyInstance) { return reply.code(400).send({ error: error.message }); } + // @ts-ignore const sorted =sortData(data,sort,asc === "true" ? true : false) return sorted; diff --git a/src/routes/tenant.ts b/src/routes/tenant.ts index 6ad68d7..86e4c04 100644 --- a/src/routes/tenant.ts +++ b/src/routes/tenant.ts @@ -81,10 +81,15 @@ export default async function routes(server: FastifyInstance) { } let correctedData = data.map(i => { + + return { id: i.user_id, + // @ts-ignore email: i.auth_users.email, + // @ts-ignore profile: i.auth_users.auth_profiles.find(x => x.tenant_id === authUser.tenant_id), + // @ts-ignore full_name: i.auth_users.auth_profiles.find(x => x.tenant_id === authUser.tenant_id)?.full_name, } }) diff --git a/src/utils/export/datev.ts b/src/utils/export/datev.ts index c8d5298..3365fc8 100644 --- a/src/utils/export/datev.ts +++ b/src/utils/export/datev.ts @@ -18,8 +18,10 @@ const getCreatedDocumentTotal = (item) => { totalNet = totalNet + Number(rowPrice) if(row.taxPercent === 19) { + // @ts-ignore total19 = total19 + Number(rowPrice * 0.19) } else if(row.taxPercent === 7) { + // @ts-ignore total7 = total7 + Number(rowPrice * 0.07) } } @@ -168,10 +170,10 @@ export async function buildExportZip(server: FastifyInstance, tenant: number, st let accountData = accounts.find(i => i.id === account.account) - let buschluessel = 9 + let buschluessel: string = "9" if(account.taxType === '19'){ - buschluessel = 9 + buschluessel = "9" } else if(account.taxType === 'null') { buschluessel = "" } else if(account.taxType === '7') { diff --git a/src/utils/sort.ts b/src/utils/sort.ts index 1237d62..4cb28ef 100644 --- a/src/utils/sort.ts +++ b/src/utils/sort.ts @@ -7,7 +7,7 @@ */ export function sortData>( data: T[], - column?: keyof T, + column?: keyof T | null, ascending: boolean = true ): T[] { if (!column) return data @@ -27,6 +27,7 @@ export function sortData>( } // Datumsvergleich + // @ts-ignore if (valA instanceof Date && valB instanceof Date) { return ascending ? valA.getTime() - valB.getTime() : valB.getTime() - valA.getTime() }