feat: integrate email event queue for payment confirmation with attachments
This commit is contained in:
parent
81337c852f
commit
b500c7133f
1 changed files with 106 additions and 69 deletions
|
|
@ -13,6 +13,7 @@ import {
|
|||
genPdfCondizioniBase64,
|
||||
genPdfRicevutaCortesiaBase64,
|
||||
} from "../services/puppeteer.service";
|
||||
import { addEventToQueue } from "./event_queue.controller";
|
||||
|
||||
export const stripeHealthCheck = async () => {
|
||||
try {
|
||||
|
|
@ -167,8 +168,11 @@ export const whIntentSucceededHandler = async ({
|
|||
})
|
||||
.execute();
|
||||
|
||||
//SERVIZIO ATTIVATO
|
||||
await NewMail({
|
||||
//TODO inserire gli allegati solo se si ha il pdf generato
|
||||
await addEventToQueue({
|
||||
data: {
|
||||
tipo: "email",
|
||||
data: {
|
||||
template: {
|
||||
mailType: "servizioAttivato",
|
||||
},
|
||||
|
|
@ -187,14 +191,21 @@ export const whIntentSucceededHandler = async ({
|
|||
},
|
||||
{
|
||||
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
|
||||
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
|
||||
content: await genPdfRicevutaCortesiaBase64(
|
||||
ordine.ordine_id,
|
||||
),
|
||||
encoding: "base64",
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
],
|
||||
},
|
||||
userId: utente.id,
|
||||
},
|
||||
},
|
||||
lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
|
||||
});
|
||||
//SERVIZIO ATTIVATO
|
||||
|
||||
break;
|
||||
|
||||
case OrderTypeEnum.Saldo:
|
||||
|
|
@ -207,7 +218,10 @@ export const whIntentSucceededHandler = async ({
|
|||
isOkSaldo: true,
|
||||
})
|
||||
.execute();
|
||||
await NewMail({
|
||||
await addEventToQueue({
|
||||
data: {
|
||||
tipo: "email",
|
||||
data: {
|
||||
template: {
|
||||
mailType: "pagamentoConferma",
|
||||
},
|
||||
|
|
@ -217,14 +231,20 @@ export const whIntentSucceededHandler = async ({
|
|||
attachments: [
|
||||
{
|
||||
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
|
||||
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
|
||||
content: await genPdfRicevutaCortesiaBase64(
|
||||
ordine.ordine_id,
|
||||
),
|
||||
encoding: "base64",
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
],
|
||||
},
|
||||
userId: utente.id,
|
||||
},
|
||||
},
|
||||
lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
|
||||
});
|
||||
//PAGAMENTO SALDO CONFERMATO
|
||||
break;
|
||||
case OrderTypeEnum.Consulenza:
|
||||
await trx
|
||||
|
|
@ -234,7 +254,10 @@ export const whIntentSucceededHandler = async ({
|
|||
isOkConsulenza: true,
|
||||
})
|
||||
.execute();
|
||||
await NewMail({
|
||||
await addEventToQueue({
|
||||
data: {
|
||||
tipo: "email",
|
||||
data: {
|
||||
template: {
|
||||
mailType: "pagamentoConferma",
|
||||
},
|
||||
|
|
@ -244,18 +267,27 @@ export const whIntentSucceededHandler = async ({
|
|||
attachments: [
|
||||
{
|
||||
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
|
||||
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
|
||||
content: await genPdfRicevutaCortesiaBase64(
|
||||
ordine.ordine_id,
|
||||
),
|
||||
encoding: "base64",
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
],
|
||||
},
|
||||
userId: utente.id,
|
||||
},
|
||||
},
|
||||
lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
|
||||
});
|
||||
//CONSULENZA ATTIVATA
|
||||
break;
|
||||
case OrderTypeEnum.Altro:
|
||||
// TODO: Handle other types
|
||||
await NewMail({
|
||||
await addEventToQueue({
|
||||
data: {
|
||||
tipo: "email",
|
||||
data: {
|
||||
template: {
|
||||
mailType: "pagamentoConferma",
|
||||
},
|
||||
|
|
@ -265,13 +297,18 @@ export const whIntentSucceededHandler = async ({
|
|||
attachments: [
|
||||
{
|
||||
filename: `ricevuta_cortesia_${ordine.ordine_id}.pdf`,
|
||||
content: await genPdfRicevutaCortesiaBase64(ordine.ordine_id),
|
||||
content: await genPdfRicevutaCortesiaBase64(
|
||||
ordine.ordine_id,
|
||||
),
|
||||
encoding: "base64",
|
||||
contentType: "application/pdf",
|
||||
},
|
||||
],
|
||||
},
|
||||
userId: utente.id,
|
||||
},
|
||||
},
|
||||
lock_expires: new Date(Date.now() + 60 * 1000), // Lock for 1 minute
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue