Kundendatenmodule - Daten speichern wenn nicht eingeloggt
This commit is contained in:
@@ -37,9 +37,9 @@ export const createCaller = createCallerFactory({
|
||||
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
|
||||
"verbrauchsausweis-wohnen/[id]": await import("../src/pages/api/verbrauchsausweis-wohnen/[id].ts"),
|
||||
"verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"),
|
||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||
"aufnahme/[id]/bilder": await import("../src/pages/api/aufnahme/[id]/bilder.ts"),
|
||||
"aufnahme/[id]": await import("../src/pages/api/aufnahme/[id]/index.ts"),
|
||||
"aufnahme/[id]/unterlagen": await import("../src/pages/api/aufnahme/[id]/unterlagen.ts"),
|
||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||
"objekt/[id]": await import("../src/pages/api/objekt/[id]/index.ts"),
|
||||
})
|
||||
15
src/client/lib/lesen.ts
Normal file
15
src/client/lib/lesen.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { Benutzer } from "#lib/client/prisma.js";
|
||||
import { api } from "astro-typesafe-api/client";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export async function benutzerLesen(benutzerId: string): Promise<Benutzer> {
|
||||
const benutzer = await api.user.GET.fetch({ id: benutzerId }
|
||||
, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
});
|
||||
|
||||
return benutzer[0];
|
||||
}
|
||||
@@ -33,6 +33,7 @@
|
||||
import { endEnergieVerbrauchVerbrauchsausweis_2016_Client } from "#lib/Berechnungen/VerbrauchsausweisWohnen/VerbrauchsausweisWohnen_2016_Client.js";
|
||||
import { endEnergieVerbrauchVerbrauchsausweisGewerbe_2016_Client } from "#lib/Berechnungen/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbe_2016_Client.js";
|
||||
import { benutzerSpeichern } from "#client/lib/speichern.js";
|
||||
import { benutzerLesen } from "#client/lib/lesen.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
|
||||
export let user: Partial<BenutzerClient>;
|
||||
@@ -240,7 +241,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function speichern() {
|
||||
async function speichern(authuser = null) {
|
||||
loginAction = speichern;
|
||||
if (!await validateAccessTokenClient()) {
|
||||
loginOverlayHidden = false;
|
||||
@@ -257,6 +258,10 @@
|
||||
result = await ausweisSpeichern(ausweis, objekt, aufnahme, bilder, unterlagen, ausweisart)
|
||||
}
|
||||
|
||||
if (authuser) {
|
||||
user = await benutzerLesen(authuser.id);
|
||||
}
|
||||
|
||||
let resultUser: Awaited<ReturnType<typeof benutzerSpeichern>> | Awaited<ReturnType<typeof benutzerSpeichern>> | null = null;
|
||||
const { passwort, ...baseUser } = impersonatedUser ?? user;
|
||||
|
||||
@@ -289,7 +294,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function bestellen() {
|
||||
async function bestellen(authuser = null) {
|
||||
if (!form.checkValidity()) {
|
||||
addNotification({
|
||||
dismissable: true,
|
||||
@@ -332,6 +337,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (authuser) {
|
||||
user = await benutzerLesen(authuser.id);
|
||||
}
|
||||
|
||||
let resultUser: Awaited<ReturnType<typeof benutzerSpeichern>> | Awaited<ReturnType<typeof benutzerSpeichern>> | null = null;
|
||||
const { passwort, ...baseUser } = impersonatedUser ?? user;
|
||||
|
||||
@@ -1104,7 +1113,7 @@ sm:grid-cols-[min-content_min-content_min-content] sm:justify-self-end sm:mt-8"
|
||||
|
||||
|
||||
|
||||
<button class="order-2 button" type="button" on:click={speichern}>Speichern</button>
|
||||
<button class="order-2 button" type="button" on:click={() => speichern()}>Speichern</button>
|
||||
|
||||
{#if rechnung && rechnung.status === "paid"}
|
||||
<!-- Von einer GEG Anfrage sollte man sowieso nicht noch mal auf die Kundendaten Seite gelangen, also brauchen wir das hier nicht. -->
|
||||
@@ -1112,7 +1121,7 @@ sm:grid-cols-[min-content_min-content_min-content] sm:justify-self-end sm:mt-8"
|
||||
class="order-1 sm:order-2 button cursor-pointer"
|
||||
data-cy="bestellen"
|
||||
type="button"
|
||||
on:click={bestellen}>Absenden</button
|
||||
on:click={() => bestellen()}>Absenden</button
|
||||
>
|
||||
{:else}
|
||||
{#if gegAnfrage}
|
||||
@@ -1127,7 +1136,7 @@ sm:grid-cols-[min-content_min-content_min-content] sm:justify-self-end sm:mt-8"
|
||||
class="order-1 sm:order-2 button cursor-pointer"
|
||||
data-cy="bestellen"
|
||||
type="button"
|
||||
on:click={bestellen}>Kostenpflichtig bestellen</button
|
||||
on:click={() => bestellen()}>Kostenpflichtig bestellen</button
|
||||
>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -38,7 +38,7 @@ export const POST = defineApiRoute({
|
||||
if (input.telefon) updateData.telefon = input.telefon;
|
||||
if (input.verified) updateData.telefon = input.verified;
|
||||
|
||||
//Admin may update other users
|
||||
//Only Admin can update other users
|
||||
if (user.rolle == Enums.BenutzerRolle.ADMIN && input.id != user.id) {
|
||||
updateData.id = input.id;
|
||||
} else if(user.rolle != Enums.BenutzerRolle.ADMIN && input.id != user.id){
|
||||
@@ -64,9 +64,14 @@ export const GET = defineApiRoute({
|
||||
email: z.string()
|
||||
})),
|
||||
output: z.array(BenutzerSchema),
|
||||
middleware: adminMiddleware,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, admin) {
|
||||
if ("id" in input) {
|
||||
//Only Admin can read other users
|
||||
if (admin.rolle != Enums.BenutzerRolle.ADMIN && input.id != admin.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await prisma.benutzer.findUnique({
|
||||
where: {
|
||||
id: input.id
|
||||
@@ -79,6 +84,11 @@ export const GET = defineApiRoute({
|
||||
|
||||
return [user];
|
||||
} else {
|
||||
//Only admin can read many users
|
||||
if (admin.rolle != Enums.BenutzerRolle.ADMIN ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const users = await prisma.benutzer.findMany({
|
||||
where: {
|
||||
email: {
|
||||
|
||||
Reference in New Issue
Block a user