Float zu Int und Bildupload

This commit is contained in:
Moritz Utcke
2025-09-25 10:20:18 -04:00
parent 82f8cfc0ff
commit 634bef971d
11 changed files with 50 additions and 16 deletions

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Bild" ADD COLUMN "benutzer_id" TEXT;
-- AddForeignKey
ALTER TABLE "Bild" ADD CONSTRAINT "Bild_benutzer_id_fkey" FOREIGN KEY ("benutzer_id") REFERENCES "benutzer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

View File

@@ -0,0 +1,10 @@
/*
Warnings:
- You are about to alter the column `flaeche` on the `Aufnahme` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Integer`.
- You are about to alter the column `nutzflaeche` on the `Aufnahme` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Integer`.
*/
-- AlterTable
ALTER TABLE "Aufnahme" ALTER COLUMN "flaeche" SET DATA TYPE INTEGER,
ALTER COLUMN "nutzflaeche" SET DATA TYPE INTEGER;

View File

@@ -29,9 +29,9 @@ model Aufnahme {
/// @zod.describe("Anzahl der (Wohn)Einheiten im Gebäude")
einheiten Int?
/// @zod.describe("Wohnfläche bei Wohngebäuden, Nutzfläche bei Gewerbegebäuden")
flaeche Float?
flaeche Int?
/// @zod.describe("(energetische) Nutzfläche des Gebäudes. Bei Gewerbegebäuden entspricht Sie der Nutzfläche")
nutzflaeche Float?
nutzflaeche Int?
/// @zod.describe("Falls das Gebäude energetisch saniert ist, sollte dieser Wert auf true stehen")
saniert Boolean?
/// @zod.describe("Ob ein Keller vorhanden, beheizt oder unbeheizt ist")

View File

@@ -53,6 +53,7 @@ model Benutzer {
@@map("benutzer")
Provisionen Provisionen[]
bilder Bild[]
}

View File

@@ -15,6 +15,8 @@ model Bild {
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
benutzer_id String?
benutzer Benutzer? @relation(fields: [benutzer_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
aufnahme_id String?
aufnahme Aufnahme? @relation(fields: [aufnahme_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
}

View File

@@ -5,6 +5,7 @@ export const createCaller = createCallerFactory({
"klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"),
"postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"),
"unterlage": await import("../src/pages/api/unterlage.ts"),
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
"admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"),
"admin/bedarfsausweis-ausstellen": await import("../src/pages/api/admin/bedarfsausweis-ausstellen.ts"),
"admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"),
@@ -12,11 +13,10 @@ export const createCaller = createCallerFactory({
"admin/nicht-ausstellen": await import("../src/pages/api/admin/nicht-ausstellen.ts"),
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
"admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"),
"ausweise": await import("../src/pages/api/ausweise/index.ts"),
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
"auth/access-token": await import("../src/pages/api/auth/access-token.ts"),
"auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"),
"auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"),
"ausweise": await import("../src/pages/api/ausweise/index.ts"),
"bedarfsausweis-wohnen/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"),
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
"bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].ts"),
@@ -31,10 +31,10 @@ export const createCaller = createCallerFactory({
"rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"),
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
"ticket": await import("../src/pages/api/ticket/index.ts"),
"user": await import("../src/pages/api/user/index.ts"),
"user/self": await import("../src/pages/api/user/self.ts"),
"verbrauchsausweis-wohnen/[id]": await import("../src/pages/api/verbrauchsausweis-wohnen/[id].ts"),
"verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"),
"user": await import("../src/pages/api/user/index.ts"),
"user/self": await import("../src/pages/api/user/self.ts"),
"verbrauchsausweis-gewerbe/[id]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[id].ts"),
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),

View File

@@ -97,10 +97,9 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
data-test="flaeche"
maxlength="4"
type="number"
step="1"
required
autocomplete="off"
data-rule-minlength="2"
data-msg-minlength="min. 2 Zeichen"
bind:value={aufnahme.flaeche}
/>
@@ -124,6 +123,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
data-test="nutzflaeche"
maxlength="4"
type="number"
step="1"
required
bind:value={aufnahme.nutzflaeche}
/>

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import HelpLabel from "#components/labels/HelpLabel.svelte";
import type { Enums } from "#lib/client/prisma.js";
import Cookies from "js-cookie";
import { tryCatch } from "#lib/tryCatch.js";
export let max: number = 2;
@@ -17,6 +18,7 @@
} from "./Ausweis/types.js";
import { api } from "astro-typesafe-api/client";
import { addNotification } from "./Notifications/shared.js";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
export let images: BildClient[] = [];
export let ausweis:
@@ -85,6 +87,12 @@
data: dataURL,
kategorie,
name: file.name
}, {
headers: {
"Authorization": `Bearer ${Cookies.get(
API_ACCESS_TOKEN_COOKIE_NAME
)}`
}
}))
if (error) {

View File

@@ -7,5 +7,6 @@ export const BildSchema = z.object({
name: z.string(),
created_at: z.date(),
updated_at: z.date(),
benutzer_id: z.string().nullish(),
aufnahme_id: z.string().nullish(),
})

View File

@@ -92,11 +92,14 @@ export async function authorizationMiddleware(input: any, ctx: TypesafeAPIContex
}
export async function maybeAuthorizationMiddleware(input: any, ctx: TypesafeAPIContextWithRequest<any>) {
let user = null;
try {
return authorizationMiddleware(input, ctx)
user = await authorizationMiddleware(input, ctx)
} catch(e) {
return null;
console.log(e);
}
return user;
}
export const authorizationHeaders = {

View File

@@ -23,7 +23,8 @@ export const PUT = defineApiRoute({
output: z.object({
id: z.string({ description: "Die id des Bildes." }),
}),
async fetch(input) {
middleware: maybeAuthorizationMiddleware,
async fetch(input, context, user) {
const data = input.data;
if (!isBase64(data, { mimeRequired: true })) {
@@ -43,6 +44,7 @@ export const PUT = defineApiRoute({
id,
kategorie: input.kategorie,
name: input.name,
benutzer_id: user ? user.id : null,
},
});
@@ -91,11 +93,11 @@ export const DELETE = defineApiRoute({
await prisma.bild.delete({
where: {
id: input.id,
aufnahme: {
benutzer: {
id: user.id,
},
},
OR: [{
benutzer_id: user.id
}, {
benutzer_id: null
}]
},
});
} else {
@@ -107,6 +109,8 @@ export const DELETE = defineApiRoute({
});
}
} catch (e) {
console.log(e);
throw new APIError({
code: "INTERNAL_SERVER_ERROR",
message: "Bild konnte nicht gelöscht werden.",