Ausstellen
This commit is contained in:
@@ -18,7 +18,7 @@ import { BASE_URI } from "#lib/constants.js";
|
||||
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { s3Client } from "#lib/s3.js";
|
||||
import { createInvoice } from "#lib/server/invoice.js";
|
||||
import { createInvoice, getLexOfficeRechnung } from "#lib/server/invoice.js";
|
||||
import { tryCatch } from "#lib/tryCatch.js";
|
||||
import {
|
||||
getBedarfsausweisWohnenKomplett,
|
||||
@@ -121,32 +121,60 @@ export const GET = defineApiRoute({
|
||||
ausweis.aufnahme.objekt.benutzer
|
||||
);
|
||||
|
||||
if (pdfAusweis) {
|
||||
const command = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Energieausweis.pdf`,
|
||||
Body: pdfAusweis,
|
||||
ACL: "private",
|
||||
});
|
||||
const pdfRechnung = await getLexOfficeRechnung(rechnung);
|
||||
|
||||
await s3Client.send(command);
|
||||
if (!pdfAusweis) {
|
||||
throw new APIError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Ausweis PDF konnte nicht generiert werden."
|
||||
})
|
||||
}
|
||||
|
||||
if (pdfDatenblatt) {
|
||||
const command = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Datenblatt.pdf`,
|
||||
Body: pdfDatenblatt,
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
await s3Client.send(command);
|
||||
if (!pdfDatenblatt) {
|
||||
throw new APIError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Datenblatt PDF konnte nicht generiert werden."
|
||||
})
|
||||
}
|
||||
|
||||
let text: string;
|
||||
if (!pdfRechnung) {
|
||||
throw new APIError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Rechnungs PDF konnte nicht generiert werden."
|
||||
})
|
||||
}
|
||||
|
||||
const ausweisCommand = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Energieausweis.pdf`,
|
||||
Body: pdfAusweis,
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
await s3Client.send(ausweisCommand);
|
||||
|
||||
const datenblattCommand = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Datenblatt.pdf`,
|
||||
Body: pdfDatenblatt,
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
await s3Client.send(datenblattCommand);
|
||||
|
||||
const rechnungsCommand = new PutObjectCommand({
|
||||
Bucket: "ibc-pdfs",
|
||||
Key: `ID_${ausweis.id}_Rechnung.pdf`,
|
||||
Body: pdfDatenblatt,
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
await s3Client.send(rechnungsCommand);
|
||||
|
||||
let html: string;
|
||||
|
||||
if (rechnung.status === Enums.Rechnungsstatus.paid) {
|
||||
text = `
|
||||
html = `
|
||||
<p>Sehr geehrte*r ${user.vorname} ${user.name},</p>
|
||||
|
||||
<p>im Anhang finden Sie Ihren geprüften Energieusweis inkl. Rechnung als PDF-Datei. Den Rechnungsbetrag haben Sie bereits bezahlt. Vielen Dank.</p>
|
||||
@@ -173,7 +201,7 @@ fon 040 · 209339850
|
||||
fax 040 · 209339859
|
||||
</p>`;
|
||||
} else {
|
||||
text = `
|
||||
html = `
|
||||
<p>Sehr geehrte*r ${user.vorname} ${user.name},</p>
|
||||
|
||||
<p>im Anhang finden Sie Ihren geprüften Energieusweis inkl. Rechnung als PDF-Datei. Nachfolgend finden Sie unsere Bankverbindung. Bitte geben Sie als Verwendungszweck die Rechnungsnummer an (siehe unten). Vielen Dank.</p>
|
||||
@@ -229,8 +257,28 @@ fax 040 · 209339859
|
||||
await transport.sendMail({
|
||||
from: `"IBCornelsen" <info@online-energieausweis.org>`,
|
||||
to: user.email,
|
||||
bcc: "info@online-energieausweis.org",
|
||||
subject: `Ihr Originalausweis vom Ingenieurbüro Cornelsen (ID: ${ausweis.id})`,
|
||||
text,
|
||||
html,
|
||||
attachments: [{
|
||||
filename: `ID_${ausweis.id}_Ansichtsausweis.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfAusweis),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}, {
|
||||
filename: `ID_${ausweis.id}_Datenblatt.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfDatenblatt),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}, {
|
||||
filename: `ID_${ausweis.id}_Rechnung.pdf`,
|
||||
encoding: "binary",
|
||||
content: Buffer.from(pdfRechnung),
|
||||
contentType: "application/pdf",
|
||||
contentDisposition: "attachment",
|
||||
}]
|
||||
});
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
|
||||
Reference in New Issue
Block a user