Verbesserungen im Prozess

This commit is contained in:
Moritz Utcke
2025-03-25 19:15:16 -03:00
parent 0117f94c07
commit 75ade8ebaa
45 changed files with 380 additions and 392 deletions

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/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"),
"admin/erinnern": await import("../src/pages/api/admin/erinnern.ts"),
@@ -12,13 +13,12 @@ export const createCaller = createCallerFactory({
"admin/post-ausstellen": await import("../src/pages/api/admin/post-ausstellen.ts"),
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
"admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"),
"bedarfsausweis-gewerbe/[uid]": await import("../src/pages/api/bedarfsausweis-gewerbe/[uid].ts"),
"bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"),
"ausweise": await import("../src/pages/api/ausweise/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"),
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
"bedarfsausweis-gewerbe/[uid]": await import("../src/pages/api/bedarfsausweis-gewerbe/[uid].ts"),
"bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/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"),
"bilder/[id]": await import("../src/pages/api/bilder/[id].ts"),

View File

@@ -3,7 +3,7 @@ import { api } from "astro-typesafe-api/client"
import { exclude } from "#lib/exclude.js";
import Cookies from "js-cookie";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js";
import { Enums } from "#lib/client/prisma.js";
export async function ausweisSpeichern(

View File

@@ -1,95 +0,0 @@
import {
ObjektClient,
UploadedGebaeudeBild,
VerbrauchsausweisWohnenClient,
} from "#components/Ausweis/types.js";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { Enums } from "#lib/client/prisma";
import { addNotification, updateNotification } from "@ibcornelsen/ui";
import { api } from "astro-typesafe-api/client";
import Cookies from "js-cookie";
export async function bilderHochladen(
images: (UploadedGebaeudeBild & { base64?: string, update?: boolean })[],
aufnahme_uid: string
) {
if (images.length == 0) {
return images;
}
// Wenn Bilder hochgeladen werden konvertieren wir sie zu base64, das heißt, dass die base64 Eigenschaft bei diesen Bildern
// existiert. Das müssen wir TypeScript nur wissen lassen, damit es uns in Ruhe lässt.
const imagesToUpload = images.filter(
(image) => !image.uid || image.update
) as unknown as {
data: string;
kategorie: string;
uid?: string;
update: boolean;
}[];
if (imagesToUpload.length == 0) {
return images;
}
// Alle Bilder hochladen
const notification = addNotification({
dismissable: false,
message: "Bilder hochladen.",
subtext: `${imagesToUpload.length} Bilder werden hochgeladen, bitte haben sie Geduld.`,
timeout: 0,
type: "info",
});
for (let i = 0; i < imagesToUpload.length; i++) {
const image = imagesToUpload[i];
try {
if (image.update) {
await api.bilder._uid.PATCH.fetch({
data: image.data,
kategorie: image.kategorie as Enums.BilderKategorie,
}, {
params: {
uid: image.uid as string,
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
});
} else {
const response = await api.aufnahme._uid.bilder.PUT.fetch({
data: image.data,
kategorie: image.kategorie as Enums.BilderKategorie
}, {
params: {
uid: aufnahme_uid
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
});
image.uid = response.uid;
}
updateNotification(notification, {
dismissable: true,
message: "Bild hochgeladen.",
subtext: `${i + 1}/${
imagesToUpload.length
} Bildern wurden erfolgreich hochgeladen.`,
timeout: 3000,
});
} catch (e) {
updateNotification(notification, {
dismissable: true,
message: "Bild konnte nicht hochgeladen werden.",
subtext: `Eines ihrer Bilder konnte nicht hochgeladen werden. Wir haben bereits ein Ticket erstellt und melden uns so schnell wie möglich bei ihnen.`,
timeout: 15000,
type: "error",
});
}
}
return images;
}

View File

@@ -3,7 +3,7 @@ import { api } from "astro-typesafe-api/client"
import { exclude } from "#lib/exclude.js";
import Cookies from "js-cookie";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, UnterlageClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, UnterlageClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js";
import { Enums } from "#lib/client/prisma.js";
export async function nachweisSpeichern(
@@ -14,8 +14,8 @@ export async function nachweisSpeichern(
unterlagen: UnterlageClient[],
ausweisart: Enums.Ausweisart
) {
if (objekt.uid) {
await api.objekt._uid.PATCH.fetch({
if (objekt.id) {
await api.objekt._id.PATCH.fetch({
adresse: objekt.adresse,
latitude: 0,
longitude: 0,
@@ -23,14 +23,14 @@ export async function nachweisSpeichern(
plz: objekt.plz
}, {
params: {
uid: objekt.uid
id: objekt.id
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
} else {
const { uid } = await api.objekt.PUT.fetch({
const { id } = await api.objekt.PUT.fetch({
adresse: objekt.adresse,
latitude: 0,
longitude: 0,
@@ -42,13 +42,13 @@ export async function nachweisSpeichern(
}
})
objekt.uid = uid;
objekt.id = id;
}
if (aufnahme.uid) {
await api.aufnahme._uid.PATCH.fetch({
if (aufnahme.id) {
await api.aufnahme._id.PATCH.fetch({
baujahr_gebaeude: aufnahme.baujahr_gebaeude || [],
baujahr_heizung: aufnahme.baujahr_heizung || [],
baujahr_klima: aufnahme.baujahr_klima || [],
@@ -103,14 +103,14 @@ export async function nachweisSpeichern(
zirkulation: aufnahme.zirkulation
}, {
params: {
uid: aufnahme.uid
id: aufnahme.id
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
} else {
const { uid } = await api.aufnahme.PUT.fetch({
const { id } = await api.aufnahme.PUT.fetch({
aufnahme: {
baujahr_gebaeude: aufnahme.baujahr_gebaeude,
baujahr_heizung: aufnahme.baujahr_heizung,
@@ -166,56 +166,56 @@ export async function nachweisSpeichern(
zentralheizung: aufnahme.zentralheizung,
zirkulation: aufnahme.zirkulation
},
uid_objekt: objekt.uid
objekt_id: objekt.id
}, {
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
aufnahme.uid = uid
aufnahme.id = id
}
let patchRoute: any;
let putRoute: any;
if (ausweisart == Enums.Ausweisart.GEGNachweisWohnen) {
patchRoute = api["geg-nachweis-wohnen"]._uid.PATCH
patchRoute = api["geg-nachweis-wohnen"]._id.PATCH
putRoute = api["geg-nachweis-wohnen"].PUT
} else if (ausweisart === Enums.Ausweisart.GEGNachweisGewerbe) {
patchRoute = api["geg-nachweis-gewerbe"]._uid.PATCH
patchRoute = api["geg-nachweis-gewerbe"]._id.PATCH
putRoute = api["geg-nachweis-gewerbe"].PUT
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) {
patchRoute = api["bedarfsausweis-gewerbe"]._uid.PATCH
patchRoute = api["bedarfsausweis-gewerbe"]._id.PATCH
putRoute = api["bedarfsausweis-gewerbe"].PUT
}
if (nachweis.uid) {
if (nachweis.id) {
await patchRoute.fetch({
...exclude(nachweis, ["uid"])
...exclude(nachweis, ["id"])
}, {
params: {
uid: nachweis.uid
id: nachweis.id
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
} else {
const { uid } = await putRoute.fetch({
const { id } = await putRoute.fetch({
nachweis,
uid_aufnahme: aufnahme.uid
uid_aufnahme: aufnahme.id
}, {
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
nachweis.uid = uid;
nachweis.id = id;
}
await api.aufnahme._uid.bilder.PUT.fetch(bilder.map(bild => bild.uid), {
await api.aufnahme._id.bilder.PUT.fetch(bilder.map(bild => bild.id), {
params: {
uid: aufnahme.uid
id: aufnahme.id
},
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
@@ -223,8 +223,8 @@ export async function nachweisSpeichern(
})
return {
uid_nachweis: nachweis.uid,
uid_aufnahme: aufnahme.uid,
uid_objekt: objekt.uid
nachweis_id: nachweis.id,
aufnahme_id: aufnahme.id,
objekt_id: objekt.id
}
}

View File

@@ -1,13 +1,12 @@
<script lang="ts">
import { Buffer } from "buffer";
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "./Ausweis/types.js";
import { Enums } from "#lib/client/prisma";
import { AufnahmeClient, BildClient, ObjektClient, VerbrauchsausweisWohnenClient } from "./Ausweis/types.js";
import { Enums } from "#lib/client/prisma.js";
import { openWindowWithPost } from "#lib/helpers/window.js";
export let ausweis: VerbrauchsausweisWohnenClient;
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let bilder: UploadedGebaeudeBild[];
export let bilder: BildClient[];
export let ausweisart: Enums.Ausweisart
</script>

View File

@@ -2,7 +2,7 @@
import {
AufnahmeClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
} from "./types.js";
import SanierungsOption from "#components/Ausweis/SanierungsOption.svelte";
import AnlagenTechnikImage from "./AnlagenTechnikImage.svelte";
@@ -11,7 +11,7 @@
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let ausweis: BedarfsausweisGewerbe;
export let images: UploadedGebaeudeBild[];
export let images: BildClient[];
</script>
<div

View File

@@ -6,13 +6,13 @@
import ImageGrid from "#components/ImageGrid.svelte";
import {
Enums,
} from "#lib/client/prisma";
} from "#lib/client/prisma.js";
import {
AufnahmeClient,
BedarfsausweisWohnenClient,
BildClient,
ObjektClient,
UploadedGebaeudeBild,
VerbrauchsausweisGewerbeClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
@@ -20,7 +20,7 @@
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient;
export let aufnahme: AufnahmeClient;
export let objekt: ObjektClient;
export let images: UploadedGebaeudeBild[] = [];
export let images: BildClient[] = [];
export let ausweisart: Enums.Ausweisart;
</script>

View File

@@ -12,7 +12,7 @@
import {
AufnahmeClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
import { boolean } from "astro:schema";
@@ -21,7 +21,7 @@
export let gebaeude: ObjektClient;
export let aufnahme: AufnahmeClient;
export let ausweis: VerbrauchsausweisWohnenClient;
export let images: UploadedGebaeudeBild[];
export let images: BildClient[];
</script>
<div

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { ausweisSpeichern } from "#client/lib/ausweisSpeichern.js";
import { validateAccessTokenClient } from "#client/lib/validateAccessToken.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BenutzerClient, GEGNachweisWohnenClient, ObjektClient, UnterlageClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { AufnahmeClient, BedarfsausweisWohnenClient, BenutzerClient, GEGNachweisWohnenClient, ObjektClient, UnterlageClient, BildClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import Overlay from "#components/Overlay.svelte";
import EmbeddedAuthFlowModule from "#modules/EmbeddedAuthFlowModule.svelte";
@@ -11,9 +11,9 @@
import { nachweisSpeichern } from "#client/lib/nachweisSpeichern.js";
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient | GEGNachweisWohnenClient;
export let bilder: UploadedGebaeudeBild[];
export let bilder: BildClient[];
export let unterlagen: UnterlageClient[] = [];
export let user: BenutzerClient;
export let user: BenutzerClient | null;
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let ausweisart: Enums.Ausweisart
@@ -71,20 +71,22 @@
let result: Awaited<ReturnType<typeof ausweisSpeichern>> | Awaited<ReturnType<typeof nachweisSpeichern>> | null = null;
if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen || ausweisart === Enums.Ausweisart.GEGNachweisGewerbe || ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) {
result = await nachweisSpeichern(ausweis, objekt, aufnahme, bilder, unterlagen, ausweisart)
result = await nachweisSpeichern({ ...ausweis, ausweistyp }, objekt, aufnahme, bilder, unterlagen, ausweisart)
ausweis.id = result.nachweis_id;
} else {
result = await ausweisSpeichern(ausweis, objekt, aufnahme, bilder, ausweisart)
result = await ausweisSpeichern({ ...ausweis, ausweistyp }, objekt, aufnahme, bilder, ausweisart)
ausweis.id = result.ausweis_id;
}
if (result !== null) {
window.history.pushState(
{},
"",
`${location.pathname}?uid=${ausweis.id}`
`${location.pathname}?id=${ausweis.id}`
);
localStorage.clear()
window.location.href = `/speichern-erfolgreich?uid=${ausweis.id}`
window.location.href = `/speichern-erfolgreich?id=${ausweis.id}`
}
}

View File

@@ -1,9 +1,9 @@
<script lang="ts">
import ImageGrid from "../ImageGrid.svelte";;
import { Enums } from "#lib/client/prisma.js";
import { BedarfsausweisWohnenClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
import { BedarfsausweisWohnenClient, ObjektClient, BildClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
export let images: UploadedGebaeudeBild[] = [];
export let images: BildClient[] = [];
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient;
export let objekt: ObjektClient;
</script>

View File

@@ -1,9 +1,9 @@
<script lang="ts">
import ImageGrid from "../ImageGrid.svelte";;
import { Enums } from "#lib/client/prisma";
import { BedarfsausweisWohnenClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
import { Enums } from "#lib/client/prisma.js";
import { BedarfsausweisWohnenClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
export let images: UploadedGebaeudeBild[] = [];
export let images: BildClient[] = [];
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient;
export let objekt: ObjektClient;
</script>

View File

@@ -1,9 +1,9 @@
<script lang="ts">
import ImageGrid from "../ImageGrid.svelte";;
import { Enums } from "#lib/client/prisma";
import { BedarfsausweisWohnenClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
import { Enums } from "#lib/client/prisma.js";
import { BedarfsausweisWohnenClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./types.js";
export let images: UploadedGebaeudeBild[] = [];
export let images: BildClient[] = [];
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient;
export let gebaeude: ObjektClient;
</script>

View File

@@ -9,7 +9,7 @@
import {
AufnahmeClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
VerbrauchsausweisGewerbeClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
@@ -19,7 +19,7 @@
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient;
export let images: UploadedGebaeudeBild[];
export let images: BildClient[];
</script>
<div

View File

@@ -1,24 +1,21 @@
<script lang="ts">
import HelpLabel from "#components/labels/HelpLabel.svelte";
import Inputlabel from "#components/labels/InputLabel.svelte";
import { Enums } from "#lib/client/prisma.js";
import HeizungImage from "./HeizungImage.svelte";
import {
AufnahmeClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
VerbrauchsausweisGewerbeClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
import { boolean } from "astro:schema";
import SanierungsOption from "#components/Ausweis/SanierungsOption.svelte";
import AngabenZurHeizunganlage from "#components/Ausweis/AngabenZurHeizunganlage.svelte";
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient;
export let images: UploadedGebaeudeBild[];
export let images: BildClient[];
export let ausweisart: Enums.Ausweisart;
</script>

View File

@@ -6,7 +6,7 @@
AufnahmeClient,
BedarfsausweisWohnenClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
VerbrauchsausweisGewerbeClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
@@ -18,7 +18,7 @@
| VerbrauchsausweisWohnenClient
| VerbrauchsausweisGewerbeClient
| BedarfsausweisWohnenClient;
export let images: UploadedGebaeudeBild[];
export let images: BildClient[];
</script>
<div

View File

@@ -31,9 +31,7 @@ export type UploadedGebaeudeBild = OmitKeys<Bild, "id" | "aufnahme_id"> & {
* @export
* @typedef {VerbrauchsausweisWohnenClient}
*/
export type VerbrauchsausweisWohnenClient = VerbrauchsausweisWohnen & {
objekt_id: string
};
export type VerbrauchsausweisWohnenClient = VerbrauchsausweisWohnen
/**
* Das ist der Typescript Type für den Verbrauchsausweis Gewerbe mit allen Feldern die
@@ -45,9 +43,7 @@ export type VerbrauchsausweisWohnenClient = VerbrauchsausweisWohnen & {
* @export
* @typedef {VerbrauchsausweisWohnenClient}
*/
export type VerbrauchsausweisGewerbeClient = VerbrauchsausweisGewerbe & {
objekt_id: string
};
export type VerbrauchsausweisGewerbeClient = VerbrauchsausweisGewerbe
/**
* Das ist der Typescript Type für den Verbrauchsausweis Gewerbe mit allen Feldern die
@@ -59,9 +55,7 @@ export type VerbrauchsausweisGewerbeClient = VerbrauchsausweisGewerbe & {
* @export
* @typedef {VerbrauchsausweisWohnenClient}
*/
export type BedarfsausweisWohnenClient = BedarfsausweisWohnen & {
objekt_id: string
};
export type BedarfsausweisWohnenClient = BedarfsausweisWohnen
/**
* Das ist der Typescript Type für die Gebäude Stammdaten mit allen Feldern die
@@ -152,8 +146,4 @@ export type AufnahmeKomplettClient = AufnahmeClient & {
geg_nachweise_wohnen: (GEGNachweisWohnenClient & { rechnung: RechnungClient })[]
}
export type GEGNachweisWohnenClient = Omit<GEGNachweisWohnen, "id" | "aufnahme_id" | "benutzer_id"> & {
uid_objekt: string,
uid_aufnahme: string,
uid_benutzer?: string
}
export type GEGNachweisWohnenClient = GEGNachweisWohnen

View File

@@ -5,7 +5,7 @@
AufnahmeClient,
getAusweisartFromUUID,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
VerbrauchsausweisWohnenClient,
} from "./Ausweis/types.js";
import AusweisPruefenTooltip from "./AusweisPruefenTooltip.svelte";
@@ -22,7 +22,7 @@
export let ausweis: VerbrauchsausweisWohnenClient;
export let aufnahme: AufnahmeClient;
export let objekt: ObjektClient;
export let bilder: UploadedGebaeudeBild[]
export let bilder: BildClient[]
export let events: Event[]
export let calculations: Awaited<
ReturnType<typeof endEnergieVerbrauchVerbrauchsausweis_2016>
@@ -49,7 +49,7 @@
const ausweisArt = getAusweisartFromUUID(ausweis.uid)
const ausweisArt = getAusweisartFromUUID(ausweis.id)
let verbrauchWWGesamt_1 = "";
let verbrauchWWGesamt_2 = "";
@@ -458,7 +458,7 @@
async function stornieren(ausweis: VerbrauchsausweisWohnenClient) {
try {
const response = await api.admin.stornieren.PUT.fetch({
uid_ausweis: ausweis.uid
uid_ausweis: ausweis.id
}, {
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
@@ -748,7 +748,7 @@
{#each bilder as image}
<div>
<h2 class="text-lg mb-4 font-bold">{image.kategorie}</h2>
<img src="/bilder/{image.uid}.jpg">
<img src="/bilder/{image.id}.jpg">
</div>
{/each}
{/if}
@@ -774,7 +774,7 @@
<td title="Ausweis anzeigen" class="w-[50px]"
><a
class="energieausweis-img"
href="/pdf/ansichtsausweis?uid={ausweis.uid}"
href="/pdf/ansichtsausweis?uid={ausweis.id}"
target="_blank"
><img
src="/images/dashboard/ausweis.jpg"
@@ -786,7 +786,7 @@
<td title="Datenblatt anzeigen" width="50px"
><a
class="energieausweis-img"
href="/pdf/datenblatt?uid={ausweis.uid}"
href="/pdf/datenblatt?uid={ausweis.id}"
target="_blank"
><img
src="/images/dashboard/datenblatt.jpg"
@@ -857,7 +857,7 @@
{/if}
{#if !ausweis.registriernummer}
<td title="Registriernummer vom DiBT anfordern." class="w-4 p-1"><button class="btn btn-xs btn-ghost" on:click={() => {
registriernummerAnfordern(ausweis.uid)
registriernummerAnfordern(ausweis.id)
}}>R</button></td>
{/if}
</tr>
@@ -884,7 +884,7 @@
</tr>
<tr>
<td>UID</td>
<td><strong><pre>{ausweis.uid}</pre></strong></td>
<td><strong><pre>{ausweis.id}</pre></strong></td>
</tr>
</tbody>
</table>

View File

@@ -311,12 +311,12 @@
{#if ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen}
<a
class="button text-sm"
href="/energieausweis-erstellen/verbrauchsausweis-wohngebaeude?uid={ausweis.id}"
href="/energieausweis-erstellen/verbrauchsausweis-wohngebaeude?id={ausweis.id}"
>Bearbeiten</a>
{:else if ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe}
<a
class="button text-sm"
href="/energieausweis-erstellen/verbrauchsausweis-gewerbe?uid={ausweis.id}"
href="/energieausweis-erstellen/verbrauchsausweis-gewerbe?id={ausweis.id}"
>Bearbeiten</a>
{/if}
{/if}
@@ -326,12 +326,12 @@
{#if ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen}
<a
class="button text-sm"
href="/energieausweis-erstellen/verbrauchsausweis-wohngebaeude?uid={ausweis.id}"
href="/energieausweis-erstellen/verbrauchsausweis-wohngebaeude?id={ausweis.id}"
>Formular</a>
{:else if ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe}
<a
class="button text-sm"
href="/energieausweis-erstellen/verbrauchsausweis-gewerbe?uid={ausweis.id}"
href="/energieausweis-erstellen/verbrauchsausweis-gewerbe?id={ausweis.id}"
>Formular</a>
{/if}
{/if}
@@ -346,7 +346,7 @@
class="p-2 rounded-lg hover:bg-gray-200"
title="PDF Herunterladen"
target="_blank"
href="/pdf/ansichtsausweis?uid={ausweis.id}"
href="/pdf/ansichtsausweis?id={ausweis.id}"
>
<img src="/images/ausweis.webp" width="32" alt="Energieausweis">
</a>
@@ -354,7 +354,7 @@
class="p-2 rounded-lg hover:bg-gray-200"
title="PDF Herunterladen"
target="_blank"
href="/pdf/datenblatt?uid={ausweis.id}"
href="/pdf/datenblatt?id={ausweis.id}"
>
<img src="/images/datenblatt.webp" width="32" alt="Datenblatt">
</a>

View File

@@ -12,7 +12,7 @@
{@const bild = objekt.aufnahmen[0].bilder.find(bild => bild.kategorie === Enums.BilderKategorie.Gebaeude)}
{#if bild}
<img src="/bilder/{bild.uid}.jpg" class="w-full max-h-72 object-cover rounded-t-lg" alt="Gebäude">
<img src="/bilder/{bild.id}.jpg" class="w-full max-h-72 object-cover rounded-t-lg" alt="Gebäude">
{:else}
<img src="/placeholder.png" class="w-full max-h-72 object-cover rounded-t-lg" alt="Gebäude">
{/if}
@@ -29,14 +29,14 @@
<div class="border rounded-lg px-4 py-2">
<div class="flex flex-row justify-between items-center">
<span>Stand vom {moment(aufnahme.erstellungsdatum).format("DD.MM.YYYY")}</span>
<a href="/dashboard/aufnahme/{aufnahme.uid}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><OpenInNewWindow size={20}></OpenInNewWindow></a>
<a href="/dashboard/aufnahme/{aufnahme.id}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><OpenInNewWindow size={20}></OpenInNewWindow></a>
</div>
<div class="flex flex-row gap-2">
{#if aufnahme.verbrauchsausweise_wohnen.length > 0}
<a href="/dashboard/aufnahme/{aufnahme.uid}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><File size={20}></File></a>
<a href="/dashboard/aufnahme/{aufnahme.id}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><File size={20}></File></a>
{/if}
{#if aufnahme.verbrauchsausweise_gewerbe.length > 0}
<a href="/dashboard/aufnahme/{aufnahme.uid}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><File size={20}></File></a>
<a href="/dashboard/aufnahme/{aufnahme.id}" class="rounded-lg p-2 hover:bg-gray-100 transition-all"><File size={20}></File></a>
{/if}
</div>
</div>

View File

@@ -1,13 +1,13 @@
<script lang="ts">
import { Buffer } from "buffer";
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "./Ausweis/types.js";
import { Enums } from "#lib/client/prisma";
import { AufnahmeClient, BildClient, ObjektClient, VerbrauchsausweisWohnenClient } from "./Ausweis/types.js";
import { Enums } from "#lib/client/prisma.js";
import { openWindowWithPost } from "#lib/helpers/window.js";
export let ausweis: VerbrauchsausweisWohnenClient;
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let bilder: UploadedGebaeudeBild[];
export let bilder: BildClient[];
export let ausweisart: Enums.Ausweisart

View File

@@ -2,7 +2,7 @@
import UploadImages from "./UploadImages.svelte";
import type { Enums } from "#lib/client/prisma.js";
import { BedarfsausweisWohnenClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "./Ausweis/types.js";
import { RotateCounterClockwise, Trash, Upload } from "radix-svelte-icons";
import { Trash, Upload } from "radix-svelte-icons";
import { api } from "astro-typesafe-api/client";
import Cookies from "js-cookie";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
@@ -17,14 +17,14 @@
async function deleteImage(image: BildClient) {
await api.bild.DELETE.fetch({
uid: image.uid
id: image.id
}, {
headers: {
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
images = images.filter((x) => x.uid !== image.uid);
images = images.filter((x) => x.id !== image.id);
}
let upload: () => void;
@@ -37,7 +37,7 @@
{#if image.kategorie == kategorie}
<div class="relative group">
<img
src="/bilder/{image.uid}.jpg"
src="/bilder/{image.id}.jpg"
alt={kategorie}
class="h-full max-h-96 w-full rounded-lg border-2 group-hover:contrast-50 object-cover transition-all"
/>

View File

@@ -11,7 +11,6 @@
BedarfsausweisWohnenClient,
BildClient,
ObjektClient,
UploadedGebaeudeBild,
VerbrauchsausweisGewerbeClient,
VerbrauchsausweisWohnenClient,
} from "./Ausweis/types.js";
@@ -80,13 +79,13 @@
// Get the scaled-down data from the canvas in the desired output format and quality
const dataURL = canvas.toDataURL("image/jpeg", 0.8);
const { uid } = await api.bild.PUT.fetch({
const { id } = await api.bild.PUT.fetch({
data: dataURL,
kategorie,
name: file.name
})
images.push({ uid, kategorie });
images.push({ id, kategorie });
images = images;
if (i == Math.min(files.length, max) - 1) {

View File

@@ -23,7 +23,7 @@ const { title, user } = Astro.props;
const objekte = await prisma.objekt.findMany({
where: {
benutzer: {
uid: user.uid
id: user.id
}
},
take: 10,

View File

@@ -1,14 +1,11 @@
import { AufnahmeClient, BenutzerClient, BildClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016.js";
import { AufnahmeClient, BenutzerClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types.js";
import * as fs from "fs"
import { PDFDocument, rgb, StandardFonts, TextAlignment } from "pdf-lib";
import { PDFDocument, StandardFonts } from "pdf-lib";
import { xml2pdf } from "./elements/xml2pdf.js";
import moment from "moment";
import { Enums, Heizungsstatus } from "#lib/server/prisma.js";
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016 } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016.js";
import { fileURLToPath } from "url";
import { copyPage } from "./utils/copyPage.js";
import { PERSISTENT_DIR } from "#lib/server/constants.js";
/* -------------------------------- Pdf Tools ------------------------------- */

View File

@@ -1,4 +1,4 @@
import { AufnahmeClient, BenutzerClient, BildClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types.js";
import { AufnahmeClient, BenutzerClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types.js";
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016 } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016.js";
import { getEmpfehlungen } from "#lib/XML/getEmpfehlungen.js";
import { Enums } from "#lib/server/prisma.js";
@@ -8,8 +8,6 @@ import { PDFDocument, PDFFont, PDFImage, PDFPage, StandardFonts } from "pdf-lib"
import { addCheckMark } from "./utils/checkbox.js";
import { addText } from "./utils/text.js";
import { addAnsichtsausweisLabel, addDatumGEG } from "./utils/helpers.js";
import { PERSISTENT_DIR } from "#lib/server/constants.js";
import { fileURLToPath } from "url";
import { getS3File } from "#lib/s3.js";

33
src/lib/server/db.ts Normal file
View File

@@ -0,0 +1,33 @@
import { Aufnahme, Bild, Objekt, prisma, VerbrauchsausweisWohnen } from "./prisma.js";
export async function getVerbrauchsausweisWohnen(id: string): Promise<VerbrauchsausweisWohnen | null> {
return await prisma.verbrauchsausweisWohnen.findUnique({
where: {
id
}
})
}
export async function getAufnahme(id: string): Promise<Aufnahme | null> {
return await prisma.aufnahme.findUnique({
where: {
id
}
})
}
export async function getObjekt(id: string): Promise<Objekt | null> {
return await prisma.objekt.findUnique({
where: {
id
}
})
}
export async function getBilder(aufnahme_id: string): Promise<Bild[]> {
return await prisma.bild.findMany({
where: {
aufnahme_id
}
})
}

18
src/lib/tryCatch.ts Normal file
View File

@@ -0,0 +1,18 @@
// Types for the result object with discriminated union
type Success<T> = [T, null]
type Failure<E> = [null, E];
type Result<T, E = Error> = Success<T> | Failure<E>;
// Main wrapper function
export async function tryCatch<T, E = Error>(
promise: Promise<T>,
): Promise<Result<T, E>> {
try {
const data = await promise;
return [data, null];
} catch (error) {
return [null, error as E];
}
}

View File

@@ -24,7 +24,7 @@
BedarfsausweisWohnenClient,
BenutzerClient,
ObjektClient,
UploadedGebaeudeBild,
BildClient,
AufnahmeClient
} from "#components/Ausweis/types.js";
@@ -35,7 +35,7 @@
export let aufnahme: AufnahmeClient
export let user: BenutzerClient = {} as BenutzerClient;
export let ausweistyp: Enums.AusweisTyp
export let bilder: UploadedGebaeudeBild[] = []
export let bilder: BildClient[] = []
export let uid: string;
if (!uid && (!ausweis.updated_at || moment(localStorage.getItem("bedarfsausweis-wohnen.updated_at") || new Date()).isAfter(ausweis.updated_at))) {

View File

@@ -50,7 +50,6 @@
const result = await api.objekt.PUT.fetch({
adresse: objekt.adresse,
erstellungsdatum: new Date(),
latitude: 0,
longitude: 0,
ort: objekt.ort,
@@ -78,7 +77,7 @@
objekte.push({
...objekt,
aufnahmen: [],
uid: result.uid
id: result.id
})
objekt = {

View File

@@ -241,7 +241,7 @@
);
localStorage.clear();
window.location.href = `/speichern-erfolgreich?uid=${ausweis.id}`
window.location.href = `/speichern-erfolgreich?id=${ausweis.id}`
}
}

View File

@@ -14,7 +14,7 @@
import Bereich from "#components/labels/Bereich.svelte";
import StromVerbrauch from "#components/Ausweis/StromVerbrauch.svelte";
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types.js";
import { AufnahmeClient, ObjektClient, BildClient, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types.js";
import { BenutzerClient } from "#components/Ausweis/types.js";
import GebaeudeDaten from "#components/Ausweis/GebaeudeDaten.svelte";
import { Enums } from "#lib/client/prisma.js";
@@ -46,7 +46,7 @@
export let objekt: ObjektClient;
export let ausweistyp: Enums.AusweisTyp;
export let aufnahme: AufnahmeClient;
export let bilder: UploadedGebaeudeBild[];
export let bilder: BildClient[];
const ausweisart = Enums.Ausweisart.VerbrauchsausweisGewerbe
const anliegen = "Energieausweis erstellen";

View File

@@ -41,26 +41,24 @@
import Overlay from "#components/Overlay.svelte";
import AusweisGespeichertModule from "#modules/VerbrauchsausweisWohnen/AusweisGespeichertModule.svelte";
import type {
VerbrauchsausweisWohnenClient,
BenutzerClient,
UploadedGebaeudeBild,
ObjektClient,
AufnahmeClient,
BildClient,
} from "#components/Ausweis/types.js";
import { Enums } from "#lib/client/prisma.js";
import { Aufnahme, Enums, Objekt, VerbrauchsausweisWohnen } from "#lib/client/prisma.js";
import moment from "moment";
// TODO: Vom Server sollte ein volles Objekt kommen, dass alle Subobjekte enthält, weil es sonst zu Problemen führen kann
// wenn aufnahme oder objekt nicht existiert...
export let ausweis: VerbrauchsausweisWohnenClient;
export let objekt: ObjektClient
export let aufnahme: AufnahmeClient
export let user: BenutzerClient;
export let bilder: UploadedGebaeudeBild[];
export let ausweis: VerbrauchsausweisWohnen;
export let objekt: Objekt
export let aufnahme: Aufnahme
export let user: BenutzerClient | null;
export let bilder: BildClient[];
export let ausweistyp: Enums.AusweisTyp;
export let uid: string | null;
export let id: string | null;
if (!uid && (!ausweis.updated_at || moment(localStorage.getItem("verbrauchsausweis-wohnen.updated_at") || new Date()).isAfter(ausweis.updated_at))) {
// Falls die Daten im localStorage neuer sind als der Ausweis den wir von der Datenbank bekommen haben, benutzen wir lieber diese.
if (!id && (!ausweis.updated_at || moment(localStorage.getItem("verbrauchsausweis-wohnen.updated_at") || new Date()).isAfter(ausweis.updated_at))) {
const localStorageAusweis = localStorage.getItem("verbrauchsausweis-wohnen.ausweis");
if (localStorageAusweis) {
ausweis = JSON.parse(localStorageAusweis)
@@ -116,7 +114,7 @@ let skala: HTMLDivElement;
<Overlay bind:hidden={speichernOverlayHidden}>
<div class="bg-white w-full max-w-screen-sm py-8 px-8">
<AusweisGespeichertModule uid={ausweis.uid}></AusweisGespeichertModule>
<AusweisGespeichertModule uid={ausweis.id}></AusweisGespeichertModule>
</div>
</Overlay>

View File

@@ -5,7 +5,7 @@
ObjektClient,
AufnahmeClient,
BenutzerClient,
UploadedGebaeudeBild,
BildClient,
UnterlageClient,
GEGNachweisWohnenClient,
} from "#components/Ausweis/types.js";
@@ -21,7 +21,7 @@
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
export let user: BenutzerClient = {} as BenutzerClient;
export let bilder: UploadedGebaeudeBild[] = [];
export let bilder: BildClient[] = [];
export let plaene: UnterlageClient[] = [];
export let unterlagen: UnterlageClient[] = [];

View File

@@ -1,6 +1,6 @@
---
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
import { AufnahmeClient, GEGNachweisWohnenClient, ObjektClient, UnterlageClient, UploadedGebaeudeBild } from "#components/Ausweis/types";
import { AufnahmeClient, GEGNachweisWohnenClient, ObjektClient, UnterlageClient, BildClient } from "#components/Ausweis/types";
import { createCaller } from "src/astro-typesafe-api-caller";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js";
@@ -10,7 +10,7 @@ const uid = Astro.url.searchParams.get("uid");
let nachweis: GEGNachweisWohnenClient = {} as GEGNachweisWohnenClient;
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
let objekt: ObjektClient = {} as ObjektClient;
let bilder: UploadedGebaeudeBild[] = []
let bilder: BildClient[] = []
let unterlagen: UnterlageClient[] = []
const valid = validateAccessTokenServer(Astro);

View File

@@ -1,4 +1,4 @@
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, UUidWithPrefix, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { AufnahmeClient, ObjektClient, BildClient, UUidWithPrefix, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { filterAusweise } from "#lib/filters.js";
import { omit } from "#lib/helpers.js";
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
@@ -18,7 +18,7 @@ export const GET = defineApiRoute({
if (user.rolle !== Enums.BenutzerRolle.ADMIN) {
input.filters = input.filters || {}
input.filters["benutzer"] = {
uid: user.uid
id: user.id
}
}
@@ -43,7 +43,7 @@ export const GET = defineApiRoute({
ausweis: omit(ausweis, ["aufnahme"]) as VerbrauchsausweisWohnenClient,
aufnahme: omit(omit(ausweis.aufnahme, ["events"]), ["objekt"]) as AufnahmeClient,
objekt: omit(ausweis.aufnahme.objekt, ["bilder"]) as ObjektClient,
bilder: ausweis.aufnahme.bilder as unknown as UploadedGebaeudeBild[],
bilder: ausweis.aufnahme.bilder as unknown as BildClient[],
events: ausweis.aufnahme.events
}))
},

View File

@@ -1,5 +1,5 @@
---
import { AufnahmeClient, BenutzerClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { AufnahmeClient, BenutzerClient, ObjektClient, BildClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import UserLayout from "#layouts/DashboardLayout.astro";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import { omit } from "#lib/helpers";
@@ -31,7 +31,7 @@ if (user.rolle !== Enums.BenutzerRolle.ADMIN) {
const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
where: {
benutzer: {
uid: user.uid
id: user.id
}
},
include: {
@@ -50,7 +50,7 @@ const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
const totalPages = await prisma.verbrauchsausweisWohnen.count({
where: {
benutzer: {
uid: user.uid
id: user.id
}
}
})
@@ -59,7 +59,7 @@ const reformedAusweise = ausweise.map(ausweis => ({
ausweis: omit(ausweis, ["aufnahme"]) as VerbrauchsausweisWohnenClient,
aufnahme: omit(omit(ausweis.aufnahme, ["events"]), ["objekt"]) as AufnahmeClient,
objekt: omit(ausweis.aufnahme.objekt, ["bilder"]) as ObjektClient,
bilder: ausweis.aufnahme.bilder as unknown as UploadedGebaeudeBild[],
bilder: ausweis.aufnahme.bilder as unknown as BildClient[],
events: ausweis.aufnahme.events
}))
---

View File

@@ -6,7 +6,7 @@ import { Enums, prisma } from "#lib/server/prisma";
import UserLayout from "#layouts/DashboardLayout.astro";
import DashboardAufnahmeModule from "#modules/Dashboard/DashboardAufnahmeModule.svelte";
const { uid } = Astro.params;
const { id } = Astro.params;
const accessTokenValid = await validateAccessTokenServer(Astro);
@@ -30,10 +30,10 @@ if (!user) {
const aufnahme = await prisma.aufnahme.findUnique({
where: user.rolle === Enums.BenutzerRolle.USER ? {
benutzer: {
uid: user.uid
id: user.id
},
uid
} : { uid },
id
} : { id },
include: {
objekt: true,
bilder: true,

View File

@@ -26,7 +26,7 @@ if (!user) {
const totalPages = await prisma.objekt.count({
where: user.rolle === Enums.BenutzerRolle.USER ? {
benutzer: {
uid: user.uid
id: user.id
}
} : {}
})
@@ -34,7 +34,7 @@ const totalPages = await prisma.objekt.count({
const objekte = await prisma.objekt.findMany({
where: user.rolle === Enums.BenutzerRolle.USER ? {
benutzer: {
uid: user.uid
id: user.id
},
} : {
...(id ? {OR: [

View File

@@ -2,25 +2,25 @@
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
import BedarfsausweisWohnenModule from "#modules/BedarfsausweisWohnen/BedarfsausweisWohnenModule.svelte";
import { AufnahmeClient, BedarfsausweisWohnenClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { AufnahmeClient, ObjektClient, BildClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { createCaller } from "src/astro-typesafe-api-caller";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
import { Enums } from "#lib/server/prisma";
const uid = Astro.url.searchParams.get("uid") || "";
const uid_aufnahme = Astro.url.searchParams.get("aufnahme")
const id = Astro.url.searchParams.get("uid") || "";
const aufnahme_id = Astro.url.searchParams.get("aufnahme")
const ausweistyp = Astro.url.searchParams.get("ausweistyp") || Enums.AusweisTyp.Standard;
let ausweis: VerbrauchsausweisWohnenClient = {} as VerbrauchsausweisWohnenClient;
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
let objekt: ObjektClient = {} as ObjektClient;
let bilder: UploadedGebaeudeBild[] = []
let bilder: BildClient[] = []
const valid = validateAccessTokenServer(Astro);
const caller = createCaller(Astro);
if (uid) {
if (id) {
if (!valid) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
@@ -28,39 +28,39 @@ if (uid) {
}
try {
ausweis = await caller["bedarfsausweis-wohnen"]._uid.GET.fetch(null, {
ausweis = await caller["bedarfsausweis-wohnen"]._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid
id
}
});
aufnahme = await caller.aufnahme._uid.GET.fetch(null, {
aufnahme = await caller.aufnahme._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: ausweis.uid_aufnahme
id: ausweis.aufnahme_id
}
})
objekt = await caller.objekt._uid.GET.fetch(null, {
objekt = await caller.objekt._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: ausweis.uid_objekt
id: ausweis.objekt_id
}
})
bilder = await caller.aufnahme._uid.bilder.GET.fetch(null, {
bilder = await caller.aufnahme._id.bilder.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: ausweis.uid_aufnahme
id: ausweis.aufnahme_id
}
})
@@ -81,5 +81,5 @@ if (uid) {
---
<AusweisLayout title="Bedarfsausweis erstellen | IBCornelsen">
<BedarfsausweisWohnenModule client:only {ausweis} {objekt} {aufnahme} {bilder} {ausweistyp} {uid}></BedarfsausweisWohnenModule>
<BedarfsausweisWohnenModule client:only {ausweis} {objekt} {aufnahme} {bilder} {ausweistyp} {id}></BedarfsausweisWohnenModule>
</AusweisLayout>

View File

@@ -1,26 +1,26 @@
---
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types";
import { AufnahmeClient, ObjektClient, BildClient, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types";
import { createCaller } from "src/astro-typesafe-api-caller";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
import VerbrauchsausweisGewerbeModule from "#modules/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbeModule.svelte";
import { Enums } from "#lib/server/prisma";
const uid = Astro.url.searchParams.get("uid");
const uid_aufnahme = Astro.url.searchParams.get("aufnahme")
const id = Astro.url.searchParams.get("uid");
const aufnahme_id = Astro.url.searchParams.get("aufnahme")
const ausweistyp = Astro.url.searchParams.get("ausweistyp") || Enums.AusweisTyp.Standard;
let ausweis: VerbrauchsausweisGewerbeClient = {} as VerbrauchsausweisGewerbeClient;
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
let objekt: ObjektClient = {} as ObjektClient;
let bilder: UploadedGebaeudeBild[] = []
let bilder: BildClient[] = []
const valid = validateAccessTokenServer(Astro);
const caller = createCaller(Astro);
if (uid) {
if (id) {
if (!valid) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
@@ -28,41 +28,41 @@ if (uid) {
}
try {
let { uid_aufnahme, uid_objekt, uid_benutzer, ...result } = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(null, {
let { aufnahme_id, objekt_id, benutzer_id, ...result } = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid
id
}
});
ausweis = result
aufnahme = await caller.aufnahme._uid.GET.fetch(null, {
aufnahme = await caller.aufnahme._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: uid_aufnahme
id: aufnahme_id
}
})
objekt = await caller.objekt._uid.GET.fetch(null, {
objekt = await caller.objekt._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: uid_objekt
id: objekt_id
}
})
bilder = await caller.aufnahme._uid.bilder.GET.fetch(null, {
bilder = await caller.aufnahme._id.bilder.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: uid_aufnahme
id: aufnahme_id
}
})
@@ -78,30 +78,30 @@ if (uid) {
"/energieausweis-erstellen/verbrauchsausweis-gewerbe"
);
}
} else if (uid_aufnahme) {
} else if (aufnahme_id) {
if (!valid) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
);
}
let { uid_objekt, ...result} = await caller.aufnahme._uid.GET.fetch(null, {
let { objekt_id, ...result} = await caller.aufnahme._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: uid_aufnahme
id: aufnahme_id
}
})
aufnahme = result;
objekt = await caller.objekt._uid.GET.fetch(null, {
objekt = await caller.objekt._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: uid_objekt
id: objekt_id
}
})
}

View File

@@ -1,112 +1,85 @@
---
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
import VerbrauchsausweisWohnenModule from "#modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte";
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { createCaller } from "src/astro-typesafe-api-caller";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
import { Enums } from "#lib/server/prisma";
import { AufnahmeClient, BildClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { Aufnahme, Bild, Enums, Objekt, VerbrauchsausweisWohnen } from "#lib/server/prisma";
import { getAufnahme, getBilder, getObjekt, getVerbrauchsausweisWohnen } from "#lib/server/db";
import { getCurrentUser } from "#lib/server/user";
const id = Astro.url.searchParams.get("id");
const aufnahme_id = Astro.url.searchParams.get("aufnahme")
let ausweistyp = Astro.url.searchParams.get("ausweistyp") || Enums.AusweisTyp.Standard;
let ausweistyp = Astro.url.searchParams.get("ausweistyp") as Enums.AusweisTyp || Enums.AusweisTyp.Standard;
let ausweis: VerbrauchsausweisWohnenClient = {} as VerbrauchsausweisWohnenClient;
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
let objekt: ObjektClient = {} as ObjektClient;
let bilder: UploadedGebaeudeBild[] = []
let ausweis: VerbrauchsausweisWohnen = {} as VerbrauchsausweisWohnen;
let aufnahme: Aufnahme = {} as Aufnahme;
let objekt: Objekt = {} as Objekt;
let bilder: Bild[] = []
const valid = validateAccessTokenServer(Astro);
const caller = createCaller(Astro);
const user = await getCurrentUser(Astro)
if (id) {
if (!valid) {
if (!user) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
);
}
try {
ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id
}
});
ausweis = await getVerbrauchsausweisWohnen(id) as VerbrauchsausweisWohnen
ausweistyp = ausweis.ausweistyp
aufnahme = await caller.aufnahme._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id: ausweis.aufnahme_id
}
})
objekt = await caller.objekt._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id: ausweis.objekt_id
}
})
bilder = await caller.aufnahme._id.bilder.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id: ausweis.aufnahme_id
}
})
if (!ausweis) {
if (!ausweis || ausweis.benutzer_id !== user.id) {
// Der Ausweis scheint nicht zu existieren.
// Wir leiten auf die generische Ausweisseite ohne UID weiter.
// Wir leiten auf die generische Ausweisseite ohne ID weiter.
return Astro.redirect(
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
);
}
} catch(e) {
aufnahme = await getAufnahme(ausweis.aufnahme_id) as Aufnahme
if (!aufnahme) {
// Die Aufnahme existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren.
return Astro.redirect(
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
);
}
objekt = await getObjekt(aufnahme.objekt_id) as Objekt
if (!objekt) {
// Das Objekt existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren.
return Astro.redirect(
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
);
}
bilder = await getBilder(aufnahme.id);
} else if (aufnahme_id) {
if (!valid) {
if (!user) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
);
}
let { objekt_id, ...result} = await caller.aufnahme._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id: aufnahme_id
}
})
aufnahme = await getAufnahme(ausweis.aufnahme_id) as Aufnahme
aufnahme = result;
objekt = await caller.objekt._id.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
id: objekt_id
if (!aufnahme) {
// Die Aufnahme existiert wohl nicht.
return Astro.redirect(
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
);
}
objekt = await getObjekt(aufnahme.objekt_id) as Objekt
if (!objekt) {
// Das Objekt existiert nicht.
return Astro.redirect(
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
);
}
})
}
---
<AusweisLayout title="Verbrauchsausweis erstellen">
<VerbrauchsausweisWohnenModule client:only {ausweis} {objekt} {aufnahme} {bilder} {id} {ausweistyp} />
<VerbrauchsausweisWohnenModule client:only {ausweis} {objekt} {aufnahme} {bilder} {id} {ausweistyp} {user} />
</AusweisLayout>

View File

@@ -8,13 +8,13 @@ import { createCaller } from "src/astro-typesafe-api-caller.js";
import { getS3File } from "#lib/s3.js";
export const GET: APIRoute = async (Astro) => {
const uidAusweis = Astro.url.searchParams.get("uid");
const ausweis_id = Astro.url.searchParams.get("uid");
if (!uidAusweis) {
if (!ausweis_id) {
return new Response(null, { status: 404 });
}
const ausweisart = getAusweisartFromUUID(uidAusweis)
const ausweisart = getAusweisartFromUUID(ausweis_id)
const caller = createCaller(Astro);
@@ -25,18 +25,18 @@ export const GET: APIRoute = async (Astro) => {
let bilder: UploadedGebaeudeBild[] = []
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, {
params: {
uid: uidAusweis
id: ausweis_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
});
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, {
params: {
uid: uidAusweis
id: ausweis_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
@@ -49,18 +49,18 @@ export const GET: APIRoute = async (Astro) => {
return new Response(null, { status: 404 });
}
aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
aufnahme = await caller.aufnahme._id.GET.fetch(undefined, {
params: {
uid: ausweis.uid_aufnahme
id: ausweis.aufnahme_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
});
objekt = await caller.objekt._uid.GET.fetch(undefined, {
objekt = await caller.objekt._id.GET.fetch(undefined, {
params: {
uid: ausweis.uid_objekt
id: ausweis.objekt_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`

View File

@@ -27,18 +27,18 @@ export const GET: APIRoute = async (Astro) => {
let bilder: UploadedGebaeudeBild[] = []
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, {
params: {
uid: uidAusweis
id: uidAusweis
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
});
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, {
params: {
uid: uidAusweis
id: uidAusweis
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
@@ -51,18 +51,18 @@ export const GET: APIRoute = async (Astro) => {
return new Response(null, { status: 404 });
}
aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
aufnahme = await caller.aufnahme._id.GET.fetch(undefined, {
params: {
uid: ausweis.uid_aufnahme
id: ausweis.aufnahme_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
});
objekt = await caller.objekt._uid.GET.fetch(undefined, {
objekt = await caller.objekt._id.GET.fetch(undefined, {
params: {
uid: ausweis.uid_objekt
id: ausweis.objekt_id
},
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
@@ -80,9 +80,9 @@ export const GET: APIRoute = async (Astro) => {
// Dieser Ausweis wurde mit der alten Version erstellt, das PDF sollte bereits existieren.
pdf = await getS3File("ibc-pdfs", `ID_${ausweis.alte_ausweis_id}_Datenblatt.pdf`)
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
pdf = await pdfVerbrauchsausweisWohnen(ausweis as VerbrauchsausweisWohnenClient, aufnahme, objekt, bilder, user);
pdf = await pdfDatenblattVerbrauchsausweisWohnen(ausweis as VerbrauchsausweisWohnenClient, aufnahme, objekt, user, bilder);
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
pdf = await pdfVerbrauchsausweisGewerbe(ausweis as VerbrauchsausweisGewerbeClient, aufnahme, objekt, bilder, user);
pdf = await pdfDatenblattVerbrauchsausweisGewerbe(ausweis as VerbrauchsausweisGewerbeClient, aufnahme, objekt, user, bilder);
}
return new Response(pdf, {

View File

@@ -6,24 +6,19 @@ import { getPrismaAusweisAdapter } from "#lib/server/ausweis";
import { getCurrentUser } from "#lib/server/user";
const user = await getCurrentUser(Astro)
const uid = Astro.url.searchParams.get("uid");
const adapter = getPrismaAusweisAdapter(uid || "")
const id = Astro.url.searchParams.get("id");
const adapter = getPrismaAusweisAdapter(id || "")
console.log(user, uid);
if (!user || !uid || !adapter) {
if (!user || !id || !adapter) {
return Astro.redirect("/")
}
const ausweis = await adapter.findUnique({
where: {
uid
id
}
})
const id = ausweis.id;
if (!ausweis) {
return Astro.redirect("/")
}

View File

@@ -0,0 +1,85 @@
Verbrauchsausweis Wohnen
if Domain hat bereits eine vorhandene ID?
if LocalStorage hat Daten?
Wir vergleichen ob der LocalStorage neuer ist als die Datenbank
if LocalStorage is neuer?
Wir benutzen LocalStorage
else
Wir benutzen Daten aus der Datenbank.
else
Daten werden aus der Datenbank geladen.
else
if LocalStorage hat Daten?
Daten werden aus dem LocalStorage geladen.
else
Formular wird leer geliefert
Benutzer gibt Daten ein.
Wir speichern alles im LocalStorage mit dem aktuallen Timestamp
*User lädt ein Bild hoch*
if Ausweis hat bereits eine id
Wir verknüpfen das Bild sofort mit dem Ausweis
else
Wir laden das Bild hoch ohne es mit dem Ausweis zu verknüpfen
if *Klick auf Weiter || Klick auf Hilfe*
Wir leiten weiter auf Kundendaten mit dem entsprechenden Produkt
*User gibt Kundendaten ein*
if *Klick auf Speichern*
if Ausweis hat bereits eine id?
Wir updaten den bereits gespeicherten Ausweis mit den neuen Daten
else
if URL hat ein Objekt gegeben?
Wir updaten das Objekt
else
Wir erstellen ein neues Objekt
if URL hat eine Aufnahme gegeben?
Wir updaten die bestehende Aufnahme
else
Wir erstellen eine neue Aufnahme
Wir erstellen einen neuen Ausweis
else
*User klickt auf Bestellen*
if Ausweis hat bereits eine id?
Wir updaten den bereits gespeicherten Ausweis mit den neuen Daten
else
if URL hat ein Objekt gegeben?
Wir updaten das Objekt
else
Wir erstellen ein neues Objekt
if URL hat eine Aufnahme gegeben?
Wir updaten die bestehende Aufnahme
else
Wir erstellen eine neue Aufnahme
Wir erstellen einen neuen Ausweis
if Bezahlart === "Rechnung"
Wir erstellen eine Rechnung für den Ausweis und leiten auf die Payment Success Seite weiter.
else
Wir erstellen eine Rechnung für den Ausweis und holen uns die Checkout URL
while Bezahlung ist nicht erfolgreich
Wir leiten zurück auf die Kundendaten Seite zurück und fordern eine andere Bezahlart an.
Wir leiten auf die Payment Success Seite weiter und senden eine Email
elif *Klick auf Speichern*
if Ausweis hat bereits eine id?
Wir updaten den bereits gespeicherten Ausweis mit den neuen Daten
else
if URL hat ein Objekt gegeben?
Wir updaten das Objekt
else
Wir erstellen ein neues Objekt
if URL hat eine Aufnahme gegeben?
Wir updaten die bestehende Aufnahme
else
Wir erstellen eine neue Aufnahme
Wir erstellen einen neuen Ausweis