Skip to content

Commit

Permalink
Added partner name to the notification email
Browse files Browse the repository at this point in the history
  • Loading branch information
atGit2021 authored and CarsonF committed May 21, 2024
1 parent adcd2d7 commit 2574adf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/components/project/project.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -61,6 +63,7 @@ export interface EmailNotification {
changedBy: Pick<User, 'id' | 'displayFirstName' | 'displayLastName'>;
project: Pick<Project, 'id' | 'modifiedAt' | 'name' | 'step' | 'type'>;
previousStep?: ProjectStep;
primaryPartnerName?: string | undefined;
}

const rolesThatCanBypassWorkflow: Role[] = [Role.Administrator];
Expand All @@ -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,
Expand Down Expand Up @@ -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<Organization> }>(
merge('org', {
name: 'name.value',
}).as('dto'),
)
.first();
return result?.dto ?? null;
}

private async getEmailNotificationObject(
changedById: ID,
projectId: ID,
Expand Down Expand Up @@ -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,
};
}
}
5 changes: 5 additions & 0 deletions src/core/email/templates/project-step-changed.template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function ProjectStepChanged({
changedBy,
previousStep: oldStepVal,
recipient,
primaryPartnerName,
}: StepChangeNotification) {
const projectUrl = useFrontendUrl(`/projects/${project.id}`);
const projectName = project.name.value;
Expand Down Expand Up @@ -65,6 +66,10 @@ export function ProjectStepChanged({
/>
<br />
Project Type: {project.type}
<br />
{primaryPartnerName ? (
<>Primary Partner: {primaryPartnerName}</>
) : null}
</Text>
<HideInText>
<Button href={projectUrl} paddingTop={16}>
Expand Down

0 comments on commit 2574adf

Please sign in to comment.