Highlight und neue ID
This commit is contained in:
@@ -9,9 +9,10 @@ import {
|
||||
} from "#lib/middleware/authorization.js";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis.js";
|
||||
import { PRICES, SERVICES } from "#lib/constants.js";
|
||||
import { PRICES, SERVICES, VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { Rechnung } from "#lib/client/prisma.js";
|
||||
import { RechnungSchema } from "src/generated/zod/rechnung.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
meta: {
|
||||
@@ -24,7 +25,7 @@ export const PUT = defineApiRoute({
|
||||
input: z
|
||||
.object({
|
||||
ausweisart: z.nativeEnum(Enums.Ausweisart),
|
||||
ausweis_uid: UUidWithPrefix,
|
||||
ausweis_id: UUidWithPrefix,
|
||||
})
|
||||
.merge(
|
||||
RechnungSchema.omit({
|
||||
@@ -33,7 +34,6 @@ export const PUT = defineApiRoute({
|
||||
erstellt_am: true,
|
||||
id: true,
|
||||
status: true,
|
||||
uid: true,
|
||||
betrag: true,
|
||||
storniert_am: true,
|
||||
transaktions_referenz: true,
|
||||
@@ -41,7 +41,7 @@ export const PUT = defineApiRoute({
|
||||
),
|
||||
output: z.object({
|
||||
checkout_url: z.string().optional(),
|
||||
uid: UUidWithPrefix,
|
||||
id: UUidWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -49,9 +49,9 @@ export const PUT = defineApiRoute({
|
||||
// Wir erstellen eine Mollie Payment Referenz und eine neue Rechnung in unserer Datenbank, daraufhin geben
|
||||
// wir eine Checkout URL zurück auf die der Nutzer weitergeleitet werden kann.
|
||||
|
||||
const { ausweis_uid, ausweisart, bezahlmethode, services } = input;
|
||||
const { ausweis_id, ausweisart, bezahlmethode, services } = input;
|
||||
|
||||
const adapter = getPrismaAusweisAdapter(ausweis_uid);
|
||||
const adapter = getPrismaAusweisAdapter(ausweis_id);
|
||||
|
||||
if (!adapter) {
|
||||
throw new APIError({
|
||||
@@ -62,7 +62,7 @@ export const PUT = defineApiRoute({
|
||||
|
||||
const ausweis = await adapter.findUnique({
|
||||
where: {
|
||||
uid: ausweis_uid
|
||||
id: ausweis_id
|
||||
}
|
||||
})
|
||||
|
||||
@@ -87,18 +87,21 @@ export const PUT = defineApiRoute({
|
||||
betrag += servicePriceList[service]
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.Rechnung);
|
||||
|
||||
// Wir erstellen eine neue Rechnung in unserer Datenbank.
|
||||
let rechnung: Rechnung | null = null;
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
rechnung = await prisma.rechnung.create({
|
||||
data: {
|
||||
id,
|
||||
benutzer_id: user.id,
|
||||
betrag,
|
||||
bezahlmethode: bezahlmethode,
|
||||
status: Enums.Rechnungsstatus.open,
|
||||
verbrauchsausweis_wohnen: {
|
||||
connect: {
|
||||
uid: ausweis_uid
|
||||
id: ausweis_id
|
||||
}
|
||||
},
|
||||
services,
|
||||
@@ -107,13 +110,14 @@ export const PUT = defineApiRoute({
|
||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
rechnung = await prisma.rechnung.create({
|
||||
data: {
|
||||
id,
|
||||
benutzer_id: user.id,
|
||||
betrag,
|
||||
bezahlmethode: bezahlmethode,
|
||||
status: Enums.Rechnungsstatus.open,
|
||||
verbrauchsausweis_gewerbe: {
|
||||
connect: {
|
||||
uid: ausweis_uid
|
||||
id: ausweis_id
|
||||
}
|
||||
},
|
||||
services,
|
||||
@@ -122,13 +126,14 @@ export const PUT = defineApiRoute({
|
||||
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) {
|
||||
rechnung = await prisma.rechnung.create({
|
||||
data: {
|
||||
id,
|
||||
benutzer_id: user.id,
|
||||
betrag,
|
||||
bezahlmethode: bezahlmethode,
|
||||
status: Enums.Rechnungsstatus.open,
|
||||
bedarfsausweis_wohnen: {
|
||||
connect: {
|
||||
uid: ausweis_uid
|
||||
id: ausweis_id
|
||||
}
|
||||
},
|
||||
services,
|
||||
@@ -145,7 +150,7 @@ export const PUT = defineApiRoute({
|
||||
|
||||
await adapter.update({
|
||||
where: {
|
||||
uid: ausweis_uid
|
||||
id: ausweis_id
|
||||
},
|
||||
data: {
|
||||
bestellt: true
|
||||
@@ -153,7 +158,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
|
||||
if (bezahlmethode === Enums.Bezahlmethoden.rechnung) {
|
||||
return { uid: rechnung.uid }
|
||||
return { id }
|
||||
}
|
||||
|
||||
// Wir erstellen eine Mollie Payment Referenz.
|
||||
@@ -163,12 +168,12 @@ export const PUT = defineApiRoute({
|
||||
currency: "EUR",
|
||||
},
|
||||
metadata: {
|
||||
rechnung_uid: rechnung.uid,
|
||||
rechnung_id: rechnung.id,
|
||||
},
|
||||
method: input.bezahlmethode as PaymentMethod,
|
||||
description: "Verbrauchsausweis Wohnen 2016",
|
||||
redirectUrl: `https://ibcornelsen.de/payment/success?a=${ausweis.uid}&r=${rechnung.uid}`,
|
||||
webhookUrl: `http://ibcornelsen.de/api/webhooks/mollie?uid=${rechnung.uid}`,
|
||||
redirectUrl: `https://ibcornelsen.de/payment/success?a=${ausweis.id}&r=${rechnung.id}`,
|
||||
webhookUrl: `http://ibcornelsen.de/api/webhooks/mollie?uid=${rechnung.id}`,
|
||||
});
|
||||
|
||||
const checkoutUrl = payment.getCheckoutUrl();
|
||||
@@ -181,7 +186,7 @@ export const PUT = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
uid: rechnung.uid,
|
||||
id,
|
||||
checkout_url: checkoutUrl,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user