diff --git a/api/src/services/uploads/uploads.test.ts b/api/src/services/uploads/uploads.test.ts index be22f43e..74d30aaa 100644 --- a/api/src/services/uploads/uploads.test.ts +++ b/api/src/services/uploads/uploads.test.ts @@ -24,6 +24,7 @@ import { SubrecipientLambdaPayload, ProjectLambdaPayload, CreateArchiveLambdaPayload, + EmailLambdaPayload, } from './uploads' import type { StandardScenario } from './uploads.scenarios' @@ -336,6 +337,20 @@ describe('treasury report', () => { }, }, } + const emailPayload: EmailLambdaPayload = { + email: { + organization: { + id: mockOrganization.id, + preferences: { + current_reporting_period_id: mockReportingPeriod.id, + }, + }, + user: { + email: mockUser.email, + id: mockUser.id, + }, + }, + } const input = JSON.stringify({ '1A': {}, @@ -343,9 +358,11 @@ describe('treasury report', () => { '1C': {}, Subrecipient: {}, zip: {}, + email: {}, ...projectPayload, ...subrecipientPayload, ...zipPayload, + ...emailPayload, }) const result = await sendTreasuryReport() diff --git a/api/src/services/uploads/uploads.ts b/api/src/services/uploads/uploads.ts index 086fe6f8..38acc089 100644 --- a/api/src/services/uploads/uploads.ts +++ b/api/src/services/uploads/uploads.ts @@ -191,6 +191,10 @@ type InfoForSubrecipient = { type InfoForArchive = { organization: OrganizationObj } +type InfoForEmail = { + organization: OrganizationObj + user: UserObj +} /* This type should be similar to the following python class: class ProjectLambdaPayload(BaseModel): @@ -204,6 +208,7 @@ export type SubrecipientLambdaPayload = Record< InfoForSubrecipient > export type CreateArchiveLambdaPayload = Record<'zip', InfoForArchive> +export type EmailLambdaPayload = Record<'email', InfoForEmail> export const getUploadsByExpenditureCategory = async ( organization: Organization, @@ -343,6 +348,27 @@ export const getCreateArchiveLambdaPayload = async ( } } +export const getEmailLambdaPayload = async ( + organization: Organization, + user: CurrentUser +): Promise => { + return { + email: { + organization: { + id: organization.id, + preferences: { + current_reporting_period_id: + organization.preferences['current_reporting_period_id'], + }, + }, + user: { + email: user.email, + id: user.id, + }, + }, + } +} + export const sendTreasuryReport: MutationResolvers['sendTreasuryReport'] = async () => { try { @@ -363,15 +389,20 @@ export const sendTreasuryReport: MutationResolvers['sendTreasuryReport'] = const createArchiveLambdaPayload: CreateArchiveLambdaPayload = await getCreateArchiveLambdaPayload(organization) + const emailLambdaPayload: EmailLambdaPayload = + await getEmailLambdaPayload(organization, context.currentUser) + const input = { '1A': {}, '1B': {}, '1C': {}, Subrecipient: {}, zip: {}, + email: {}, ...projectLambdaPayload, ...subrecipientLambdaPayload, ...createArchiveLambdaPayload, + ...emailLambdaPayload, } await startStepFunctionExecution( diff --git a/terraform/treasury_generation_step_function.tf b/terraform/treasury_generation_step_function.tf index 695b82c7..c59d4485 100644 --- a/terraform/treasury_generation_step_function.tf +++ b/terraform/treasury_generation_step_function.tf @@ -123,6 +123,7 @@ module "treasury_generation_step_function" { }, "CreateTreasuryZipfile" : { "Type" : "Task", + "Next" : "SendSuccessEmail", "Resource" : "arn:aws:states:::lambda:invoke", "Parameters" : { "FunctionName" : module.lambda_function-cpfCreateArchive.lambda_function_arn, @@ -141,6 +142,27 @@ module "treasury_generation_step_function" { "BackoffRate" : 2 } ], + } + "SendSuccessEmail" : { + "Type" : "Task", + "Resource" : "arn:aws:states:::lambda:invoke", + "Parameters" : { + "FunctionName" : module.lambda_function-email-presigned-url.lambda_function_arn, + "Payload.$" : "$$.Execution.Input.email" + }, + "Retry" : [ + { + "ErrorEquals" : [ + "Lambda.ServiceException", + "Lambda.AWSLambdaException", + "Lambda.SdkClientException", + "Lambda.TooManyRequestsException" + ], + "IntervalSeconds" : 1, + "MaxAttempts" : 3, + "BackoffRate" : 2 + } + ], "End" : true } }