Skip to content

Commit

Permalink
PIN-5796 agreement notification (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor-K authored Dec 11, 2024
1 parent 43e007e commit 1f89b64
Show file tree
Hide file tree
Showing 11 changed files with 1,949 additions and 1,014 deletions.
89 changes: 53 additions & 36 deletions packages/agreement-email-sender/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { runConsumer } from "kafka-iam-auth";
import { EachMessagePayload } from "kafkajs";
import {
EmailManagerPEC,
EmailManagerSES,
ReadModelRepository,
buildHTMLTemplateService,
decodeKafkaMessage,
Expand All @@ -17,27 +19,36 @@ import {
unsafeBrandId,
} from "pagopa-interop-models";
import { P, match } from "ts-pattern";
import { readModelServiceBuilder } from "./services/readModelService.js";
import {
sendAgreementActivationEmail,
senderAgreementSubmissionEmail,
} from "./services/agreementEmailSenderService.js";

import { config } from "./config/config.js";

const sesEmailManager = initSesMailManager(config);
const pecEmailManager = initPecEmailManager({
smtpAddress: config.smtpAddress,
smtpPort: config.smtpPort,
smtpSecure: config.smtpSecure,
smtpUsername: config.smtpUsername,
smtpPassword: config.smtpPassword,
});
import { agreementEmailSenderServiceBuilder } from "./services/agreementEmailSenderService.js";
import { readModelServiceBuilder } from "./services/readModelService.js";

const readModelService = readModelServiceBuilder(
ReadModelRepository.init(config)
);
const templateService = buildHTMLTemplateService();
const interopFeBaseUrl = config.interopFeBaseUrl;
const sesEmailManager: EmailManagerSES = initSesMailManager(config);
const sesEmailsenderData = {
label: config.senderLabel,
mail: config.senderLabel,
};

const pecEmailManager: EmailManagerPEC = initPecEmailManager(config);
const pecEmailsenderData = {
label: config.pecSenderLabel,
mail: config.pecSenderMail,
};

const agreementEmailSenderService = agreementEmailSenderServiceBuilder(
pecEmailManager,
pecEmailsenderData,
sesEmailManager,
sesEmailsenderData,
readModelService,
templateService,
interopFeBaseUrl
);

export async function processMessage({
message,
Expand All @@ -61,17 +72,16 @@ export async function processMessage({
{ event_version: 2, type: "AgreementActivated" },
async ({ data: { agreement } }) => {
if (agreement) {
await sendAgreementActivationEmail({
agreementV2: agreement,
readModelService,
emailManager: pecEmailManager,
sender: {
label: config.pecSenderLabel,
mail: config.pecSenderMail,
},
templateService,
logger: loggerInstance,
});
await Promise.all([
agreementEmailSenderService.sendAgreementActivationCertifiedEmail(
agreement,
loggerInstance
),
agreementEmailSenderService.sendAgreementActivationSimpleEmail(
agreement,
loggerInstance
),
]);
} else {
throw missingKafkaMessageDataError("agreement", decodedMessage.type);
}
Expand All @@ -81,15 +91,23 @@ export async function processMessage({
{ event_version: 2, type: "AgreementSubmitted" },
async ({ data: { agreement } }) => {
if (agreement) {
await senderAgreementSubmissionEmail({
agreementV2: agreement,
readModelService,
emailManager: sesEmailManager,
feBaseUrl: config.interopFeBaseUrl,
sender: { label: config.senderLabel, mail: config.senderMail },
templateService,
logger: loggerInstance,
});
await agreementEmailSenderService.sendAgreementSubmissionSimpleEmail(
agreement,
loggerInstance
);
} else {
throw missingKafkaMessageDataError("agreement", decodedMessage.type);
}
}
)
.with(
{ event_version: 2, type: "AgreementRejected" },
async ({ data: { agreement } }) => {
if (agreement) {
await agreementEmailSenderService.sendAgreementRejectSimpleEmail(
agreement,
loggerInstance
);
} else {
throw missingKafkaMessageDataError("agreement", decodedMessage.type);
}
Expand All @@ -111,7 +129,6 @@ export async function processMessage({
"AgreementSuspendedByProducer",
"AgreementSuspendedByConsumer",
"AgreementSuspendedByPlatform",
"AgreementRejected",
"AgreementConsumerDocumentAdded",
"AgreementConsumerDocumentRemoved",
"AgreementSetDraftByPlatform",
Expand Down
Loading

0 comments on commit 1f89b64

Please sign in to comment.