Ausstellen
This commit is contained in:
2
.github/workflows/prod-pipeline.yml
vendored
2
.github/workflows/prod-pipeline.yml
vendored
@@ -1,8 +1,6 @@
|
|||||||
name: Production Pipeline
|
name: Production Pipeline
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
|
|||||||
@@ -280,3 +280,51 @@ export async function createInvoice(
|
|||||||
voucherNumber: abfrage_response["voucherNumber"],
|
voucherNumber: abfrage_response["voucherNumber"],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ládt das Reechnungs PDF von LexOffice runter.
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @async
|
||||||
|
* @param {Rechnung} rechnung
|
||||||
|
* @returns {ArrayBuffer}
|
||||||
|
* @throws Falls eine der requests fehlschlägt.
|
||||||
|
*/
|
||||||
|
export async function getLexOfficeRechnung(rechnung: Rechnung) {
|
||||||
|
|
||||||
|
const response = await fetch(`https://api.lexoffice.io/v1/invoices/${rechnung.lex_office_id}/document`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Accept": `application/json`,
|
||||||
|
"Authorization": `Bearer ${LEX_OFFICE_API_KEY}`,
|
||||||
|
"Content-Type": `application/json`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const body = await response.json()
|
||||||
|
|
||||||
|
if(!("documentFileId" in body)){
|
||||||
|
throw new Error("documentFileId nicht in request.")
|
||||||
|
}
|
||||||
|
|
||||||
|
const file_id = body["documentFileId"];
|
||||||
|
|
||||||
|
|
||||||
|
const fileRequest = await fetch(`https://api.lexoffice.io/v1/files/${file_id}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Accept": `application/pdf`,
|
||||||
|
"Authorization": `Bearer ${LEX_OFFICE_API_KEY}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (fileRequest.status !== 200) {
|
||||||
|
throw new Error("File request hat nicht funktioniert.")
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await fileRequest.arrayBuffer()
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import { BASE_URI } from "#lib/constants.js";
|
|||||||
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
import { getAnsichtsausweis, getDatenblatt } from "#lib/server/ausweis.js";
|
||||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||||
import { s3Client } from "#lib/s3.js";
|
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 { tryCatch } from "#lib/tryCatch.js";
|
||||||
import {
|
import {
|
||||||
getBedarfsausweisWohnenKomplett,
|
getBedarfsausweisWohnenKomplett,
|
||||||
@@ -121,32 +121,60 @@ export const GET = defineApiRoute({
|
|||||||
ausweis.aufnahme.objekt.benutzer
|
ausweis.aufnahme.objekt.benutzer
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pdfAusweis) {
|
const pdfRechnung = await getLexOfficeRechnung(rechnung);
|
||||||
const command = new PutObjectCommand({
|
|
||||||
Bucket: "ibc-pdfs",
|
|
||||||
Key: `ID_${ausweis.id}_Energieausweis.pdf`,
|
|
||||||
Body: pdfAusweis,
|
|
||||||
ACL: "private",
|
|
||||||
});
|
|
||||||
|
|
||||||
await s3Client.send(command);
|
if (!pdfAusweis) {
|
||||||
|
throw new APIError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message: "Ausweis PDF konnte nicht generiert werden."
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdfDatenblatt) {
|
if (!pdfDatenblatt) {
|
||||||
const command = new PutObjectCommand({
|
throw new APIError({
|
||||||
Bucket: "ibc-pdfs",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
Key: `ID_${ausweis.id}_Datenblatt.pdf`,
|
message: "Datenblatt PDF konnte nicht generiert werden."
|
||||||
Body: pdfDatenblatt,
|
})
|
||||||
ACL: "private",
|
|
||||||
});
|
|
||||||
|
|
||||||
await s3Client.send(command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (rechnung.status === Enums.Rechnungsstatus.paid) {
|
||||||
text = `
|
html = `
|
||||||
<p>Sehr geehrte*r ${user.vorname} ${user.name},</p>
|
<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>
|
<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
|
fax 040 · 209339859
|
||||||
</p>`;
|
</p>`;
|
||||||
} else {
|
} else {
|
||||||
text = `
|
html = `
|
||||||
<p>Sehr geehrte*r ${user.vorname} ${user.name},</p>
|
<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>
|
<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({
|
await transport.sendMail({
|
||||||
from: `"IBCornelsen" <info@online-energieausweis.org>`,
|
from: `"IBCornelsen" <info@online-energieausweis.org>`,
|
||||||
to: user.email,
|
to: user.email,
|
||||||
|
bcc: "info@online-energieausweis.org",
|
||||||
subject: `Ihr Originalausweis vom Ingenieurbüro Cornelsen (ID: ${ausweis.id})`,
|
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) {
|
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||||
|
|||||||
Reference in New Issue
Block a user