Float zu Int und Bildupload
This commit is contained in:
@@ -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;
|
||||||
10
prisma/migrations/20250925141939_float_to_int/migration.sql
Normal file
10
prisma/migrations/20250925141939_float_to_int/migration.sql
Normal 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;
|
||||||
@@ -29,9 +29,9 @@ model Aufnahme {
|
|||||||
/// @zod.describe("Anzahl der (Wohn)Einheiten im Gebäude")
|
/// @zod.describe("Anzahl der (Wohn)Einheiten im Gebäude")
|
||||||
einheiten Int?
|
einheiten Int?
|
||||||
/// @zod.describe("Wohnfläche bei Wohngebäuden, Nutzfläche bei Gewerbegebäuden")
|
/// @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")
|
/// @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")
|
/// @zod.describe("Falls das Gebäude energetisch saniert ist, sollte dieser Wert auf true stehen")
|
||||||
saniert Boolean?
|
saniert Boolean?
|
||||||
/// @zod.describe("Ob ein Keller vorhanden, beheizt oder unbeheizt ist")
|
/// @zod.describe("Ob ein Keller vorhanden, beheizt oder unbeheizt ist")
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ model Benutzer {
|
|||||||
|
|
||||||
@@map("benutzer")
|
@@map("benutzer")
|
||||||
Provisionen Provisionen[]
|
Provisionen Provisionen[]
|
||||||
|
bilder Bild[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ model Bild {
|
|||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt @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_id String?
|
||||||
aufnahme Aufnahme? @relation(fields: [aufnahme_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
aufnahme Aufnahme? @relation(fields: [aufnahme_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ export const createCaller = createCallerFactory({
|
|||||||
"klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"),
|
"klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"),
|
||||||
"postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"),
|
"postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"),
|
||||||
"unterlage": await import("../src/pages/api/unterlage.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/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"),
|
||||||
"admin/bedarfsausweis-ausstellen": await import("../src/pages/api/admin/bedarfsausweis-ausstellen.ts"),
|
"admin/bedarfsausweis-ausstellen": await import("../src/pages/api/admin/bedarfsausweis-ausstellen.ts"),
|
||||||
"admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.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/nicht-ausstellen": await import("../src/pages/api/admin/nicht-ausstellen.ts"),
|
||||||
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
|
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
|
||||||
"admin/stornieren": await import("../src/pages/api/admin/stornieren.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/access-token": await import("../src/pages/api/auth/access-token.ts"),
|
||||||
"auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.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"),
|
"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/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"),
|
||||||
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
|
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
|
||||||
"bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].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/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"),
|
||||||
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
|
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
|
||||||
"ticket": await import("../src/pages/api/ticket/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/[id]": await import("../src/pages/api/verbrauchsausweis-wohnen/[id].ts"),
|
||||||
"verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.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/[id]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[id].ts"),
|
||||||
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
|
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
|
||||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||||
|
|||||||
@@ -97,10 +97,9 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
|
|||||||
data-test="flaeche"
|
data-test="flaeche"
|
||||||
maxlength="4"
|
maxlength="4"
|
||||||
type="number"
|
type="number"
|
||||||
|
step="1"
|
||||||
required
|
required
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
data-rule-minlength="2"
|
|
||||||
data-msg-minlength="min. 2 Zeichen"
|
|
||||||
bind:value={aufnahme.flaeche}
|
bind:value={aufnahme.flaeche}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -124,6 +123,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
|
|||||||
data-test="nutzflaeche"
|
data-test="nutzflaeche"
|
||||||
maxlength="4"
|
maxlength="4"
|
||||||
type="number"
|
type="number"
|
||||||
|
step="1"
|
||||||
required
|
required
|
||||||
bind:value={aufnahme.nutzflaeche}
|
bind:value={aufnahme.nutzflaeche}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import HelpLabel from "#components/labels/HelpLabel.svelte";
|
import HelpLabel from "#components/labels/HelpLabel.svelte";
|
||||||
import type { Enums } from "#lib/client/prisma.js";
|
import type { Enums } from "#lib/client/prisma.js";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
import { tryCatch } from "#lib/tryCatch.js";
|
import { tryCatch } from "#lib/tryCatch.js";
|
||||||
|
|
||||||
export let max: number = 2;
|
export let max: number = 2;
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
} from "./Ausweis/types.js";
|
} from "./Ausweis/types.js";
|
||||||
import { api } from "astro-typesafe-api/client";
|
import { api } from "astro-typesafe-api/client";
|
||||||
import { addNotification } from "./Notifications/shared.js";
|
import { addNotification } from "./Notifications/shared.js";
|
||||||
|
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||||
|
|
||||||
export let images: BildClient[] = [];
|
export let images: BildClient[] = [];
|
||||||
export let ausweis:
|
export let ausweis:
|
||||||
@@ -85,6 +87,12 @@
|
|||||||
data: dataURL,
|
data: dataURL,
|
||||||
kategorie,
|
kategorie,
|
||||||
name: file.name
|
name: file.name
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${Cookies.get(
|
||||||
|
API_ACCESS_TOKEN_COOKIE_NAME
|
||||||
|
)}`
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ export const BildSchema = z.object({
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
created_at: z.date(),
|
created_at: z.date(),
|
||||||
updated_at: z.date(),
|
updated_at: z.date(),
|
||||||
|
benutzer_id: z.string().nullish(),
|
||||||
aufnahme_id: z.string().nullish(),
|
aufnahme_id: z.string().nullish(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -92,11 +92,14 @@ export async function authorizationMiddleware(input: any, ctx: TypesafeAPIContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function maybeAuthorizationMiddleware(input: any, ctx: TypesafeAPIContextWithRequest<any>) {
|
export async function maybeAuthorizationMiddleware(input: any, ctx: TypesafeAPIContextWithRequest<any>) {
|
||||||
|
let user = null;
|
||||||
try {
|
try {
|
||||||
return authorizationMiddleware(input, ctx)
|
user = await authorizationMiddleware(input, ctx)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return null;
|
console.log(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authorizationHeaders = {
|
export const authorizationHeaders = {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export const PUT = defineApiRoute({
|
|||||||
output: z.object({
|
output: z.object({
|
||||||
id: z.string({ description: "Die id des Bildes." }),
|
id: z.string({ description: "Die id des Bildes." }),
|
||||||
}),
|
}),
|
||||||
async fetch(input) {
|
middleware: maybeAuthorizationMiddleware,
|
||||||
|
async fetch(input, context, user) {
|
||||||
const data = input.data;
|
const data = input.data;
|
||||||
|
|
||||||
if (!isBase64(data, { mimeRequired: true })) {
|
if (!isBase64(data, { mimeRequired: true })) {
|
||||||
@@ -43,6 +44,7 @@ export const PUT = defineApiRoute({
|
|||||||
id,
|
id,
|
||||||
kategorie: input.kategorie,
|
kategorie: input.kategorie,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
|
benutzer_id: user ? user.id : null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,11 +93,11 @@ export const DELETE = defineApiRoute({
|
|||||||
await prisma.bild.delete({
|
await prisma.bild.delete({
|
||||||
where: {
|
where: {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
aufnahme: {
|
OR: [{
|
||||||
benutzer: {
|
benutzer_id: user.id
|
||||||
id: user.id,
|
}, {
|
||||||
},
|
benutzer_id: null
|
||||||
},
|
}]
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -107,6 +109,8 @@ export const DELETE = defineApiRoute({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
throw new APIError({
|
throw new APIError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: "Bild konnte nicht gelöscht werden.",
|
message: "Bild konnte nicht gelöscht werden.",
|
||||||
|
|||||||
Reference in New Issue
Block a user