Dashboard
This commit is contained in:
@@ -13,17 +13,17 @@ import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
input: z.object({
|
||||
uid: z.string(),
|
||||
uid_ausweis: z.string(),
|
||||
}),
|
||||
output: z.void(),
|
||||
middleware: adminMiddleware,
|
||||
async fetch({ uid }, context, user) {
|
||||
async fetch({ uid_ausweis }, context, user) {
|
||||
const ausweisart = getAusweisartFromUUID(uid);
|
||||
|
||||
if (ausweisart === "VerbrauchsausweisWohnen") {
|
||||
const ausweis = await prisma.verbrauchsausweisWohnen.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
uid: uid_ausweis,
|
||||
},
|
||||
include: {
|
||||
aufnahme: {
|
||||
@@ -48,7 +48,9 @@ export const GET = defineApiRoute({
|
||||
|
||||
const rechnung = await prisma.rechnung.findFirst({
|
||||
where: {
|
||||
aufnahme_id: ausweis.aufnahme.id,
|
||||
verbrauchsausweis_wohnen: {
|
||||
uid: uid_ausweis
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
erstellt_am: "desc",
|
||||
|
||||
103
src/pages/api/admin/stornieren.ts
Normal file
103
src/pages/api/admin/stornieren.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { adminMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { mollieClient } from "#lib/mollie.js";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis.js";
|
||||
import { Prisma, prisma } from "@ibcornelsen/database/server";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.object({
|
||||
uid_ausweis: UUidWithPrefix
|
||||
}),
|
||||
middleware: adminMiddleware,
|
||||
async fetch(input, context, transfer) {
|
||||
const adapter = getPrismaAusweisAdapter(input.uid_ausweis) as Prisma.VerbrauchsausweisWohnenDelegate;
|
||||
|
||||
if (!adapter) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Ungültige 'uid_ausweis'"
|
||||
})
|
||||
}
|
||||
|
||||
const ausweis = await adapter.findUnique({
|
||||
where: {
|
||||
uid: input.uid_ausweis
|
||||
}
|
||||
})
|
||||
|
||||
if (!ausweis) {
|
||||
throw new APIError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Ausweis konnte nicht gefunden werden."
|
||||
})
|
||||
}
|
||||
|
||||
const response = await adapter.findUnique({
|
||||
where: {
|
||||
uid: input.uid_ausweis
|
||||
},
|
||||
select: {
|
||||
rechnung: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!response || !response.rechnung) {
|
||||
await adapter.update({
|
||||
where: {
|
||||
uid: input.uid_ausweis
|
||||
},
|
||||
data: {
|
||||
storniert: true
|
||||
}
|
||||
})
|
||||
|
||||
throw new APIError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Rechnung konnte nicht gefunden werden aber Ausweis wurde storniert."
|
||||
})
|
||||
}
|
||||
|
||||
const rechnung = response.rechnung;
|
||||
|
||||
await adapter.update({
|
||||
where: {
|
||||
uid: input.uid_ausweis
|
||||
},
|
||||
data: {
|
||||
storniert: true,
|
||||
rechnung: {
|
||||
update: {
|
||||
status: "canceled",
|
||||
storniert_am: new Date()
|
||||
}
|
||||
}
|
||||
},
|
||||
select: {
|
||||
rechnung: {
|
||||
select: {
|
||||
betrag: true,
|
||||
bezahlmethode: true,
|
||||
status: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (rechnung.betrag > 0 && rechnung.bezahlmethode !== "rechnung" && rechnung.status === "paid" && rechnung.transaktions_referenz) {
|
||||
const refund = await mollieClient.paymentRefunds.create({
|
||||
description: "Rückerstattung IBCornelsen",
|
||||
paymentId: rechnung.transaktions_referenz,
|
||||
amount: {
|
||||
currency: "EUR",
|
||||
value: rechnung.betrag.toFixed(2)
|
||||
},
|
||||
metadata: {
|
||||
rechnung_uid: rechnung.uid
|
||||
},
|
||||
testmode: true
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
46
src/pages/api/ausweise/index.ts
Normal file
46
src/pages/api/ausweise/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, 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";
|
||||
import { Enums, prisma, VerbrauchsausweisWohnenSchema } from "@ibcornelsen/database/server";
|
||||
import { defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
middleware: authorizationMiddleware,
|
||||
headers: authorizationHeaders,
|
||||
input: z.object({
|
||||
filters: filterAusweise.optional(),
|
||||
limit: z.number().optional(),
|
||||
skip: z.number().optional()
|
||||
}),
|
||||
async fetch(input, context, user) {
|
||||
const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
|
||||
where: {
|
||||
...input.filters,
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
},
|
||||
},
|
||||
include: {
|
||||
aufnahme: {
|
||||
include: {
|
||||
objekt: true,
|
||||
bilder: true,
|
||||
events: true
|
||||
}
|
||||
}
|
||||
},
|
||||
skip: input.skip || 0,
|
||||
take: Math.min(input.limit || 50, 50)
|
||||
})
|
||||
|
||||
return 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[],
|
||||
events: ausweis.aufnahme.events
|
||||
}))
|
||||
},
|
||||
})
|
||||
@@ -86,6 +86,7 @@ export const PUT = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Wir erstellen eine neue Rechnung in unserer Datenbank.
|
||||
const rechnung = await prisma.rechnung.create({
|
||||
data: {
|
||||
@@ -93,7 +94,11 @@ export const PUT = defineApiRoute({
|
||||
betrag,
|
||||
bezahlmethode: bezahlmethode,
|
||||
status: Enums.Rechnungsstatus.open,
|
||||
aufnahme_id: ausweis.aufnahme_id,
|
||||
verbrauchsausweis_wohnen: {
|
||||
connect: {
|
||||
uid: ausweis_uid
|
||||
}
|
||||
},
|
||||
services,
|
||||
ausweistyp
|
||||
},
|
||||
|
||||
@@ -9,6 +9,9 @@ import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
|
||||
const caller = createCaller(Astro)
|
||||
|
||||
const params = Astro.params;
|
||||
const page = Number(params.page)
|
||||
|
||||
|
||||
let user: BenutzerClient;
|
||||
try {
|
||||
@@ -34,14 +37,21 @@ const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
|
||||
include: {
|
||||
aufnahme: {
|
||||
include: {
|
||||
objekt: {
|
||||
include: {
|
||||
bilder: true,
|
||||
}
|
||||
},
|
||||
objekt: true,
|
||||
bilder: true,
|
||||
events: true
|
||||
}
|
||||
}
|
||||
},
|
||||
skip: (page - 1) * 10,
|
||||
take: 10
|
||||
})
|
||||
|
||||
const totalPages = await prisma.verbrauchsausweisWohnen.count({
|
||||
where: {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -55,5 +65,5 @@ const reformedAusweise = ausweise.map(ausweis => ({
|
||||
---
|
||||
|
||||
<UserLayout title="Ausweise Prüfen" {user}>
|
||||
<DashboardAusweisePruefenModule ausweise={reformedAusweise} client:load></DashboardAusweisePruefenModule>
|
||||
<DashboardAusweisePruefenModule totalPages={Math.ceil(totalPages / 10)} page={page} ausweise={reformedAusweise} client:load></DashboardAusweisePruefenModule>
|
||||
</UserLayout>
|
||||
3
src/pages/dashboard/admin/ausweise-pruefen/index.astro
Normal file
3
src/pages/dashboard/admin/ausweise-pruefen/index.astro
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
return Astro.redirect("/dashboard/admin/ausweise-pruefen/1")
|
||||
---
|
||||
@@ -2,11 +2,11 @@
|
||||
import { createCaller } from "../../../astro-typesafe-api-caller.js";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
import DashboardModule from "#modules/Dashboard/DashboardModule.svelte";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import Layout from "#layouts/Layout.astro";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
import DashboardObjektModule from "#modules/Dashboard/DashboardObjektModule.svelte";
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import DashboardAufnahmeModule from "#modules/Dashboard/DashboardAufnahmeModule.svelte";
|
||||
|
||||
const { uid } = Astro.params;
|
||||
|
||||
@@ -28,7 +28,7 @@ if (!user) {
|
||||
return Astro.redirect("/auth/login")
|
||||
}
|
||||
|
||||
const objekt = await prisma.objekt.findUnique({
|
||||
const aufnahme = await prisma.aufnahme.findUnique({
|
||||
where: {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
@@ -36,19 +36,24 @@ const objekt = await prisma.objekt.findUnique({
|
||||
uid
|
||||
},
|
||||
include: {
|
||||
objekt: true,
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
aufnahmen: {
|
||||
include: {
|
||||
bedarfsausweis_wohnen: true,
|
||||
verbrauchsausweis_gewerbe: true,
|
||||
verbrauchsausweis_wohnen: true
|
||||
}
|
||||
}
|
||||
bedarfsausweise_wohnen: true,
|
||||
verbrauchsausweise_gewerbe: true,
|
||||
verbrauchsausweise_wohnen: true,
|
||||
bedarfsausweise_gewerbe: true,
|
||||
geg_nachweise_gewerbe: true,
|
||||
geg_nachweise_wohnen: true,
|
||||
events: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!aufnahme) {
|
||||
return Astro.redirect("/dashboard")
|
||||
}
|
||||
---
|
||||
|
||||
<UserLayout title="Dashboard" {user}>
|
||||
<DashboardObjektModule {user} {objekt} client:only/>
|
||||
<DashboardAufnahmeModule {user} {aufnahme} objekt={aufnahme.objekt} client:only/>
|
||||
</UserLayout>
|
||||
@@ -1,20 +1,17 @@
|
||||
---
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { createCaller } from "#lib/caller";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
import DashboardEinstellungenModule from "#modules/Dashboard/DashboardEinstellungenModule.svelte";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
|
||||
const valid = await validateAccessTokenServer(Astro);
|
||||
const user = getCurrentUser(Astro)
|
||||
|
||||
if (!valid) {
|
||||
if (!user) {
|
||||
return Astro.redirect("/auth/login", 302);
|
||||
}
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
const benutzer = await caller.v1.benutzer.self();
|
||||
|
||||
---
|
||||
|
||||
<UserLayout title="Einstellungen">
|
||||
<DashboardEinstellungenModule benutzer={benutzer} client:load />
|
||||
<UserLayout title="Einstellungen" {user}>
|
||||
<DashboardEinstellungenModule benutzer={user} client:load />
|
||||
</UserLayout>
|
||||
@@ -36,9 +36,9 @@ const objekte = await prisma.objekt.findMany({
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
bedarfsausweis_wohnen: true,
|
||||
verbrauchsausweis_gewerbe: true,
|
||||
verbrauchsausweis_wohnen: true
|
||||
bedarfsausweise_wohnen: true,
|
||||
verbrauchsausweise_gewerbe: true,
|
||||
verbrauchsausweise_wohnen: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
---
|
||||
import Layout from "#layouts/Layout.astro";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
|
||||
|
||||
@@ -26,6 +26,6 @@ if (!ausweis || !user) {
|
||||
---
|
||||
|
||||
<AusweisLayout title="Kundendaten Aufnehmen - IBCornelsen">
|
||||
<KaufabschlussModule user={user} ausweis={ausweis} selectedPaymentType={Enums.Bezahlmethoden.paypal} client:load></KaufabschlussModule>
|
||||
<KaufabschlussModule user={user} ausweis={ausweis} aktiveBezahlmethode={Enums.Bezahlmethoden.paypal} client:load></KaufabschlussModule>
|
||||
</AusweisLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user