Skip to content

Commit

Permalink
add notify ownership change method to the notification center adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Aug 5, 2024
1 parent 7ec6637 commit ef55167
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/adapters/notifications/NotificationAdapterInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface ProjectsHaveNewRankingInputParam {
newBottomRank: number;
}

export interface ProjectOwnershipChangedParams {
previousOwnerUser: User | null;
newOwnerUser: User | null;
projectName: string;
}

export interface OrttoPerson {
fields: {
'str::first': string;
Expand Down Expand Up @@ -114,4 +120,7 @@ export interface NotificationAdapterInterface {
params: BroadCastNotificationInputParams,
): Promise<void>;
projectsHaveNewRank(params: ProjectsHaveNewRankingInputParam): Promise<void>;
notifyProjectOwnershipChange(
params: ProjectOwnershipChangedParams,
): Promise<void>;
}
24 changes: 24 additions & 0 deletions src/adapters/notifications/NotificationCenterAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BroadCastNotificationInputParams,
NotificationAdapterInterface,
OrttoPerson,
ProjectOwnershipChangedParams,
ProjectsHaveNewRankingInputParam,
} from './NotificationAdapterInterface';
import { Donation } from '../../entities/donation';
Expand Down Expand Up @@ -989,6 +990,29 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
});
}
}

async notifyProjectOwnershipChange(
params: ProjectOwnershipChangedParams,
): Promise<void> {
try {
const payload = {
previousOwnerEmail: params.previousOwnerUser?.email,
newOwnerEmail: params.newOwnerUser?.email,
projectName: params.projectName,
previousOwnerName: params.previousOwnerUser?.name,
newOwnerName: params.newOwnerUser?.name,
};

await callSendNotification({
eventName: NOTIFICATIONS_EVENT_NAMES.PROJECT_OWNERSHIP_CHANGED,
segment: {
payload,
},
});
} catch (e) {
logger.error('notifyProjectOwnershipChange >> error', e);
}
}
}

const getEmailDataDonationAttributes = async (params: {
Expand Down
1 change: 1 addition & 0 deletions src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export enum NOTIFICATIONS_EVENT_NAMES {
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',
SEND_EMAIL_CONFIRMATION = 'Send email confirmation',
PROJECT_OWNERSHIP_CHANGED = 'Project ownership changed',
}

0 comments on commit ef55167

Please sign in to comment.