Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger ortto activity when user saves their profile info for the first time #1520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/adapters/notifications/MockNotificationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { logger } from '../../utils/logger';
import { RecurringDonation } from '../../entities/recurringDonation';

export class MockNotificationAdapter implements NotificationAdapterInterface {
async createOrttoProfile(params: User): Promise<void> {
logger.debug('MockNotificationAdapter createOrttoProfile', params);
return Promise.resolve(undefined);
}

async updateOrttoPeople(params: OrttoPerson[]): Promise<void> {
logger.debug('MockNotificationAdapter updateOrttoPeople', params);
return Promise.resolve(undefined);
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/notifications/NotificationAdapterInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface OrttoPerson {
}

export interface NotificationAdapterInterface {
createOrttoProfile(params: User): Promise<void>;

updateOrttoPeople(params: OrttoPerson[]): Promise<void>;

donationReceived(params: {
Expand Down
18 changes: 17 additions & 1 deletion src/adapters/notifications/NotificationCenterAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface {
return;
}

async createOrttoProfile(user: User): Promise<void> {
try {
const { id, email, firstName, lastName } = user;
await callSendNotification({
eventName: NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE,
trackId: 'create-ortto-profile-' + user.id,
userWalletAddress: user.walletAddress!,
segment: {
payload: { userId: id, email, firstName, lastName },
},
});
} catch (e) {
logger.error('createOrttoProfile >> error', e);
}
}

async updateOrttoPeople(people: OrttoPerson[]): Promise<void> {
// TODO we should me this to notification-center, it's not good that we call Ortto directly
try {
Expand Down Expand Up @@ -1196,7 +1212,7 @@ interface SendNotificationBody {
email?: string;
trackId?: string;
metadata?: any;
projectId: string;
projectId?: string;
userWalletAddress: string;
segment?: {
payload: any;
Expand Down
1 change: 1 addition & 0 deletions src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export enum NOTIFICATIONS_EVENT_NAMES {
SUPER_TOKENS_BALANCE_WEEK = 'One week left in stream balance',
SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance',
SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',
}
4 changes: 4 additions & 0 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class UserResolver {
@Arg('email', { nullable: true }) email: string,
@Arg('url', { nullable: true }) url: string,
@Arg('avatar', { nullable: true }) avatar: string,
@Arg('newUser', { nullable: true }) newUser: boolean,
@Ctx() { req: { user } }: ApolloContext,
): Promise<boolean> {
if (!user)
Expand Down Expand Up @@ -185,6 +186,9 @@ export class UserResolver {
userId: dbUser.id.toString(),
});
await getNotificationAdapter().updateOrttoPeople([orttoPerson]);
if (newUser) {
await getNotificationAdapter().createOrttoProfile(dbUser);
}

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ export const updateUser = `
$lastName: String
$firstName: String
$avatar: String
$newUser: Boolean
) {
updateUser(
url: $url
Expand All @@ -1326,6 +1327,7 @@ export const updateUser = `
firstName: $firstName
lastName: $lastName
avatar: $avatar
newUser: $newUser
)
}
`;
Expand Down
Loading