Skip to content

Commit

Permalink
Merge pull request #3207 from SeedCompany/1100-Controller-Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed May 10, 2024
2 parents ab7ad29 + 5bae9fb commit 12ccab3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/components/project/project.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ProjectStepTransition,
TransitionType,
} from './dto';
import { FinancialApproverRepository } from './financial-approver';
import { ProjectService } from './project.service';

type EmailAddress = string;
Expand Down Expand Up @@ -54,7 +55,7 @@ export interface EmailNotification {
'email' | 'displayFirstName' | 'displayLastName' | 'timezone'
>;
changedBy: Pick<User, 'id' | 'displayFirstName' | 'displayLastName'>;
project: Pick<Project, 'id' | 'modifiedAt' | 'name' | 'step'>;
project: Pick<Project, 'id' | 'modifiedAt' | 'name' | 'step' | 'type'>;
previousStep?: ProjectStep;
}

Expand All @@ -73,6 +74,7 @@ export class ProjectRules {
@Inject(forwardRef(() => AuthenticationService))
private readonly auth: AuthenticationService & {},
private readonly configService: ConfigService,
private readonly financialApproverRepo: FinancialApproverRepository,
// eslint-disable-next-line @seedcompany/no-unused-vars
@Logger('project:rules') private readonly logger: ILogger,
) {}
Expand All @@ -85,6 +87,10 @@ export class ProjectRules {
): Promise<StepRule> {
const mostRecentPreviousStep = (steps: ProjectStep[]) =>
this.getMostRecentPreviousStep(id, steps, changeset);
const financialApprovers = async () =>
(await this.financialApproverRepo.read(projectType)).map(
({ user }) => user.id,
);
const isMultiplication =
projectType === ProjectType.MultiplicationTranslation;

Expand Down Expand Up @@ -405,15 +411,15 @@ export class ProjectRules {
type: TransitionType.Approve,
label: 'Confirm Project 🎉',
notifiers: async () => [
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
'project_approval@tsco.org',
'projects@tsco.org',
],
},
],
getNotifiers: async () => [
...(await this.getProjectTeamUserIds(id)),
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
],
};
case ProjectStep.OnHoldFinanceConfirmation:
Expand All @@ -425,7 +431,7 @@ export class ProjectRules {
type: TransitionType.Approve,
label: 'Confirm Project 🎉',
notifiers: async () => [
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
'project_approval@tsco.org',
'projects@tsco.org',
],
Expand All @@ -443,7 +449,7 @@ export class ProjectRules {
],
getNotifiers: async () => [
...(await this.getProjectTeamUserIds(id)),
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
],
};
case ProjectStep.Active:
Expand Down Expand Up @@ -500,7 +506,7 @@ export class ProjectRules {
],
getNotifiers: async () => [
...(await this.getProjectTeamUserIds(id)),
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
'project_extension@tsco.org',
'project_revision@tsco.org',
],
Expand Down Expand Up @@ -598,7 +604,7 @@ export class ProjectRules {
],
getNotifiers: async () => [
...(await this.getProjectTeamUserIds(id)),
...(await this.getRoleEmails(Role.Controller)),
...(await financialApprovers()),
'project_extension@tsco.org',
'project_revision@tsco.org',
],
Expand Down Expand Up @@ -1046,22 +1052,6 @@ export class ProjectRules {
return users?.ids ?? [];
}

private async getRoleEmails(role: Role): Promise<string[]> {
const emails = await this.db
.query()
.match([
node('email', 'EmailAddress'),
relation('in', '', 'email', ACTIVE),
node('user', 'User'),
relation('out', '', 'roles', ACTIVE),
node('role', 'Property', { value: role }),
])
.return<{ emails: string[] }>('collect(email.value) as emails')
.first();

return emails?.emails ?? [];
}

/** Of the given steps which one was the most recent previous step */
private async getMostRecentPreviousStep(
id: ID,
Expand Down
2 changes: 2 additions & 0 deletions src/core/email/templates/project-step-changed.template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export function ProjectStepChanged({
value={project.modifiedAt}
timezone={recipient.timezone.value}
/>
<br />
Project Type: {project.type}
</Text>
<HideInText>
<Button href={projectUrl} paddingTop={16}>
Expand Down

0 comments on commit 12ccab3

Please sign in to comment.