From c4de916057563805b5401b26242d57cdf0e6e0d4 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Fri, 7 Mar 2025 16:24:24 -0300 Subject: [PATCH] Email ID --- src/client/lib/helpers.ts | 8 +++++++- src/lib/server/mail/invoice.ts | 16 +++++++++------- src/lib/server/mail/payment-success.ts | 20 ++++++++------------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/client/lib/helpers.ts b/src/client/lib/helpers.ts index e20fc762..8017ff52 100644 --- a/src/client/lib/helpers.ts +++ b/src/client/lib/helpers.ts @@ -1,3 +1,4 @@ +import Sqids from "sqids"; import { writable, Writable } from "svelte/store"; import { ZodEffects, ZodNullable, ZodOptional, ZodType } from "zod"; @@ -57,4 +58,9 @@ export function getZodBaseType(schema: ZodType): ZodType { return getZodBaseType(schema._def.schema) } return schema; -} \ No newline at end of file +} + +export const sqids = new Sqids({ + alphabet: "0123456789abcdefghijklmnopqrstuvw", + minLength: 8 + }) \ No newline at end of file diff --git a/src/lib/server/mail/invoice.ts b/src/lib/server/mail/invoice.ts index edd01b7a..96c95608 100644 --- a/src/lib/server/mail/invoice.ts +++ b/src/lib/server/mail/invoice.ts @@ -6,9 +6,11 @@ import { Enums, Rechnung, VerbrauchsausweisWohnen, -} from "#lib/client/prisma"; -import { prisma } from "#lib/server/prisma"; +} from "#lib/client/prisma.js"; +import { prisma } from "#lib/server/prisma.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( ausweis: VerbrauchsausweisWohnen, @@ -33,7 +35,7 @@ export async function sendInvoiceMail( const ausweisart = getAusweisartFromUUID(ausweis.uid); - const attachments: any[] = []; + const attachments: Mail.Attachment[] = []; if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) { const ansichtsausweis = await getAnsichtsausweis( @@ -46,15 +48,15 @@ export async function sendInvoiceMail( ); if (ansichtsausweis) { - attachments.push([ + attachments.push( { - filename: "Ansichtsausweis.pdf", + filename: `ID_${ausweis.id}_Ansichtsausweis.pdf`, encoding: "binary", content: Buffer.from(ansichtsausweis), contentType: "application/pdf", contentDisposition: "attachment", }, - ]); + ); } } @@ -62,7 +64,7 @@ export async function sendInvoiceMail( attachments, from: `"IBCornelsen" `, to: user.email, - subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.uid})`, + subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.id})`, cc: { address: rechnung.email || "", name: rechnung.empfaenger || "", diff --git a/src/lib/server/mail/payment-success.ts b/src/lib/server/mail/payment-success.ts index d97e21d2..b7a2833d 100644 --- a/src/lib/server/mail/payment-success.ts +++ b/src/lib/server/mail/payment-success.ts @@ -8,18 +8,14 @@ import { } from "#lib/client/prisma.js"; import { prisma } from "#lib/server/prisma.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( ausweis: VerbrauchsausweisWohnen, rechnung: Rechnung, user: Benutzer ) { - const sqids = new Sqids({ - alphabet: "0123456789abcdefghijklmnopqrstuvw", - minLength: 8 - }) - const aufnahme = await prisma.aufnahme.findUnique({ where: { id: ausweis.aufnahme_id, @@ -36,7 +32,7 @@ export async function sendPaymentSuccessMail( let info: string = ""; const ausweisart = getAusweisartFromUUID(ausweis.uid); - const attachments: any[] = []; + const attachments: Mail.Attachment[] = []; if (ausweisart != Enums.Ausweisart.BedarfsausweisWohnen) { const ansichtsausweis = await getAnsichtsausweis( @@ -49,15 +45,15 @@ export async function sendPaymentSuccessMail( ); if (ansichtsausweis) { - attachments.push([ + attachments.push( { - filename: "Ansichtsausweis.pdf", + filename: `ID_${ausweis.id}_Ansichtsausweis.pdf`, encoding: "binary", content: Buffer.from(ansichtsausweis), contentType: "application/pdf", contentDisposition: "attachment", - }, - ]); + } + ); } info = "In der Regel erhalten Sie Ihren geprüften Ausweis innerhalb von 24 Stunden."; @@ -70,7 +66,7 @@ export async function sendPaymentSuccessMail( attachments, from: `"IBCornelsen" `, to: user.email, - subject: `Bestellbestätigung vom IBCornelsen (ID: ${sqids.encode([ausweis.id])})`, + subject: `Bestellbestätigung vom IBCornelsen (ID: ${ausweis.id})`, cc: { address: rechnung.email || "", name: rechnung.empfaenger || "",