This commit is contained in:
Moritz Utcke
2025-03-07 16:24:24 -03:00
parent 096f325292
commit c4de916057
3 changed files with 24 additions and 20 deletions

View File

@@ -1,3 +1,4 @@
import Sqids from "sqids";
import { writable, Writable } from "svelte/store"; import { writable, Writable } from "svelte/store";
import { ZodEffects, ZodNullable, ZodOptional, ZodType } from "zod"; import { ZodEffects, ZodNullable, ZodOptional, ZodType } from "zod";
@@ -57,4 +58,9 @@ export function getZodBaseType(schema: ZodType<any>): ZodType<any> {
return getZodBaseType(schema._def.schema) return getZodBaseType(schema._def.schema)
} }
return schema; return schema;
} }
export const sqids = new Sqids({
alphabet: "0123456789abcdefghijklmnopqrstuvw",
minLength: 8
})

View File

@@ -6,9 +6,11 @@ import {
Enums, Enums,
Rechnung, Rechnung,
VerbrauchsausweisWohnen, VerbrauchsausweisWohnen,
} from "#lib/client/prisma"; } from "#lib/client/prisma.js";
import { prisma } from "#lib/server/prisma"; import { prisma } from "#lib/server/prisma.js";
import { getAnsichtsausweis } from "../ausweis.js"; import { getAnsichtsausweis } from "../ausweis.js";
import Mail from "nodemailer/lib/mailer/index.js";
import { sqids } from "#client/lib/helpers.js";
export async function sendInvoiceMail( export async function sendInvoiceMail(
ausweis: VerbrauchsausweisWohnen, ausweis: VerbrauchsausweisWohnen,
@@ -33,7 +35,7 @@ export async function sendInvoiceMail(
const ausweisart = getAusweisartFromUUID(ausweis.uid); const ausweisart = getAusweisartFromUUID(ausweis.uid);
const attachments: any[] = []; const attachments: Mail.Attachment[] = [];
if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) { if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) {
const ansichtsausweis = await getAnsichtsausweis( const ansichtsausweis = await getAnsichtsausweis(
@@ -46,15 +48,15 @@ export async function sendInvoiceMail(
); );
if (ansichtsausweis) { if (ansichtsausweis) {
attachments.push([ attachments.push(
{ {
filename: "Ansichtsausweis.pdf", filename: `ID_${ausweis.id}_Ansichtsausweis.pdf`,
encoding: "binary", encoding: "binary",
content: Buffer.from(ansichtsausweis), content: Buffer.from(ansichtsausweis),
contentType: "application/pdf", contentType: "application/pdf",
contentDisposition: "attachment", contentDisposition: "attachment",
}, },
]); );
} }
} }
@@ -62,7 +64,7 @@ export async function sendInvoiceMail(
attachments, attachments,
from: `"IBCornelsen" <info@online-energieausweis.org>`, from: `"IBCornelsen" <info@online-energieausweis.org>`,
to: user.email, to: user.email,
subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.uid})`, subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.id})`,
cc: { cc: {
address: rechnung.email || "", address: rechnung.email || "",
name: rechnung.empfaenger || "", name: rechnung.empfaenger || "",

View File

@@ -8,18 +8,14 @@ import {
} from "#lib/client/prisma.js"; } from "#lib/client/prisma.js";
import { prisma } from "#lib/server/prisma.js"; import { prisma } from "#lib/server/prisma.js";
import { getAnsichtsausweis } from "../ausweis.js"; import { getAnsichtsausweis } from "../ausweis.js";
import Sqids from "sqids"; import { sqids } from "#client/lib/helpers.js";
import Mail from "nodemailer/lib/mailer/index.js";
export async function sendPaymentSuccessMail( export async function sendPaymentSuccessMail(
ausweis: VerbrauchsausweisWohnen, ausweis: VerbrauchsausweisWohnen,
rechnung: Rechnung, rechnung: Rechnung,
user: Benutzer user: Benutzer
) { ) {
const sqids = new Sqids({
alphabet: "0123456789abcdefghijklmnopqrstuvw",
minLength: 8
})
const aufnahme = await prisma.aufnahme.findUnique({ const aufnahme = await prisma.aufnahme.findUnique({
where: { where: {
id: ausweis.aufnahme_id, id: ausweis.aufnahme_id,
@@ -36,7 +32,7 @@ export async function sendPaymentSuccessMail(
let info: string = ""; let info: string = "";
const ausweisart = getAusweisartFromUUID(ausweis.uid); const ausweisart = getAusweisartFromUUID(ausweis.uid);
const attachments: any[] = []; const attachments: Mail.Attachment[] = [];
if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) { if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) {
const ansichtsausweis = await getAnsichtsausweis( const ansichtsausweis = await getAnsichtsausweis(
@@ -49,15 +45,15 @@ export async function sendPaymentSuccessMail(
); );
if (ansichtsausweis) { if (ansichtsausweis) {
attachments.push([ attachments.push(
{ {
filename: "Ansichtsausweis.pdf", filename: `ID_${ausweis.id}_Ansichtsausweis.pdf`,
encoding: "binary", encoding: "binary",
content: Buffer.from(ansichtsausweis), content: Buffer.from(ansichtsausweis),
contentType: "application/pdf", contentType: "application/pdf",
contentDisposition: "attachment", contentDisposition: "attachment",
}, }
]); );
} }
info = info =
"In der Regel erhalten Sie Ihren geprüften Ausweis innerhalb von 24 Stunden."; "In der Regel erhalten Sie Ihren geprüften Ausweis innerhalb von 24 Stunden.";
@@ -70,7 +66,7 @@ export async function sendPaymentSuccessMail(
attachments, attachments,
from: `"IBCornelsen" <info@online-energieausweis.org>`, from: `"IBCornelsen" <info@online-energieausweis.org>`,
to: user.email, to: user.email,
subject: `Bestellbestätigung vom IBCornelsen (ID: ${sqids.encode([ausweis.id])})`, subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.id})`,
cc: { cc: {
address: rechnung.email || "", address: rechnung.email || "",
name: rechnung.empfaenger || "", name: rechnung.empfaenger || "",