From 2574adf58584e0a4c4a97f2dd514613741940ecc Mon Sep 17 00:00:00 2001 From: Andre Turner Date: Mon, 13 May 2024 18:53:39 -0500 Subject: [PATCH] Added partner name to the notification email --- src/components/project/project.rules.ts | 48 ++++++++++++++++++- .../project-step-changed.template.tsx | 5 ++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/components/project/project.rules.ts b/src/components/project/project.rules.ts index bd53a2afbf..d3fdba6979 100644 --- a/src/components/project/project.rules.ts +++ b/src/components/project/project.rules.ts @@ -16,11 +16,13 @@ import { } from '~/common'; import { ConfigService, ILogger, Logger } from '~/core'; import { DatabaseService } from '~/core/database'; -import { ACTIVE, INACTIVE } from '~/core/database/query'; +import { ACTIVE, INACTIVE, merge } from '~/core/database/query'; import { AuthenticationService } from '../authentication'; import { withoutScope } from '../authorization/dto'; import { EngagementService } from '../engagement'; import { EngagementStatus } from '../engagement/dto'; +import { OrganizationService } from '../organization'; +import { Organization } from '../organization/dto'; import { UserService } from '../user'; import { User } from '../user/dto'; import { @@ -61,6 +63,7 @@ export interface EmailNotification { changedBy: Pick; project: Pick; previousStep?: ProjectStep; + primaryPartnerName?: string | undefined; } const rolesThatCanBypassWorkflow: Role[] = [Role.Administrator]; @@ -75,6 +78,7 @@ export class ProjectRules { private readonly projectService: ProjectService & {}, @Inject(forwardRef(() => EngagementService)) private readonly engagements: EngagementService & {}, + private readonly organizations: OrganizationService, @Inject(forwardRef(() => AuthenticationService)) private readonly auth: AuthenticationService & {}, private readonly configService: ConfigService, @@ -1099,6 +1103,35 @@ export class ProjectRules { return result.steps; } + async getPrimaryOrganizationByProjectId(id: ID) { + const result = await this.db + .query() + .match([ + node('project', 'Project', { id }), + relation('out', '', 'partnership', ACTIVE), + node('partnership', 'Partnership'), + relation('out', '', 'primary', ACTIVE), + node('primary', 'Property', { value: true }), + ]) + .with('partnership') + .match([ + node('partnership'), + relation('out', '', 'partner', ACTIVE), + node('', 'Partner'), + relation('out', '', 'organization', ACTIVE), + node('org', 'Organization'), + relation('out', '', 'name', ACTIVE), + node('name', 'Property'), + ]) + .return<{ dto: UnsecuredDto }>( + merge('org', { + name: 'name.value', + }).as('dto'), + ) + .first(); + return result?.dto ?? null; + } + private async getEmailNotificationObject( changedById: ID, projectId: ID, @@ -1135,11 +1168,24 @@ export class ProjectRules { recipientSession, ); + const organization = await this.getPrimaryOrganizationByProjectId( + projectId, + ); + let orgName; + if (organization) { + const org = await this.organizations.readOne( + organization.id, + recipientSession, + ); + orgName = org.name.value; + } + return { changedBy, project, recipient, previousStep, + primaryPartnerName: orgName, }; } } diff --git a/src/core/email/templates/project-step-changed.template.tsx b/src/core/email/templates/project-step-changed.template.tsx index a673834708..9a08cd4543 100644 --- a/src/core/email/templates/project-step-changed.template.tsx +++ b/src/core/email/templates/project-step-changed.template.tsx @@ -17,6 +17,7 @@ export function ProjectStepChanged({ changedBy, previousStep: oldStepVal, recipient, + primaryPartnerName, }: StepChangeNotification) { const projectUrl = useFrontendUrl(`/projects/${project.id}`); const projectName = project.name.value; @@ -65,6 +66,10 @@ export function ProjectStepChanged({ />
Project Type: {project.type} +
+ {primaryPartnerName ? ( + <>Primary Partner: {primaryPartnerName} + ) : null}