Skip to content

Instantly share code, notes, and snippets.

@anderson-marques
Last active May 25, 2021 23:24
Show Gist options
  • Save anderson-marques/cc47de76fe12f00b1efc42a2be9dbc04 to your computer and use it in GitHub Desktop.
Save anderson-marques/cc47de76fe12f00b1efc42a2be9dbc04 to your computer and use it in GitHub Desktop.
import { SendWelcomeMessageInteractor } from "../marketing/control/send-welcome-message";
import { CustomerEventNames, CreateCustomerEvent } from "../customer/entity/customer-event";
import { S3PutEvent, S3PutEventEntry } from "../s3/entity/put-event-entry";
import { DataLakeGateway } from "../datalake/boundary/datalake-gateway";
const dataLakeGateway = DataLakeGateway.newInstance();
const sendWelcomeMessageInteractor = SendWelcomeMessageInteractor.newInstance();
const extractEventIdAndEventName = (
s3PutEventEntry: S3PutEventEntry
): { eventId: string; eventName: string } => {
const eventKeyTokens: Array<string> = s3PutEventEntry.s3.object.key.split(
"/"
);
const eventName = eventKeyTokens[0];
const eventId = eventKeyTokens[1];
return { eventId, eventName };
};
export const handler = async (s3PutEvent: S3PutEvent): Promise<void> => {
for (const s3PutEventEntry of s3PutEvent.Records) {
const { eventId, eventName } = extractEventIdAndEventName(
s3PutEventEntry
);
if (eventName === CustomerEventNames.CUSTOMER_CREATED) {
const eventPayload:CreateCustomerEvent = await dataLakeGateway.getEvent<CreateCustomerEvent>(eventid);
const { customerEmail } = eventPayload;
await sendWelcomeMessageInteractor.call(customerEmail};
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment