Update Jens #344

Merged
IB-Cornelsen merged 3 commits from main into Jens 2025-02-17 10:25:02 +00:00
31 changed files with 331 additions and 183 deletions

View File

@@ -39,7 +39,7 @@ bun link @ibcornelsen/database
PERSISTENT_DIR="${HOME}/persistent/${APP_NAME}";
mkdir -p $PERSISTENT_DIR;
# TODO: Wir legen hier die .env Datei an, die die SSL Zertifikate enthält.
# Wir legen hier die .env Datei an, die die SSL Zertifikate enthält.
rm -f ~/$APP_NAME/.env;
touch ~/$APP_NAME/.env;
echo "PRIVATE_KEY=$(cat /etc/letsencrypt/live/ibcornelsen.de/privkey.pem | base64 | tr -d '\n')" >> ~/$APP_NAME/.env;

View File

@@ -8,9 +8,9 @@ export const createCaller = createCallerFactory({
"auth/access-token": await import("../src/pages/api/auth/access-token.ts"),
"auth/forgot-password": await import("../src/pages/api/auth/forgot-password.ts"),
"auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"),
"bilder/[uid]": await import("../src/pages/api/bilder/[uid].ts"),
"bedarfsausweis-wohnen/[uid]": await import("../src/pages/api/bedarfsausweis-wohnen/[uid].ts"),
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
"bilder/[uid]": await import("../src/pages/api/bilder/[uid].ts"),
"objekt": await import("../src/pages/api/objekt/index.ts"),
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
"ticket": await import("../src/pages/api/ticket/index.ts"),

View File

@@ -5,7 +5,7 @@
//import Label from "#components/Label.svelte";
import { auditHeizungGebaeudeBaujahr } from "../Verbrauchsausweis/audits/HeizungGebaeudeBaujahr.js";
import { addNotification, deleteNotification } from "@ibcornelsen/ui";
import { addNotification, deleteNotification } from "#components/Notifications/shared.js";
import TagInput from "../TagInput.svelte";
import { Enums } from "@ibcornelsen/database/client";
import {

View File

@@ -86,22 +86,6 @@
}
}
$: {
console.log(month, year);
if ((availableDates.filter(date => date.month === month && date.year === year).length === 0) && typeof month === "number" && typeof year === "number") {
addNotification({
message: "Monat nicht verfügbar.",
subtext: "Der ausgewählte Monat ist in diesem Jahr nicht verfügbar, bitte wählen sie einen neuen Start Monat.",
dismissable: true,
type: "warning",
timeout: 0,
uid: "monat_nicht_verfuegbar",
selector: "select[name='energieverbrauch_zeitraum_monat']"
})
}
}
$: abweichung = auditVerbrauchAbweichung(ausweis, aufnahme);
</script>

View File

@@ -11,7 +11,6 @@
ObjektClient,
VerbrauchsausweisWohnenClient,
} from "./types.js";
import { addNotification } from "#components/Notifications/shared.js";
export let objekt: ObjektClient;
export let aufnahme: AufnahmeClient;
@@ -20,6 +19,7 @@
// Wir dürfen bis zu 4.5 Jahre alte Klimafaktoren benutzen, also nehmen wir alle Monate seitdem und generieren daraus die Auswahl.
// Allerdings müssen wir auch berücksichtigen, dass wir drei folgende Jahre brauchen, also
// kann der Nutzer nur 36 + 18 Monate zurückgehen.
let availableDates: {
year: number;
month: number;
@@ -62,8 +62,8 @@
fuelMap[fuel[0]].push(fuel[1]);
}
let month = ausweis.startdatum?.getMonth();
let year = ausweis.startdatum?.getFullYear();
let month = moment(ausweis.startdatum).month();
let year = moment(ausweis.startdatum).year();
$: {
if (typeof month === "number" && typeof year === "number") {
@@ -78,29 +78,6 @@
}
}
$: {
console.log(month, year);
if (
availableDates.filter(
(date) => date.month === month && date.year === year
).length === 0 &&
typeof month === "number" &&
typeof year === "number"
) {
addNotification({
message: "Monat nicht verfügbar.",
subtext:
"Der ausgewählte Monat ist in diesem Jahr nicht verfügbar, bitte wählen sie einen neuen Start Monat.",
dismissable: true,
type: "warning",
timeout: 0,
uid: "monat_nicht_verfuegbar",
selector: "select[name='energieverbrauch_zeitraum_monat']",
});
}
}
$: abweichung = auditVerbrauchAbweichung(ausweis, aufnahme);
</script>

View File

@@ -2,27 +2,31 @@
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016.js";
import moment from "moment";
import {
AufnahmeClient,
getAusweisartFromUUID,
ObjektClient,
UploadedGebaeudeBild,
VerbrauchsausweisWohnenClient,
} from "./Ausweis/types.js";
import AusweisPruefenTooltip from "./AusweisPruefenTooltip.svelte";
import { addNotification } from "./NotificationProvider/shared.js";
import { CheckCircled, CrossCircled, Image } from "radix-svelte-icons";
import ChevronDown from "radix-svelte-icons/src/lib/icons/ChevronDown.svelte";
import { Event } from "@ibcornelsen/database/client";
export let ausweis: VerbrauchsausweisWohnenClient;
export let aufnahme: AufnahmeClient;
export let objekt: ObjektClient;
export let bilder: UploadedGebaeudeBild[]
export let events: Event[]
export let calculations: Awaited<
ReturnType<typeof endEnergieVerbrauchVerbrauchsausweis_2016>
>;
console.log(ausweis);
const aufnahme = ausweis.aufnahme
const ausweisArt = "VA"; // TODO: Das ist ein Platzhalter, hier muss die Ausweisart aus dem Ausweisobjekt kommen
const images = ausweis.aufnahme.objekt.gebaeude_bilder;
const ausweisArt = getAusweisartFromUUID(ausweis.uid) // TODO: Das ist ein Platzhalter, hier muss die Ausweisart aus dem Ausweisobjekt kommen
let verbrauchWWGesamt_1 = "";
let verbrauchWWGesamt_2 = "";
@@ -145,13 +149,13 @@
) {
if (aufnahme.solarsystem_warmwasser) {
// Wenn Warmwasser enthalten und Anteil bekannt und Solarsystem
verbrauchWWGesamt_1 = `${calculations?.energieVerbrauchGesamt_1} kWh x ${ausweis.anteil_warmwasser_1 / 100} x 0.6`;
verbrauchWWGesamt_2 = `${calculations?.energieVerbrauchGesamt_2} kWh x ${ausweis.anteil_warmwasser_2 / 100} x 0.6`;
verbrauchWWGesamt_1 = `${calculations?.energieVerbrauchGesamt_1} kWh x ${(ausweis.anteil_warmwasser_1 || 0) / 100} x 0.6`;
verbrauchWWGesamt_2 = `${calculations?.energieVerbrauchGesamt_2} kWh x ${(ausweis.anteil_warmwasser_2 || 0) / 100} x 0.6`;
solarsystemWarmwasser = "Solarsystem Warmwasser";
} else {
// Wenn Warmwasser enthalten und Anteil bekannt und **kein** Solarsystem
verbrauchWWGesamt_1 = `${calculations?.energieVerbrauchGesamt_1} kWh x ${ausweis.anteil_warmwasser_1 / 100} x 0.6`
verbrauchWWGesamt_2 = `${calculations?.energieVerbrauchGesamt_2} kWh x ${ausweis.anteil_warmwasser_2 / 100} x 0.6`
verbrauchWWGesamt_1 = `${calculations?.energieVerbrauchGesamt_1} kWh x ${(ausweis.anteil_warmwasser_1 || 0) / 100} x 0.6`
verbrauchWWGesamt_2 = `${calculations?.energieVerbrauchGesamt_2} kWh x ${(ausweis.anteil_warmwasser_2 || 0) / 100} x 0.6`
solarsystemWarmwasser = "kein Solarsystem Warmwasser";
}
} else {
@@ -674,13 +678,13 @@
<button class="btn btn-square" on:click={() => bilderModal.showModal()}><Image size={22}></Image></button>
<dialog bind:this={bilderModal} class="modal">
<div class="modal-box flex flex-row gap-4 items-center justify-center">
{#if images.length === 0}
{#if bilder.length === 0}
<div class="flex flex-col gap-4 items-center justify-center">
<p>Für diesen Ausweis sind noch keine Bilder vorhanden.</p>
<button class="btn btn-primary" tabindex="0">Erinnerung Verschicken</button>
</div>
{:else}
{#each images as image}
{#each bilder as image}
<div>
<h2 class="text-lg mb-4 font-bold">{image.kategorie}</h2>
<img src="/bilder/{image.uid}.webp">
@@ -837,7 +841,7 @@
</div>
<hr/>
</li>
{#each ausweis.aufnahme.events as event, i}
{#each events as event, i}
<li>
<hr />
<div class="timeline-middle">

View File

@@ -1,3 +1,7 @@
<script lang="ts">
</script>
<div class="dropdown dropdown-hover dropdown-bottom">
<div role="button" tabindex="0">
<slot></slot>

View File

@@ -1,5 +1,7 @@
<script lang="ts"></script>
<script lang="ts">
<div class="fixed right-8 bottom-8 max-w-[400px] flex flex-col gap-4 z-50">
</script>
<div class="fixed right-8 bottom-8 max-w-[400px] flex flex-col gap-4 z-50" {...$$restProps}>
<slot></slot>
</div>

View File

@@ -75,7 +75,7 @@
on:focusin={onFocusIn}
on:focusout={onFocusOut}
on:blur={() => {
if (tag.toString().length >= minlength && tag.toString().length < maxlength) {
if (tag.toString().length >= minlength && tag.toString().length <= maxlength) {
addTag(tag)
tag = ""
}

View File

@@ -1,20 +1,29 @@
import { ObjektClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import {
ObjektClient,
VerbrauchsausweisWohnenClient,
} from "#components/Ausweis/types.js";
import { AuditType, hidden } from "./hidden.js";
import { getKlimafaktoren } from "#lib/Klimafaktoren.js";
export async function auditKlimaFaktoren(ausweis: VerbrauchsausweisWohnenClient, gebaeude: ObjektClient): Promise<boolean> {
export async function auditKlimaFaktoren(
ausweis: VerbrauchsausweisWohnenClient,
gebaeude: ObjektClient
): Promise<boolean> {
if (hidden.has(AuditType.KLIMA_FAKTOREN)) {
return false;
}
if (ausweis.startdatum && gebaeude.plz && ausweis.verbrauch_1) {
try {
const response = await getKlimafaktoren(ausweis.startdatum, gebaeude.plz);
return true; // Alle Klimfaktoren konnten abgefragt werden.
} catch (e) {
return true;
if (ausweis.startdatum && gebaeude.plz && ausweis.verbrauch_1) {
try {
const response = await getKlimafaktoren(
ausweis.startdatum,
gebaeude.plz
);
return true; // Alle Klimfaktoren konnten abgefragt werden.
} catch (e) {
return true;
}
}
}
return false;
return false;
}

View File

@@ -2,7 +2,7 @@ import { AufnahmeClient } from "#components/Ausweis/types.js";
import { AuditType, hidden } from "./hidden.js";
export function auditLeerStand(gebaeude: AufnahmeClient): boolean {
if (gebaeude.leerstand && !hidden.has(AuditType.LEER_STAND)) {
if (gebaeude.leerstand) {
return (
(gebaeude.leerstand > 30)
);

View File

@@ -1,7 +1,7 @@
import { AufnahmeClient, ObjektClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { AufnahmeClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { AuditType, hidden } from "./hidden.js";
export function auditVerbrauchAbweichung(ausweis: VerbrauchsausweisWohnenClient, aufnahme: AufnahmeClient): number[] {
export function auditVerbrauchAbweichung(ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient, aufnahme: AufnahmeClient): number[] {
if (aufnahme.leerstand && (aufnahme.leerstand > 0)) {
return [];
}

View File

@@ -16,21 +16,25 @@ const { title } = Astro.props;
<script>
window.addEventListener("scroll", (event) => {
let scroll = window.scrollY;
const skala = document.getElementById("skala")
console.log(scroll);
if(scroll>=400){
document.getElementById('skala')?.classList.add('2xl:fixed','2xl:py-4','2xl:top-0','2xl:z-20');
document.getElementById('skala')?.classList.remove('w-full');
if (skala) {
skala.classList.add('2xl:fixed','2xl:py-4','2xl:top-0','2xl:z-20');
skala.classList.remove('w-full');
skala.style.borderBottom = "3px solid #e6e6e6";
}
document.getElementById('skala').style.borderBottom = "3px solid #e6e6e6";
const performanceBox = document.getElementById('performance-box')
if (performanceBox) {
performanceBox.style.maxWidth = "688.5px";
}
const progressBox = document.getElementById('progress-box');
document.getElementById('performance-box').style.maxWidth = "688.5px";
document.getElementById('progress-box').style.maxWidth = "688.5px";
if (progressBox) {
progressBox.style.maxWidth = "688.5px"
}
document.getElementById('formInput-1')?.classList.add('2xl:mt-[370px]');
@@ -38,11 +42,12 @@ console.log(scroll);
}else{
document.getElementById('skala')?.classList.remove('2xl:fixed','2xl:py-4','2xl:top-0','2xl:z-20');
document.getElementById('skala')?.classList.add('w-full');
if (skala) {
skala.classList.remove('2xl:fixed','2xl:py-4','2xl:top-0','2xl:z-20')
skala.classList.add('w-full')
skala.style.borderBottom = "none";
}
document.getElementById('skala').style.borderBottom = "none";
document.getElementById('formInput-1')?.classList.remove('2xl:mt-[370px]');

View File

@@ -15,20 +15,12 @@ if (!valid) {
Astro.redirect("/auth/login", 302)
}
const caller = createCaller(Astro)
const benutzer = (await caller.user.self.GET.fetch(undefined, {
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
})) || {} as BenutzerClient;
export interface Props {
title: string;
user: BenutzerClient
}
const { title } = Astro.props;
const { title, user } = Astro.props;
const schema = JSON.stringify({
"@context": "http://schema.org",
@@ -107,7 +99,7 @@ let lightTheme = Astro.cookies.get("theme")?.value === "light";
</head>
<body class="min-h-screen grid md:grid-cols-[300px_1fr]">
<DashboardSidebar lightTheme={lightTheme} {benutzer} client:load></DashboardSidebar>
<DashboardSidebar lightTheme={lightTheme} benutzer={user} client:load></DashboardSidebar>
<main class="p-4 md:p-8 overflow-auto h-screen bg-base-100 pt-20 md:!pt-24">
<slot />
</main>

View File

@@ -48,13 +48,15 @@
<span class="font-semibold">Falls sie ein Konto bei uns haben wurde eine Email an sie verschickt.</span>
</div>
{/if}
<button type="submit" class="btn btn-primary"
<button type="submit" class="button"
>Email zum Zurücksetzen des Passworts senden.</button
>
{#if showEmailSuccess}
<div class="flex-row justify-between" style="margin-top: 10px">
<a class="link link-hover"
href="/auth/login{redirect ? `?redirect=${redirect}` : ""}">Einloggen</a
>
</div>
{/if}
</form>
</div>

View File

@@ -70,14 +70,9 @@
required
/>
</div>
<button type="submit" class="btn btn-primary"
<button type="submit" class="button"
>Passwort zurückzusetzen</button
>
<div class="flex-row justify-between" style="margin-top: 10px">
<a class="link link-hover"
href="/auth/login">Einloggen</a
>
</div>
</form>
</div>

View File

@@ -1,18 +1,31 @@
<script lang="ts">
import {
AufnahmeClient,
ObjektClient,
UploadedGebaeudeBild,
VerbrauchsausweisWohnenClient,
} from "#components/Ausweis/types";
} from "#components/Ausweis/types.js";
import AusweisPruefenBox from "#components/AusweisPruefenBox.svelte";
import NotificationProvider from "#components/NotificationProvider/NotificationProvider.svelte";
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016";
import { endEnergieVerbrauchVerbrauchsausweis_2016 } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016.js";
import AusweisPruefenNotification from "#components/AusweisPruefenNotification.svelte";
import { Event } from "@ibcornelsen/database/client";
export let ausweise: VerbrauchsausweisWohnenClient[];
export let ausweise: {
ausweis: VerbrauchsausweisWohnenClient,
aufnahme: AufnahmeClient,
objekt: ObjektClient,
bilder: UploadedGebaeudeBild[],
events: Event[]
}[];
console.log(ausweise);
</script>
<div class="gap-4 flex flex-col">
{#each ausweise as ausweis}
{#await endEnergieVerbrauchVerbrauchsausweis_2016(ausweis)}
{#each ausweise as { ausweis, objekt, aufnahme, bilder, events }}
{#await endEnergieVerbrauchVerbrauchsausweis_2016(ausweis, aufnahme, objekt)}
<div class="rounded-lg border w-full h-20 p-2.5 gap-4 flex flex-row items-center">
<div class="w-1/12 h-full flex flex-col gap-2">
<div class="skeleton w-8 h-8 rounded-full"></div>
@@ -85,7 +98,7 @@
<div class="skeleton w-4 h-4"></div>
</div>
{:then calculations}
<AusweisPruefenBox {ausweis} {calculations}></AusweisPruefenBox>
<AusweisPruefenBox {ausweis} {aufnahme} {objekt} {bilder} {events} {calculations}></AusweisPruefenBox>
{/await}
{/each}
</div>

View File

@@ -3,9 +3,6 @@
export let user: BenutzerClient;
export let objekte: ObjektClient[];
console.log(objekte);
</script>
<h1 class="text-4xl font-medium my-8">Willkommen zurück, {user.vorname}!</h1>

View File

@@ -10,6 +10,7 @@
import { BenutzerClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
import { PRICES } from "#lib/constants.js";
import { RechnungClient } from "#components/Ausweis/types.js";
import { api } from "astro-typesafe-api/client";
export let user: BenutzerClient;
export let ausweis:
@@ -62,17 +63,21 @@
e.preventDefault();
// TODO
const response = await client.v1.rechnungen.erstellen.mutate({
const response = await api.rechnung.PUT.fetch({
...rechnung,
ausweisart: Enums.Ausweisart.VerbrauchsausweisWohnen,
uid: ausweis.uid,
ausweis_uid: ausweis.uid,
bezahlmethode: selectedPaymentType,
services: services
.filter((service) => service.selected)
.map((service) => service.id),
});
window.location.href = response.checkout_url;
if (selectedPaymentType === Enums.Bezahlmethoden.rechnung) {
window.location.href = `/payment/success?uid=${response.uid}`
} else {
window.location.href = response.checkout_url as string;
}
}
const priceTotal = services.reduce((acc, service) => {

View File

@@ -5,9 +5,6 @@
import Ansprechpartner from "#components/Ausweis/Ansprechpartner.svelte";
import Rechnungsadresse from "#components/Ausweis/Rechnungsadresse.svelte";
import Bezahlung from "#components/Ausweis/Bezahlung.svelte";
import Pruefung from "#components/Ausweis/Pruefung.svelte";
import type { Bezahlmethoden } from "@ibcornelsen/database/client";
import { Enums } from "@ibcornelsen/database/client";
import { dialogs } from "svelte-dialogs";
@@ -24,8 +21,7 @@
} from "#components/Ausweis/types.js";
import { validateAccessTokenClient } from "src/client/lib/validateAccessToken.js";
import { api } from "astro-typesafe-api/client";
import A10WaermequellenAnlagentechnikTrinkwarmwasser from "#components/Tabellen/A10WaermequellenAnlagentechnikTrinkwarmwasser.svelte";
export let user: BenutzerClient;
export let ausweis: VerbrauchsausweisWohnenClient;
export let aufnahme: AufnahmeClient;
@@ -143,13 +139,32 @@
Authorization: `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
}
})
window.location.href = checkout_url;
} catch(e) {
console.log(e);
if (bezahlmethode === Enums.Bezahlmethoden.rechnung) {
window.location.href = `/payment/success?uid=${uid}`
} else {
window.location.href = checkout_url as string;
}
} catch(e) {
}
}
/**
* TODO
* Ausschlusskriterien: Neubau, Modernisierung
Baujahr vor 1978, unsaniert und bis 4 Wohneinheiten /
Heizung jünger als 3 Jahre / Verbrauchsjahre unvollständig / Verbrauchsjahre nicht aktuell genug /
Klimafaktoren unvollständig /
Leerstand größer 30% /
Fehlende oder unvollständige Bilder (pro Abschnitt mindestens ein Bild) /
Fehlende Angaben zum Sanierungsstand (Bei F mindestens 2 Haken), (Bei G mindestens 1 Haken)
*/
let bestellenNichtMoeglich = false;
if (((ausweis.ausstellgrund === "Neubau" || ausweis.ausstellgrund === "Modernisierung") && aufnahme.baujahr_gebaeude[0] < 1978 && aufnahme.saniert === false && aufnahme.einheiten && aufnahme.einheiten > 4) || (new Date().getFullYear() - aufnahme.baujahr_heizung[0] < 3) || (!ausweis.verbrauch_1 || !ausweis.verbrauch_2 || !ausweis.verbrauch_3) || (aufnahme.leerstand && aufnahme.leerstand > 30)) {
bestellenNichtMoeglich = true
}
</script>
<div
@@ -270,7 +285,7 @@
<button class="button">Speichern</button>
<button class="button" data-cy="bestellen" on:click={bestellen}>kostenpflichtig bestellen</button>
<button class="button cursor-pointer" data-cy="bestellen" on:click={bestellen} >Kostenpflichtig bestellen</button>
</div>
</div>
</div>

View File

@@ -0,0 +1,13 @@
<script lang="ts">
import { RechnungClient } from "#components/Ausweis/types.js";
import { Enums } from "@ibcornelsen/database/client";
export let rechnung: RechnungClient;
</script>
<h1>Bestellbestätigung</h1>
{#if rechnung.bezahlmethode === Enums.Bezahlmethoden.rechnung}
<p>Vielen Dank für Ihre Bestellung. Wir haben Ihnen soeben eine E-Mail zugeschickt. Eine Rechnung bekommen Sie nach Abschluss der Dienstleistung zugeschickt.</p>
<p>Sie haben Rechnungszahlung ausgewählt. Wir haben Ihnen in der E-Mail unsere Bankverbindung zur Überweisung des Betrages aufgeführt. Bitte denken Sie daran die Belegnummer wie aufgeführt anzugeben. Alle anderen Zahloptionen stehen Ihnen auch zur Verfügung.</p>
{/if}

View File

@@ -1,8 +1,10 @@
<script lang="ts">
import { addNotification } from "@ibcornelsen/ui";
import { addNotification } from "#components/Notifications/shared.js";
import { CrossCircled } from "radix-svelte-icons";
import { fade } from "svelte/transition";
import { api } from "astro-typesafe-api/client";
import NotificationProvider from "#components/NotificationProvider/NotificationProvider.svelte";
import NotificationWrapper from "#components/Notifications/NotificationWrapper.svelte";
let passwort: string;
let email: string;
@@ -13,6 +15,16 @@
async function login(e: SubmitEvent) {
e.preventDefault()
if (passwort.length < 8) {
addNotification({
message: "Passwort muss mindestens 6 Zeichen enthalten.",
dismissable: true,
timeout: 3000,
type: "error"
})
return;
}
try {
const { uid } = await api.user.PUT.fetch({
email,
@@ -92,7 +104,7 @@
<span class="font-semibold">Da ist wohl etwas schiefgelaufen. Diese Email Adresse ist bereits in Benutzung, haben sie vielleicht bereits ein Konto bei uns?</span>
</div>
{/if}
<button type="submit" class="btn btn-primary"
<button type="submit" class="button"
>Registrieren</button
>
<div class="flex-row justify-between" style="margin-top: 10px">
@@ -102,4 +114,5 @@
<a class="link link-hover" href="/auth/passwort-vergessen{redirect ? `?redirect=${redirect}` : ""}">Passwort Vergessen?</a>
</div>
</form>
<NotificationWrapper></NotificationWrapper>
</div>

View File

@@ -51,6 +51,7 @@
AufnahmeClient,
} from "#components/Ausweis/types.js";
import { Enums } from "@ibcornelsen/database/client";
import { onMount } from "svelte";
// 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...
@@ -60,6 +61,27 @@
export let user: BenutzerClient = {} as BenutzerClient;
export let bilder: UploadedGebaeudeBild[] = []
if (Object.keys(ausweis).length === 0) {
const localStorageAusweis = localStorage.getItem("ausweis");
if (localStorageAusweis) {
ausweis = JSON.parse(localStorageAusweis)
}
}
if (Object.keys(aufnahme).length === 0) {
const localStorageAufnahme = localStorage.getItem("aufnahme");
if (localStorageAufnahme) {
aufnahme = JSON.parse(localStorageAufnahme)
}
}
if (Object.keys(objekt).length === 0) {
const localStorageObjekt = localStorage.getItem("objekt");
if (localStorageObjekt) {
objekt = JSON.parse(localStorageObjekt)
}
}
async function spaeterWeitermachen() {
// TODO FIX
// const result = await ausweisSpeichern(
@@ -144,6 +166,18 @@
let waitOverlayHidden = true;
let speichernOverlayHidden = true;
$: {
if (ausweis.uid && objekt.uid && aufnahme.uid) {
localStorage.setItem(ausweis.uid, JSON.stringify(ausweis))
localStorage.setItem(objekt.uid, JSON.stringify(objekt))
localStorage.setItem(aufnahme.uid, JSON.stringify(aufnahme))
} else {
localStorage.setItem("ausweis", JSON.stringify(ausweis))
localStorage.setItem("aufnahme", JSON.stringify(aufnahme))
localStorage.setItem("objekt", JSON.stringify(objekt))
}
}
$: {
if (
aufnahme.saniert &&
@@ -205,7 +239,7 @@ lg:grid-cols-2 lg:gap-x-6
<form id="formInput-1" on:submit={ausweisAbschicken} name="ausweis" data-test="ausweis">
<div id="formular-box" class="formular-boxen ring-0">
<!--<ButtonSpaeterHilfe {automatischAusfüllen} {spaeterWeitermachen} />-->
<ButtonSpaeterHilfe {automatischAusfüllen} {spaeterWeitermachen} />
<!-- A Prüfung der Ausweisart -->
@@ -302,7 +336,7 @@ lg:grid-cols-2 lg:gap-x-6
>
</div>
<ButtonWeiterHilfe {spaeterWeitermachen}
<ButtonWeiterHilfe
bind:ausweis
bind:bilder
bind:user
@@ -317,7 +351,7 @@ lg:grid-cols-2 lg:gap-x-6
</form>
<RawNotificationWrapper>
<RawNotificationWrapper class="fixed left-8 bottom-8 max-w-[400px] flex flex-col gap-4 z-50">
{#each Object.entries($notifications) as [uid, notification] (uid)}
<RawNotification notification={{ ...notification, uid }}>
{@html notification.subtext}
@@ -416,7 +450,8 @@ lg:grid-cols-2 lg:gap-x-6
dismissable: true,
onUserDismiss: () => {
hidden.add(AuditType.HEIZUNG_JUENGER_DREI_JAHRE);
objekt = objekt;
aufnahme = aufnahme;
},
type: "warning",
}}
@@ -440,6 +475,7 @@ lg:grid-cols-2 lg:gap-x-6
onUserDismiss: () => {
hidden.add(AuditType.ZEITRAUM_AKTUELL);
objekt = objekt;
ausweis = ausweis
},
type: "warning",
}}
@@ -463,6 +499,7 @@ lg:grid-cols-2 lg:gap-x-6
onUserDismiss: () => {
hidden.add(AuditType.KLIMA_FAKTOREN);
objekt = objekt;
ausweis = ausweis;
},
type: "warning",
}}
@@ -486,7 +523,7 @@ lg:grid-cols-2 lg:gap-x-6
dismissable: true,
onUserDismiss: () => {
hidden.add(AuditType.WOHN_FLAECHE);
objekt = objekt;
aufnahme = aufnahme;
},
type: "warning",
}}
@@ -506,7 +543,7 @@ lg:grid-cols-2 lg:gap-x-6
dismissable: true,
onUserDismiss: () => {
hidden.add(AuditType.WARM_WASSER);
objekt = objekt;
ausweis = ausweis;
},
type: "warning",
}}
@@ -522,11 +559,7 @@ lg:grid-cols-2 lg:gap-x-6
message: "Plausibilitätsprüfung",
timeout: 0,
uid: "LEER_STAND",
dismissable: true,
onUserDismiss: () => {
hidden.add(AuditType.LEER_STAND);
objekt = objekt;
},
dismissable: false,
type: "warning",
}}
>
@@ -536,7 +569,8 @@ lg:grid-cols-2 lg:gap-x-6
</RawNotification>
{/if}
{#if auditVerbrauchAbweichung(ausweis, aufnahme).length > 0}
{@const abweichung = auditVerbrauchAbweichung(ausweis, aufnahme)}
{#if abweichung.length > 0}
<RawNotification
notification={{
message: "Plausibilitätsprüfung",
@@ -546,17 +580,12 @@ lg:grid-cols-2 lg:gap-x-6
onUserDismiss: () => {
hidden.add(AuditType.VERBRAUCH_ABWEICHUNG);
objekt = objekt;
ausweis = ausweis;
},
type: "warning",
}}
>
Die Abweichung der Verbräuche zwischen Zeitraum {auditVerbrauchAbweichung(
ausweis,
aufnahme
)[0]} und {auditVerbrauchAbweichung(
ausweis,
aufnahme
)[1]} beträgt mehr als 30% und sie haben keinen Leerstand angegeben.
Die Abweichung der Verbräuche zwischen Zeitraum {abweichung[0]} und {abweichung[1]} beträgt mehr als 30% und sie haben keinen Leerstand angegeben.
Sind sie sich sicher, dass das stimmt?
</RawNotification>
{/if}

View File

@@ -37,7 +37,7 @@ export const PUT = defineApiRoute({
})
),
output: z.object({
checkout_url: z.string(),
checkout_url: z.string().optional(),
uid: UUidWithPrefix,
}),
headers: authorizationHeaders,
@@ -113,6 +113,10 @@ export const PUT = defineApiRoute({
});
}
if (bezahlmethode === Enums.Bezahlmethoden.rechnung) {
return { uid: rechnung.uid }
}
// Wir erstellen eine Mollie Payment Referenz.
const payment = await mollieClient.payments.create({
amount: {

View File

@@ -7,7 +7,7 @@ import { z } from "zod";
export const PUT = defineApiRoute({
input: z.object({
email: z.string().email(),
passwort: z.string().min(6),
passwort: z.string().min(8),
vorname: z.string(),
name: z.string()
}),

View File

@@ -1,31 +1,54 @@
import { createCaller } from "#lib/caller";
import { APIRoute } from "astro";
import { validate } from "uuid";
export const get: APIRoute = async ({params, cookies}) => {
const { uid } = params;
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js";
import { prisma } from "@ibcornelsen/database/server";
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
import { fileURLToPath } from "bun";
import * as fs from "fs";
if (!uid) {
return new Response("No uid provided", { status: 400 });
}
export const GET = defineApiRoute({
async fetch(input, context, transfer) {
const { uid } = context.params
const token = context.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
if (!validate(uid)) {
return new Response("Invalid uid", { status: 400 });
}
if (!token) {
throw new APIError({
code: "BAD_REQUEST",
message: "Invalid access token"
})
}
const caller = createCaller({ cookies })
const valid = validateAccessTokenServer(context);
const image = await caller.v1.bilder.getBase64({ uid })
if (!valid) {
throw new APIError({
code: "BAD_REQUEST",
message: "Invalid access token"
})
}
if (!image) {
return new Response("No image found", { status: 404 });
}
const image = await prisma.gebaeudeBilder.findUnique({
where: {
uid
}
})
const buffer = Buffer.from(image.base64, "base64");
if (!image) {
throw new APIError({
code: "NOT_FOUND",
message: "Image could not be found."
})
}
return new Response(buffer, {
headers: {
"Content-Type": "image/webp"
}
});
}
const path = fileURLToPath(new URL(`../../../../../persistent/images/${image.uid}.webp`, import.meta.url))
const base64 = fs.readFileSync(path, "base64")
const buffer = Buffer.from(base64, "base64");
return new Response(buffer, {
headers: {
"Content-Type": "image/webp"
}
});
},
})

View File

@@ -0,0 +1,59 @@
---
import { AufnahmeClient, BenutzerClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import UserLayout from "#layouts/UserLayout.astro";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import DashboardAusweisePruefenModule from "#modules/Dashboard/DashboardAusweisePruefenModule.svelte";
import { prisma } from "@ibcornelsen/database/server";
import { createCaller } from "src/astro-typesafe-api-caller";
const caller = createCaller(Astro)
let user: BenutzerClient;
try {
user = (await caller.user.self.GET.fetch(undefined, {
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
}
})) || {} as BenutzerClient;
} catch(e) {
return Astro.redirect("/auth/login")
}
const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
where: {
benutzer: {
uid: user.uid
}
},
include: {
aufnahme: {
include: {
objekt: {
include: {
gebaeude_bilder: true,
}
},
events: true
}
}
}
})
function omit(key: string, obj: Record<string, any>) {
const { [key]: omitted, ...rest } = obj;
return rest;
}
const reformedAusweise = ausweise.map(ausweis => ({
ausweis: omit("aufnahme", ausweis) as VerbrauchsausweisWohnenClient,
aufnahme: omit("objekt", omit("events", ausweis.aufnahme)) as AufnahmeClient,
objekt: omit("gebaeude_bilder", ausweis.aufnahme.objekt) as ObjektClient,
bilder: ausweis.aufnahme.objekt.gebaeude_bilder as unknown as UploadedGebaeudeBild[],
events: ausweis.aufnahme.events
}))
---
<UserLayout title="Ausweise Prüfen" {user}>
<DashboardAusweisePruefenModule ausweise={reformedAusweise} client:load></DashboardAusweisePruefenModule>
</UserLayout>

View File

@@ -25,6 +25,6 @@ const gebaeudeArray = await caller.objekt.GET.fetch({ limit: 5 }, {
});
---
<UserLayout title="Dashboard">
<UserLayout title="Dashboard" {user}>
<DashboardModule user={user} gebaeudeArray={gebaeudeArray} />
</UserLayout>

View File

@@ -76,5 +76,5 @@ if (uid) {
---
<AusweisLayout title="Verbrauchsausweis erstellen">
<VerbrauchsausweisWohnenModule client:load {ausweis} {objekt} {aufnahme} {bilder} />
<VerbrauchsausweisWohnenModule client:only {ausweis} {objekt} {aufnahme} {bilder} />
</AusweisLayout>

View File

@@ -88,6 +88,6 @@ if (!ausweis || !user) {
---
<AusweisLayout title="Kundendaten Aufnehmen - IBCornelsen">
<KundendatenModule {user} {ausweis} {objekt} {aufnahme} {ausweisart} selectedPaymentType={Enums.Bezahlmethoden.paypal} client:load></KundendatenModule>
<KundendatenModule {user} {ausweis} {objekt} {aufnahme} {ausweisart} bezahlmethode={Enums.Bezahlmethoden.paypal} client:load></KundendatenModule>
</AusweisLayout>

View File

@@ -1,15 +1,16 @@
---
import { prisma } from "@ibcornelsen/database/server";
import { Enums, prisma } from "@ibcornelsen/database/server";
import Layout from "../../layouts/Layout.astro";
import { createCaller } from "../../astro-typesafe-api-caller.js";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import PaymentSuccessModule from "#modules/PaymentSuccessModule.svelte";
const uid = Astro.url.searchParams.get("uid");
const { uid } = Astro.params;
const caller = createCaller(Astro)
const user = await caller.user.self.GET.fetch(undefined, {
headers: {
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
@@ -23,7 +24,9 @@ if (!uid || !user) {
const rechnung = await prisma.rechnung.findUnique({
where: {
uid: uid,
benutzer_id: user.id
benutzer: {
uid: user.uid
}
}
})
@@ -33,7 +36,7 @@ if (!rechnung) {
---
<Layout title="Zahlung Erfolgreich - IBCornelsen">
Supa! Hat geklappt ne!
{rechnung.uid}
<PaymentSuccessModule {rechnung}></PaymentSuccessModule>
</Layout>